1
- fileTypes : [ps1, psm1, psd1]
1
+ # [PackageDev] target_format: plist, ext: tmLanguage
2
+ ---
2
3
name : PowerShell
4
+ scopeName : source.powershell
5
+ fileTypes : [ps1, psm1, psd1]
6
+ uuid : f8f5ffb0-503e-11df-9879-0800200c9a66
7
+
3
8
patterns :
9
+
10
+ # # First match comments
4
11
- name : comment.block.powershell
5
12
begin : <#
6
13
beginCaptures :
@@ -10,28 +17,20 @@ patterns:
10
17
' 0 ' : {name: punctuation.end.definition.comment.block.powershell}
11
18
patterns :
12
19
- {include: '#commentEmbeddedDocs'}
13
- - name : comment.line.powershell
14
- begin : (?<![\\-])#
15
- end : $
20
+
21
+ - name : comment.line.number-sign.powershell
22
+ match : (?<![\\-])#.* $
16
23
patterns :
17
24
- {include: '#commentEmbeddedDocs'}
18
- - name : entity.name.tag
19
- begin : \[
20
- end : \]
21
- patterns :
22
- - {match: '(\p{L}|\.|``\d+)+?', name: entity.name.tag}
23
- - {include: $self}
24
- - name : entity.other.attribute-name
25
- begin : \(
26
- end : \)
27
- patterns :
28
- - name : entity.other.attribute.parameter.powershell
29
- captures :
30
- ' 0 ' : {name: entity.other.attribute.parameter.powershell}
31
- ' 1 ' : {name: constant.language.powershell}
32
- comment : really we should match the known attributes first
33
- match : (\w+)\s*=([^"']*?|'[^']*?'|"[^"]*?")(?=,|\))
34
- - {include: $self}
25
+
26
+ # # Then match top-level script content
27
+ - include : ' #commands'
28
+ - include : ' #variable'
29
+ - include : ' #interpolatedStringContent'
30
+ - include : ' #function'
31
+ - include : ' #attribute'
32
+ - include : ' #type'
33
+
35
34
- name : string.quoted.double.powershell
36
35
begin : (?<!(?<!`)")"
37
36
end : ' "(?!")'
@@ -75,14 +74,13 @@ patterns:
75
74
begin : ' @'' $'
76
75
end : ^'@$
77
76
- include : ' #numericConstant'
78
- - include : ' #commands'
79
- - include : ' #variable'
80
77
- name : keyword.operator.logical.powershell
81
78
match : ' -([lg][te]|[ci]?(eq|ne))'
82
79
- name : support.function.powershell
83
80
match : ' (?i:[a-z][a-z0-9]+-[a-z][a-z0-9]+)'
81
+ match : ' (?i:[a-z][a-z0-9]+-?[a-z][a-z0-9]+)(?i:\.(?:exe|cmd|bat|ps1))'
84
82
- name : keyword.control.powershell
85
- match : ' \b(?i:begin|break|catch|class|continue|data|define|do|dynamicparam|else|elseif|end|exit|filter|finally|for|foreach|from|function |if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|while|workflow)\b'
83
+ match : ' \b(?i:begin|break|catch|class|continue|data|define|do|dynamicparam|else|elseif|end|exit|filter|finally|for|foreach(?!=-object) |from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|using|var|while|workflow)\b'
86
84
- name : keyword.operator.comparison.powershell
87
85
match : ' -(?i:is(?:not)?|as)\b'
88
86
- name : keyword.operator.comparison.powershell
@@ -107,9 +105,114 @@ patterns:
107
105
match : ' (?<!\s|^)\.\.(?=\d|\(|\$)'
108
106
comment : ' This is very imprecise, is there a syntax for '' must come after...'' '
109
107
repository :
108
+ type :
109
+ begin : \[
110
+ beginCaptures :
111
+ ' 0 ' : {name: entity.name.type}
112
+ end : \]
113
+ endCaptures :
114
+ ' 0 ' : {name: entity.name.type}
115
+ patterns :
116
+ - name : entity.name.type
117
+ match : ' (\p{L}|\.|``\d+)+?'
118
+ - include : $self
119
+ attribute :
120
+ begin : \[(\p{L}|\.|``\d+)+(?=\()
121
+ beginCaptures :
122
+ ' 0 ' : {name: entity.name.tag}
123
+ ' 1 ' : {name: entity.name.tag}
124
+ end : (?<=\))\]
125
+ endCaptures :
126
+ ' 0 ' : {name: entity.name.tag}
127
+ patterns :
128
+ - name : entity.other.attribute-name
129
+ begin : \(
130
+ end : \)
131
+ patterns :
132
+ - name : entity.other.attribute-name.powershell
133
+ match : (\w+)\s*=?([^"']*?|'[^']*?'|"[^"]*?")?(?=,|\))
134
+ captures :
135
+ ' 0 ' : {name: entity.other.attribute.parameter.powershell}
136
+ ' 1 ' : {name: constant.language.powershell}
137
+ ' 2 ' : {name: variable.other.powershell}
138
+ comment : really we should match the known attributes first
139
+ - include : ' #variable'
140
+ function :
141
+ begin : (function)\s+((?:\p{L}|\d|_|-)+)
142
+ beginCaptures :
143
+ ' 0 ' : {name: meta.function}
144
+ ' 1 ' : {name: storage.type}
145
+ ' 2 ' : {name: entity.name.function}
146
+ end : \{
147
+ # patterns:
148
+ # begin: \s*\(
149
+ # end: \)\s*
150
+ # patterns:
151
+ # include: '#variable'
152
+ variable :
153
+ patterns :
154
+ - comment : ' These are special constants.'
155
+ match : (\$)(?i:(False|Null|True))\b
156
+ captures :
157
+ ' 1 ' : {name: keyword.other.powershell}
158
+ ' 2 ' : {name: constant.language.powershell}
159
+
160
+ - comment : ' These are the other built-in constants.'
161
+ match : (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b
162
+ captures :
163
+ ' 1 ' : {name: keyword.other.powershell}
164
+ ' 2 ' : {name: support.constant.variable.powershell}
165
+ ' 3 ' : {name: entity.name.function.invocation.powershell}
166
+
167
+ - comment : ' Automatic variables are not constants, but they are read-only...'
168
+ match : (\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))((?:\.(?:\p{L}|\d|_)+)*\b)?\b
169
+ captures :
170
+ ' 1 ' : {name: keyword.other.powershell}
171
+ ' 2 ' : {name: support.variable.automatic.powershell}
172
+ ' 3 ' : {name: entity.name.function.invocation.powershell}
173
+
174
+ - comment : Style preference variables as language variables so that they stand out.
175
+ match : (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))((?:\.(?:\p{L}|\d|_)+)*\b)?\b
176
+ captures :
177
+ ' 1 ' : {name: keyword.other.powershell}
178
+ ' 2 ' : {name: variable.language.powershell}
179
+ ' 3 ' : {name: entity.name.function.invocation.powershell}
180
+
181
+ # then, there are four variations on variables, in general:
182
+ # with and without scope, and with and without curly braces
183
+ - match : (?i:(\$)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
184
+ captures :
185
+ ' 1 ' : {name: keyword.other.powershell}
186
+ ' 2 ' : {name: storage.modifier.scope.powershell}
187
+ ' 3 ' : {name: variable.other.normal.powershell}
188
+ ' 4 ' : {name: entity.name.function.invocation.powershell}
189
+
190
+ - match : (?i:(\$\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
191
+ captures :
192
+ ' 1 ' : {name: keyword.other.powershell}
193
+ ' 2 ' : {name: storage.modifier.scope.powershell}
194
+ ' 3 ' : {name: variable.other.readwrite.powershell}
195
+ ' 4 ' : {name: keyword.other.powershell}
196
+ ' 5 ' : {name: entity.name.function.invocation.powershell}
197
+
198
+ - match : (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
199
+ captures :
200
+ ' 1 ' : {name: keyword.other.powershell}
201
+ ' 2 ' : {name: support.variable.drive.powershell}
202
+ ' 3 ' : {name: variable.other.readwrite.powershell}
203
+ ' 4 ' : {name: entity.name.function.invocation.powershell}
204
+
205
+ - match : (?i:(\$\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
206
+ captures :
207
+ ' 1 ' : {name: keyword.other.powershell}
208
+ ' 2 ' : {name: support.variable.drive.powershell}
209
+ ' 3 ' : {name: variable.other.readwrite.powershell}
210
+ ' 4 ' : {name: keyword.other.powershell}
211
+ ' 5 ' : {name: entity.name.function.invocation.powershell}
212
+
110
213
commands :
111
214
comment : ' Verb-Noun pattern:'
112
- match : ' (?:[a-zA-Z.]*\\)?(?i:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?\b'
215
+ match : ' (?:[a-zA-Z.]*\\)?(?i:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?:exe|cmd|bat|ps1))? \b'
113
216
name : support.function.powershell
114
217
commentEmbeddedDocs :
115
218
patterns :
@@ -182,39 +285,3 @@ repository:
182
285
name : meta.scriptblock.powershell
183
286
patterns :
184
287
- {include: $self}
185
- variable :
186
- patterns :
187
- - name : support.variable.builtin.powershell
188
- captures :
189
- ' 1 ' : {name: keyword.other.powershell}
190
- ' 2 ' : {name: constant.numeric.powershell}
191
- comment : ' Style automatic variables as numeric constants: you should not set them.'
192
- match : (\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Error|Event|EventArgs|EventSubscriber|ExecutionContext|false|ForEach|Home|Host|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|NULL|PID|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PsHome|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|PsVersionTable|Pwd|Sender|ShellID|SourceArgs|SourceEventArgs|StackTrace|Switch|This|True))\b
193
- - name : support.variable.builtin.powershell
194
- captures :
195
- ' 1 ' : {name: keyword.other.powershell}
196
- ' 2 ' : {name: variable.language.powershell}
197
- comment : Style preference variables as language variables so that they stand out.
198
- match : (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PsHome|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))\b
199
- - captures :
200
- ' 1 ' : {name: keyword.other.variable.powershell}
201
- ' 2 ' : {name: storage.modifier.scope.powershell}
202
- ' 3 ' : {name: 'variable.other, variable.other.normal.shell'}
203
- match : (?i:(\$)(?:(global|local|private|script|using|workflow):)?((?:\p{L}|\d|_)+))
204
- - captures :
205
- ' 1 ' : {name: keyword.other.variable.powershell}
206
- ' 2 ' : {name: variable.other.readwrite.powershell}
207
- ' 3 ' : {name: storage.modifier.scope.powershell}
208
- match : (?i:(\$)\{(?:(global|local|private|script|using|workflow):)?([^}]*[^}`])\})
209
- - captures :
210
- ' 1 ' : {name: keyword.other.variable.powershell}
211
- ' 2 ' : {name: variable.other.readwrite.powershell}
212
- ' 3 ' : {name: variable.other.drive.powershell}
213
- match : (?i:(\$)(?:(\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))
214
- - captures :
215
- ' 1 ' : {name: keyword.other.variable.powershell}
216
- ' 2 ' : {name: variable.other.readwrite.powershell}
217
- ' 3 ' : {name: variable.other.drive.powershell}
218
- match : (?i:(\$)(\{(?:(\p{L}|\d|_)+:)?[^}]*[^}`]\}))
219
- scopeName : source.powershell
220
- uuid : f8f5ffb0-503e-11df-9879-0800200c9a66
0 commit comments