Skip to content

Commit 6bebbf5

Browse files
author
Michael Lyons
committed
Push a little further to scope rectification
1 parent 9bfd10b commit 6bebbf5

File tree

3 files changed

+385
-251
lines changed

3 files changed

+385
-251
lines changed

PowerShell.sublime-syntax

Lines changed: 77 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,46 @@ contexts:
5050
scope: punctuation.section.group.end.powershell
5151
pop: true
5252
- include: main
53-
- match: (\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b)
54-
scope: support.function.powershell
55-
- match: (?<!\w|-)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w)
53+
- match: \b(?:[A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat)\b
54+
scope: variable.function.powershell
55+
- match: \b(?:(?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w)
5656
scope: keyword.control.powershell
57-
- match: (?<!\w)(--%)\B
57+
- match: \B--%\B
5858
scope: keyword.control.powershell
59+
push:
60+
- meta_content_scope: string.unquoted.powershell
61+
- match: (?=\n|$)
62+
pop: true
5963
- match: \b(?i:hidden|static)\b
6064
# This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix.
6165
scope: storage.modifier.powershell
62-
- match: (?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b
66+
- match: \b((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b
6367
# capture should be entity.name.type, but it doesn't provide a good color in the default schema.
6468
captures:
6569
1: storage.type.class.powershell
6670
2: meta.class.powershell entity.name.class.powershell
67-
- match: (?<!\w)-(?i:replace)\b
68-
scope: keyword.operator.powershell
69-
- match: (?<!\w)-(?i:as)\b
71+
- match: \B-(?i:as)\b
72+
scope: keyword.operator.cast.powershell
73+
- match: \B-(?i:[ic]?(?:eq|ne|[gl][te]))(?!\p{L})
7074
scope: keyword.operator.comparison.powershell
71-
- match: (?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]))(?!\p{L})
72-
scope: keyword.operator.comparison.powershell
73-
- match: (?<!\w)-(?i:[ic]?(?:not)?(?:like|match|contains|in))(?!\p{L})
75+
- match: \B-(?i:[ic]?(?:not)?(?:like|match|contains|in))(?!\p{L})
7476
scope: keyword.operator.logical.powershell
75-
- match: (?<!\w)-(?i:join|split)(?!\p{L})|!
76-
scope: keyword.operator.unary.powershell
77-
- match: (?<!\w)-(?i:is(?:not)?)\b
77+
- match: \B-(?i:join|split|replace)(?!\p{L})|!
78+
scope: keyword.operator.string.powershell
79+
- match: \B-(?i:is(?:not)?)\b
7880
scope: keyword.operator.logical.powershell
79-
- match: (?<!\w)-(?i:and|or|not|xor)(?!\p{L})|!
81+
- match: \B-(?i:and|or|not|xor)(?!\p{L})|!
8082
scope: keyword.operator.logical.powershell
81-
- match: (?<!\w)-(?i:band|bor|bnot|bxor|sh[lr])(?!\p{L})
83+
- match: \B-(?i:band|bor|bnot|bxor|sh[lr])(?!\p{L})
8284
scope: keyword.operator.bitwise.powershell
83-
- match: (?<!\w)-(?i:f)(?!\p{L})
85+
- match: \B-(?i:f)(?!\p{L})
8486
scope: keyword.operator.string-format.powershell
8587
- match: '[+/*%-]?='
8688
scope: keyword.operator.assignment.powershell
89+
- match: (?:\+\+|--)(?![ \t]*\d)
90+
scope: keyword.operator.assignment.powershell
8791
- match: '[+/*%-]'
88-
scope: keyword.operator.powershell
92+
scope: keyword.operator.arithmetic.powershell
8993
- match: \|\||&&
9094
scope: keyword.operator.logical.powershell
9195
- match: ;
@@ -126,14 +130,16 @@ contexts:
126130
- meta_scope: meta.requires.powershell
127131
- match: $
128132
pop: true
133+
- include: hashtable
129134
- match: \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version)
130135
scope: keyword.other.powershell
131-
- match: (?<!-)\b\p{L}+|\d+(?:\.\d+)*
136+
- match: '-'
137+
# Intentional no-scope match to skip leading `-`s below
138+
- match: \b\p{L}+|\d+(?:\.\d+)*
132139
scope: variable.parameter.powershell
133-
- include: hashtable
134140

135141
using-directive:
136-
- match: (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
142+
- match: \b(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
137143
captures:
138144
1: keyword.control.using.powershell
139145
2: keyword.other.powershell
@@ -197,17 +203,23 @@ contexts:
197203
- include: comment-embedded-docs
198204

199205
comment-embedded-docs:
200-
- match: (?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))
206+
- match: ^\s*(\.)(?i:(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))
207+
scope: comment.documentation.embedded.powershell
208+
captures:
209+
1: punctuation.definition.keyword.documentation.powershell
210+
2: keyword.other.documentation.powershell
211+
- match: ^\s*(\.)(?i:(PARAMETER)\s+([a-z0-9-_]+))
201212
scope: comment.documentation.embedded.powershell
202213
captures:
203-
1: constant.string.documentation.powershell
204-
2: keyword.operator.documentation.powershell
205-
- match: (?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+))
214+
1: punctuation.definition.keyword.documentation.powershell
215+
2: keyword.other.documentation.param.powershell
216+
3: variable.parameter.powershell
217+
- match: ^\s*(\.)(?i:(FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+))
206218
scope: comment.documentation.embedded.powershell
207219
captures:
208-
1: constant.string.documentation.powershell
209-
2: keyword.operator.documentation.powershell
210-
3: keyword.operator.documentation.powershell
220+
1: punctuation.definition.keyword.documentation.powershell
221+
2: keyword.other.documentation.powershell
222+
3: markup.underline.link.powershell
211223

212224
comment-line:
213225
- match: (?<![`\\-])#
@@ -257,7 +269,7 @@ contexts:
257269
pop: true
258270

259271
double-quoted-string:
260-
- match: (?<!(?<!`)")"
272+
- match: '"'
261273
scope: punctuation.definition.string.begin.powershell
262274
push:
263275
- meta_scope: string.quoted.double.powershell
@@ -300,7 +312,7 @@ contexts:
300312
- match: \}
301313
scope: punctuation.section.braces.end.powershell
302314
pop: true
303-
- match: \b(['"]?)(\w+)(\1)\s*(=)\s*
315+
- match: \b(['"]?)(\w+)(['"]?)\s*(=)\s*
304316
scope: meta.hashtable.assignment.powershell
305317
captures:
306318
1: punctuation.definition.string.begin.powershell
@@ -337,23 +349,24 @@ contexts:
337349
- include: interpolated-string-content
338350

339351
numeric-constant:
340-
- match: ((?:[-+]|\b)0(?i:x)[0-9a-fA-F_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b
352+
- match: ((?:[-+]|\b)0(?i:x[0-9a-f_]+)(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b
341353
captures:
342354
1: constant.numeric.integer.hexadecimal.powershell
343355
2: keyword.other.powershell
344-
- match: ((?:[-+]|\b)(?:[0-9_]+)?\.[0-9_]+(?:(?i:e)[0-9]+)?(?i:[fdm])?)({{bytes_unit}}?)\b
356+
- match: ((?:[-+]|\b)(?:[0-9_]+)?(\.)[0-9_]+(?:(?i:e)[0-9]+)?(?i:[fdm])?)({{bytes_unit}}?)\b
345357
captures:
346-
1: constant.numeric.integer.powershell
347-
2: keyword.other.powershell
348-
- match: ((?:[-+]|\b)0(?:b|B)[01_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b
358+
1: constant.numeric.float.decimal.powershell
359+
2: punctuation.separator.decimal.powershell
360+
3: keyword.other.unit.powershell
361+
- match: ((?:[-+]|\b)0[bB][01_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b
349362
captures:
350363
1: constant.numeric.integer.binary.powershell
351364
2: keyword.other.powershell
352-
- match: ((?:[-+]|\b)[0-9_]+(?i:e)(?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b
365+
- match: ((?:[-+]|\b)[0-9_]+[eE](?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b
353366
captures:
354367
1: constant.numeric.integer.powershell
355368
2: keyword.other.powershell
356-
- match: ((?:[-+]|\b)[0-9_]+\.(?i:e)(?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b
369+
- match: ((?:[-+]|\b)[0-9_]+\.[eE](?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b
357370
captures:
358371
1: constant.numeric.integer.powershell
359372
2: keyword.other.powershell
@@ -397,45 +410,45 @@ contexts:
397410
1: support.constant.variable.powershell
398411
2: punctuation.definition.variable.powershell
399412
3: variable.other.member.powershell
400-
- 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
413+
- 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
401414
captures:
402415
1: variable.language.powershell
403416
2: punctuation.definition.variable.powershell
404417
3: variable.other.member.powershell
405-
- 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
418+
- 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
406419
comment: Style preference variables as language variables so that they stand out.
407420
captures:
408-
1: punctuation.definition.variable.powershell
409-
2: variable.language.powershell
421+
1: variable.language.powershell
422+
2: punctuation.definition.variable.powershell
410423
3: variable.other.member.powershell
411-
- match: (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
424+
- match: ((\$|@)(?i:(global|local|private|script|using|workflow):(?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
412425
captures:
413-
1: punctuation.definition.variable.powershell
414-
2: storage.modifier.scope.powershell
415-
3: variable.other.readwrite.powershell
426+
1: variable.other.readwrite.powershell
427+
2: punctuation.definition.variable.powershell
428+
3: storage.modifier.scope.powershell
416429
4: variable.other.member.powershell
417-
- match: (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
430+
- match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
418431
captures:
419-
1: punctuation.definition.variable.powershell
420-
2: punctuation.section.braces.begin.powershell
421-
3: storage.modifier.scope.powershell
422-
4: variable.other.readwrite.powershell
423-
5: punctuation.section.braces.end.powershell
424-
6: variable.other.member.powershell
425-
- match: (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
432+
1: variable.other.readwrite.powershell
433+
2: punctuation.definition.variable.powershell
434+
3: punctuation.section.braces.begin.powershell
435+
4: storage.modifier.scope.powershell
436+
6: punctuation.section.braces.end.powershell
437+
7: variable.other.member.powershell
438+
- match: ((?i:(\$|@)((?:\p{L}|\d|_)+:)?(?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
426439
captures:
427-
1: punctuation.definition.variable.powershell
428-
2: support.variable.drive.powershell
429-
3: variable.other.readwrite.powershell
440+
1: variable.other.readwrite.powershell
441+
2: punctuation.definition.variable.powershell
442+
3: support.variable.drive.powershell
430443
4: variable.other.member.powershell
431-
- match: (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
444+
- match: ((?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})))((?:\.(?:\p{L}|\d|_)+)*\b)?
432445
captures:
433-
1: punctuation.definition.variable.powershell
434-
2: punctuation.section.braces.begin.powershell
435-
3: support.variable.drive.powershell
436-
4: variable.other.readwrite.powershell
437-
5: punctuation.section.braces.end.powershell
438-
6: variable.other.member.powershell
446+
1: variable.other.readwrite.powershell
447+
2: punctuation.definition.variable.powershell
448+
3: punctuation.section.braces.begin.powershell
449+
4: support.variable.drive.powershell
450+
6: punctuation.section.braces.end.powershell
451+
7: variable.other.member.powershell
439452

440453
variable-no-property:
441454
- match: (\$)(?i:False|Null|True)\b
@@ -446,7 +459,7 @@ contexts:
446459
scope: support.constant.variable.powershell
447460
captures:
448461
1: punctuation.definition.variable.powershell
449-
- 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)\b
462+
- 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)\b
450463
scope: variable.language.powershell
451464
captures:
452465
1: punctuation.definition.variable.powershell

0 commit comments

Comments
 (0)