@@ -80,8 +80,6 @@ contexts:
8080 # Declarations
8181 - match : \b(?i:var){{kebab_break}}
8282 scope : keyword.declaration.variable.powershell
83- - match : \b(?i:(?:dynamic)?param){{kebab_break}}
84- scope : keyword.declaration.parameter.powershell # This scope is not standard
8583
8684 expressions :
8785 - include : regions
@@ -167,48 +165,6 @@ contexts:
167165 3 : keyword.other.region.end.powershell
168166 4 : meta.fold.end.powershell
169167
170- attributes :
171- - match : |-
172- (?xi:
173- (\[)\s*
174- (
175- CmdletBinding | Alias | OutputType | Parameter
176- | Validate
177- (?:
178- Count | NotNull(?:OrEmpty)? | Range | Pattern | Length | Set
179- | Script)
180- | Allow(?: Null | Empty(?: Collection | String ))
181- )\b
182- )
183- captures:
184- 1: punctuation.section.brackets.begin.powershell
185- 2: support.function.attribute.powershell
186- push:
187- - meta_scope: meta.attribute.powershell
188- - match: \]
189- scope: punctuation.section.brackets.end.powershell
190- pop: 1
191- - match: \(
192- scope: punctuation.section.group.begin.powershell
193- push:
194- - match: \)
195- scope: punctuation.section.group.end.powershell
196- pop: 1
197- - match: |-
198- (?xi:
199- \b(
200- Mandatory | ValueFromPipeline(?:ByPropertyName)?
201- | ValueFromRemainingArguments | Position(?:alBinding)?
202- | (?:Default)?ParameterSetName | SupportsShouldProcess | SupportsPaging
203- | HelpUri | ConfirmImpact | HelpMessage
204- )\b
205- \s*(=)?
206- )
207- captures:
208- 1: variable.parameter.attribute.powershell
209- 2: keyword.operator.assignment.powershell
210- - include: expressions
211-
212168 commands :
213169 # The "Verb-Noun" pattern
214170 - match : |-
@@ -223,18 +179,6 @@ contexts:
223179 - match : \b(?i:(?:foreach|where|sort|tee)-object)\b
224180 scope : support.function.powershell
225181
226- functions :
227- - match : ^(?:\s*)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)
228- scope : meta.function.powershell
229- captures :
230- 1 : storage.type.powershell
231- 2 : storage.modifier.scope.powershell
232- 3 : entity.name.function.powershell
233- push :
234- - match : (?=\{|\()
235- pop : 1
236- - include : comment-line
237-
238182 script-blocks :
239183 - match : (%)?(\{)
240184 captures :
@@ -252,20 +196,65 @@ contexts:
252196 scope : storage.modifier.powershell
253197
254198 # TODO: Fix functions, so these don't nest here.
199+ - include : function-sections
255200 - include : attributes
256- # Begin/Process/End/Clean
257- - match : \b(?i:begin){{kebab_break}}
258- scope : keyword.context.block.begin.powershell
259- - match : \b(?i:process){{kebab_break}}
260- scope : keyword.context.block.process.powershell
261- - match : \b(?i:end){{kebab_break}}
262- scope : keyword.context.block.end.powershell
263- - match : \b(?i:clean){{kebab_break}}
264- scope : keyword.context.block.clean.powershell
265201
266202 # Back to normal stuff
267203 - include : statements
268204
205+ # ##[ FUNCTIONS ]###############################################################
206+
207+ functions :
208+ - match : ^(?:\s*)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)
209+ scope : meta.function.powershell
210+ captures :
211+ 1 : storage.type.powershell
212+ 2 : storage.modifier.scope.powershell
213+ 3 : entity.name.function.powershell
214+ push :
215+ - match : (?=\{|\()
216+ pop : 1
217+ - include : comment-line
218+
219+ function-sections :
220+ - match : \b(?i:(?:dynamic)?param){{kebab_break}}
221+ scope : keyword.declaration.parameter.powershell # This scope is not standard
222+ # Begin/Process/End/Clean
223+ - match : \b(?i:begin){{kebab_break}}
224+ scope : keyword.context.block.begin.powershell
225+ - match : \b(?i:process){{kebab_break}}
226+ scope : keyword.context.block.process.powershell
227+ - match : \b(?i:end){{kebab_break}}
228+ scope : keyword.context.block.end.powershell
229+ - match : \b(?i:clean){{kebab_break}}
230+ scope : keyword.context.block.clean.powershell
231+
232+ attributes :
233+ - match : (\[)\s*({{attributes}})
234+ captures :
235+ 1 : punctuation.section.brackets.begin.powershell
236+ 2 : support.function.attribute.powershell
237+ push : inside-attribute
238+
239+ inside-attribute :
240+ - meta_scope : meta.attribute.powershell
241+ - match : \]
242+ scope : punctuation.section.brackets.end.powershell
243+ pop : 1
244+ - match : \(
245+ scope : punctuation.section.group.begin.powershell
246+ push : inside-attribute-parameters
247+
248+ inside-attribute-parameters :
249+ - match : \)
250+ scope : punctuation.section.group.end.powershell
251+ pop : 1
252+ - match : ({{attribute_parameters}})\s*(=)?
253+ captures :
254+ 1 : variable.parameter.attribute.powershell
255+ 2 : keyword.operator.assignment.powershell
256+ - include : expressions
257+
269258# ##[ TYPES ]###################################################################
270259
271260 types :
@@ -831,6 +820,22 @@ variables:
831820 | array | hashtable
832821 )\b
833822
823+ # Attributes
824+ attributes : |-
825+ \b(?xi:
826+ CmdletBinding | Alias | OutputType | Parameter
827+ | Validate
828+ (?: Count | NotNull (?:OrEmpty)? | Range | Pattern | Length | Set | Script)
829+ | Allow (?: Null | Empty (?: Collection | String ))
830+ )\b
831+ attribute_parameters : |-
832+ \b(?xi:
833+ Mandatory | ValueFromPipeline (?:ByPropertyName)?
834+ | ValueFromRemainingArguments | Position(?:alBinding)?
835+ | (?:Default)? ParameterSetName | SupportsShouldProcess | SupportsPaging
836+ | HelpUri | ConfirmImpact | HelpMessage
837+ )\b
838+
834839 # Numbers
835840 dec_exponent : (?:[eE][-+]?\d*)
836841 dec_suffix : ' [dD]'
0 commit comments