-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathpowershell.js
More file actions
executable file
·107 lines (84 loc) · 2.92 KB
/
powershell.js
File metadata and controls
executable file
·107 lines (84 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// ----------------------------------------------------------------------
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// --
// Copyright 2016-2018 Andi Dittrich <https://andidittrich.de>
// ----------------------------------------------------------------------
// Generic Rules/Regex
import _language_common_rules from './rulesets/generic';
import {generic} from './generic';
import _token from '../engine/token';
import _microTokenizer from '../engine/micro-tokenizer';
// Powershell Scripting
// Author: [Andi Dittrich]
// --
export class powershell extends generic {
setupLanguage() {
// template strings. Stage-2 Analyzing
function parseTemplateSeq(token){
// run the MicroTokenizer to identify the template tags
return _microTokenizer(token, /\$(?:\w+|\(.*?\))/g, function(match){
return [_token(match[0], 'k7')];
});
}
this.rules = [
// double quoted strings
{
regex: /"(?:[^"`]|`.)*"/g,
type: 's2',
filter: parseTemplateSeq
},
// single quoted strings
_language_common_rules.sqStrings,
// double quoted here strings
{
regex: /@"[\S\s]*?\n\s*"@/g,
type: 's5',
filter: parseTemplateSeq
},
// single quoted here strings
{
regex: /@'[\S\s]*?\n\s*'@/g,
type: 's5'
},
// control keywords
{
regex: /\b(Begin|Break|Catch|Continue|Else|Elseif|End|Finally|For|ForEach|If|Switch|Throw|Try|Until|While)\b/gi,
type: 'k1'
},
// keywords
{
regex: /\b(Data|Do|DynamicParam|Exit|Filter|From|Function|In|InlineScript|Hidden|Parallel|Param|Process|Return|Sequence|Trap|Workflow)\b/gi,
type: 'k0'
},
// commands
{
regex: /\b([A-Z]\w+(?:-\w+)+)\b/gi,
type: 'm0'
},
// multi line comments
{
regex: /<#[\S\s]+?#>/gi,
type: 'c1'
},
// single line comments
_language_common_rules.poundComments,
// variables
{
regex: /\$[A-Z_][\w]*/gim,
type: 'k7'
},
// method calls
_language_common_rules.mCalls,
// function calls
_language_common_rules.fCalls,
// integers
_language_common_rules.int,
// floats
_language_common_rules.floats,
// brackets
_language_common_rules.brackets
];
}
}