From 8c65f0e4c4369ab4238940014365db05f3147772 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Fri, 25 Jan 2019 01:25:12 -0600 Subject: [PATCH 1/6] from msftrncs\powershell.tmlanguage wip_goal Mass update --- PowerShellSyntax.tmLanguage | 2212 ++++++++++++++++++++++++++--------- 1 file changed, 1635 insertions(+), 577 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 327a2cf..32d8e89 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -13,35 +13,8 @@ patterns - begin - <# - beginCaptures - - 0 - - name - punctuation.definition.comment.block.begin.powershell - - - end - #> - endCaptures - - 0 - - name - punctuation.definition.comment.block.end.powershell - - - name - comment.block.powershell - patterns - - - include - #commentEmbeddedDocs - - + include + #commentBlock match @@ -97,11 +70,11 @@ comment Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) include - #doubleQuotedStringEscapes + #argumentModeEscapes begin - (?<!')' + ['\x{2018}-\x{201B}] beginCaptures 0 @@ -111,7 +84,9 @@ end - '(?!') + ['\x{2018}-\x{201B}] + applyEndPatternLast + endCaptures 0 @@ -126,7 +101,7 @@ match - '' + ['\x{2018}-\x{201B}]{2} name constant.character.escape.powershell @@ -134,9 +109,9 @@ begin - \@"(?=$) + @(?:["\x{201C}-\x{201E}])(?=\s*$) end - ^"@ + ^(?:["\x{201C}-\x{201E}])@ name string.quoted.double.heredoc.powershell patterns @@ -147,30 +122,21 @@ include - #doubleQuotedStringEscapes + #doubleQuotedHereStringEscapes include - #interpolation + #stringInterpolation begin - \@'(?=$) + @['\x{2018}-\x{201B}](?=\s*$) end - ^'@ + ^['\x{2018}-\x{201B}]@ name string.quoted.single.heredoc.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - include @@ -193,55 +159,32 @@ end - \) + (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? endCaptures - 0 + 1 name punctuation.section.group.end.powershell - - name - meta.group.array-expression.powershell - patterns - - - include - $self - - - - - begin - (\$)(\() - beginCaptures - - 1 + 2 name - punctuation.definition.variable.powershell + variable.other.member.powershell - 2 + 4 name - punctuation.section.group.begin.powershell + punctuation.definition.comment.powershell - - comment - TODO: move to repo; make recursive. - end - \) - endCaptures - - 0 + 3 name - punctuation.section.group.end.powershell + comment.line.powershell name - meta.group.complex.subexpression.powershell + meta.group.array-expression.powershell patterns @@ -250,21 +193,25 @@ + + include + #interpolation + match - (\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b) + (\b(([\p{L}0-9_\.!%^&+=][\p{L}0-9_\.!@#%^&+=-]*)\.(?i:exe|com|cmd|bat))\b) name support.function.powershell match - (?<!\w|-|\.)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|from|if|in|inlinescript|parallel|param|process|return|sequence|switch|throw|trap|try|until|var|while)|%|\?)(?!\w) + (?<!\w|-|\.)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|from|if|in|inlinescript|parallel|param|process|return|sequence|switch|throw|trap|try|until|var|while)\b(?![\/.-])) name keyword.control.powershell match - (?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w) + (?<!\w|-|[^\)]\.)((?i:(foreach|where)\b(?![\/.-]))) name keyword.control.powershell @@ -280,282 +227,1009 @@ end - $ + $|(?=\|) patterns match - .+ + [^"\x{201C}-\x{201E}]+? name string.unquoted.powershell - - comment - This should be moved to the repository at some point. - - - comment - This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. - match - (?<!\w)((?i:hidden|static))(?!\w) - name - storage.modifier.powershell - - - captures - - 1 - - name - storage.type.powershell - - 2 - - name - entity.name.function - - - comment - capture should be entity.name.type, but it doesn't provide a good color in the default schema. - match - (?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b - - - match - (?<!\w)-(?i:is(?:not)?|as)\b - name - keyword.operator.comparison.powershell - - - match - (?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) - name - keyword.operator.comparison.powershell - - - match - (?<!\w)-(?i:join|split)(?!\p{L})|! - name - keyword.operator.unary.powershell - - - match - (?<!\w)-(?i:and|or|not|xor)(?!\p{L})|! - name - keyword.operator.logical.powershell - - - match - (?<!\w)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L}) - name - keyword.operator.bitwise.powershell - - - match - (?<!\w)-(?i:f)(?!\p{L}) - name - keyword.operator.string-format.powershell - - - match - [+%*/-]?=|[+/*%-] - name - keyword.operator.assignment.powershell - - - match - \|{2}|&{2}|; - name - punctuation.terminator.statement.powershell - - - match - &|(?<!\w)\.(?= )|`|,|\| - name - keyword.operator.other.powershell - - - comment - This is very imprecise, is there a syntax for 'must come after...' - match - (?<!\s|^)\.\.(?=\-?\d|\(|\$) - name - keyword.operator.range.powershell - - - repository - - commentLine - - begin - (?<![`\\-])# - captures - - 0 + begin + (?:["\x{201C}-\x{201E}]) + beginCaptures + + 0 + + name + punctuation.definition.string.begin.powershell + + + end + (?:["\x{201C}-\x{201E}])|$ + applyEndPatternLast + + endCaptures + + 0 + + name + punctuation.definition.string.end.powershell + + name - punctuation.definition.comment.powershell - - - end - $\n? - name - comment.line.powershell - patterns - - - include - #commentEmbeddedDocs - - - include - #RequiresDirective + string.quoted.double.powershell + comment + This should be moved to the repository at some point. - attribute begin - (\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength)\b + (?<![\w-])((?i:class))(?=\s) beginCaptures 1 name - punctuation.section.bracket.begin.powershell - - 2 - - name - support.function.attribute.powershell + keyword.other.class.powershell end - (\]) - endCaptures - - 1 - - name - punctuation.section.bracket.end.powershell - - - name - meta.attribute.powershell + (?=[^\s])|(?<=}) + applyEndPatternLast + patterns begin - \( + (?<![\w-])([\p{L}_]\w*) beginCaptures - 0 + 1 name - punctuation.section.group.begin.powershell + entity.name.type.class.powershell end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - + (?=[^\s])|(?<=}) + applyEndPatternLast + patterns - include - #variable + begin + : + beginCaptures + + 0 + + name + punctuation.separator.colon.powershell + + + end + (?=[^\s:])|(?<=}) + applyEndPatternLast + + patterns + + + begin + (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + beginCaptures + + 0 + + patterns + + + include + #type_keywords + + + match + [^\.]+ + name + entity.other.inherited-class.powershell + + + match + \. + name + punctuation.accessor.type.powershell + + + + + end + (?=[^\s])|(?<=}) + applyEndPatternLast + + patterns + + + begin + , + beginCaptures + + 0 + + name + punctuation.separator.comma.powershell + + + end + (?=[^\s:])|(?<=}) + applyEndPatternLast + + patterns + + + begin + (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + beginCaptures + + 0 + + patterns + + + include + #type_keywords + + + match + [^\.]+ + name + entity.other.inherited-class.powershell + + + match + \. + name + punctuation.accessor.type.powershell + + + + + end + (?=[^\s])|(?<=}) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!})[^\s{},]+ + + + + + include + #commentBlock + + + include + #commentLine + + + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!})[^\s{},]+ + + + + + include + #commentBlock + + + include + #commentLine + + include - #variableNoProperty + #commentBlock include - #hashtable + #commentLine - include - #scriptblock + match + (?<!})[^\s{}:]+ + + + + begin + { + beginCaptures + + 0 - include - #doubleQuotedStringEscapes + name + punctuation.section.braces.begin.powershell + + end + } + endCaptures + + 0 - include - #doubleQuotedString + name + punctuation.section.braces.end.powershell + + name + meta.class.powershell + patterns + - include - #type + match + (?<![\w-])((?i:hidden|static))(?=\s) + name + storage.modifier.powershell - include - #numericConstant + begin + (?<![\w-])([\p{L}_]\w*)(?=\s*\() + beginCaptures + + 1 + + name + entity.name.function.powershell + + + end + (?<=[;}]) + name + meta.method.powershell + patterns + + + begin + : + beginCaptures + + 0 + + name + punctuation.separator.colon.powershell + + + end + (?=[;{]) + patterns + + + comment + (?<![;{])\s+ + + + begin + (?i:base) + beginCaptures + + 0 + + name + variable.language.super.powershell + + + end + (?=[;{]) + patterns + + + comment + (?<![;{])\s+ + + + include + #invocationParameterSet + + + + + + + include + #invocationParameterSet + + + include + $self + + include - #doubleQuotedString + $self + + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?<![\w-])((?i:enum))(?=\s) + beginCaptures + + 1 + + name + keyword.other.enum.powershell + + + end + (?=[^\s])|(?<=}) + applyEndPatternLast + + patterns + + + begin + (?<![\w-])([\p{L}_]\w*) + beginCaptures + + 1 - include - $self + name + entity.name.type.enum.powershell + + end + (?=[^\s])|(?<=}) + applyEndPatternLast + + patterns + - match - (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=)? - captures + comment + optional user specified type, PowerShell Core >= 6.2.0 + begin + : + beginCaptures - 1 + 0 name - variable.parameter.attribute.powershell + punctuation.separator.colon.powershell - 2 + + end + (?=[^\s:])|(?<=}) + applyEndPatternLast + + patterns + - name - keyword.operator.assignment.powershell + begin + (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + beginCaptures + + 0 + + patterns + + + include + #type_keywords + + + match + [^\.]+ + name + storage.type.powershell + + + match + \. + name + punctuation.accessor.type.powershell + + + + + end + (?=[^\s])|(?<=}) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!})[^\s{}]+ + + - + + include + #commentBlock + + + include + #commentLine + + + + + include + #commentBlock + + + include + #commentLine + + match + (?<!})[^\s{}:]+ + + + + + begin + { + beginCaptures + + 0 + + name + punctuation.section.braces.begin.powershell + + + end + } + endCaptures + + 0 + + name + punctuation.section.braces.end.powershell + + + name + meta.enumeration.powershell + patterns + begin - (?<!')' + (?<![\w-])([\p{L}_]\w*) beginCaptures - 0 + 1 name - punctuation.definition.string.begin.powershell + entity.name.variable.enum-member.powershell end - '(?!') - endCaptures + (?=[;}\n]) + patterns + + + begin + = + beginCaptures + + 0 + + name + keyword.operator.assignment.enum-member.powershell + + + end + (?=[;}\n]) + patterns + + + include + $self + + + + + include + #argumentModeEscapes + + + include + #commentBlock + + + include + #commentLine + + + + + match + [^;\s][^;]+ + + + + + include + #argumentModeEscapes + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w)|\G)-(?i:is(?:not)?|as)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.comparison.type.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.comparison.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)-(?i:join|split)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.unary.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)-(?i:and|or|not|xor)(?!\p{L})|! + beginCaptures + + 0 + + name + keyword.operator.logical.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.bitwise.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)-(?i:f)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.string-format.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + match + (?:(?<!\w|!)|\G)-\p{L}\w* + name + entity.name.parameter.powershell + + + match + \+\+|-- + name + keyword.operator.unary.powershell + + + begin + [+%*/-]?=|[+/*%-](?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.assignment.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + match + \|\||&&|; + name + punctuation.terminator.statement.powershell + + + begin + &|(?<!\w|!)(?<!\.)\.(?=\s)|,|\| + beginCaptures + + 0 + + name + keyword.operator.other.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + comment + the range operator is only available after an operand (binary operator) + begin + (?<!^)\s*(\.\.) + beginCaptures + + 1 + + name + keyword.operator.range.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #commentBlock + + + include + #commentLine + + + + + repository + + commentBlock + + begin + <# + beginCaptures + + 0 + + name + punctuation.definition.comment.block.begin.powershell + + + end + #> + endCaptures + + 0 + + name + punctuation.definition.comment.block.end.powershell + + + name + comment.block.powershell + patterns + + + include + #commentEmbeddedDocs + + + + commentLine + + begin + (?:(?<![`\\\w*\[\]/.?=:~!$^%+-])|\G)(#)#* + captures + + 1 + + name + punctuation.definition.comment.powershell + + + end + $(?=(\n)?) + endCaptures + + 1 + + name + comment.line.powershell + + + name + comment.line.powershell + patterns + + + include + #commentEmbeddedDocs + + + include + #RequiresDirective + + + + argumentModeEscapes + + patterns + + + match + `(?:['\x{2018}-\x{201B}0abnfrvt"\x{201C}-\x{201E}$`\n]) + name + constant.character.escape.powershell + + + match + ` + name + invalid.character.escape.powershell + + + + attribute + + begin + (\[)\s*\b(?i)(cmdletbinding|alias|flags|ordered|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|supportswildcards|validatescript|validaterange|validatepattern|validatelength)\b + beginCaptures + + 1 + + name + punctuation.section.bracket.begin.powershell + + 2 + + name + support.function.attribute.powershell + + + end + \] + endCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + + name + meta.attribute.powershell + patterns + + + begin + \( + beginCaptures + + 0 + + name + punctuation.section.group.begin.powershell + + + end + \) + endCaptures + + 0 + + name + punctuation.section.group.end.powershell + + + patterns + + + match + (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage|ignorecase)\b + captures - 0 + 1 name - punctuation.definition.string.end.powershell + variable.parameter.attribute.powershell - - name - string.quoted.single.powershell - patterns - + 2 - match - '' name - constant.character.escape.powershell + keyword.operator.assignment.powershell - + + + + include + $self @@ -569,7 +1243,7 @@ comment Verb-Noun pattern: match - (?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Deploy|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)\-.+?(?:\.(?i:exe|cmd|bat|ps1))?\b + (?:(\p{L}|\d|_|-|\\|:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Deploy|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)-.+?(?:\.(?i:exe|cmd|bat|ps1))?\b name support.function.powershell @@ -626,7 +1300,7 @@ match - ^(?i:(?:\s?|#)+(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS)) + (?:^|\G)(?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))(?:\s*$) name comment.documentation.embedded.powershell @@ -650,7 +1324,7 @@ match - (?i:\s?(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) + (?:^|\G)(?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) name comment.documentation.embedded.powershell @@ -662,52 +1336,181 @@ match - `[0abnfrvt"'$`] + `(?:[0abnfrvt\s"\x{201C}-\x{201E}$`]|(?=$)) + name + constant.character.escape.powershell + + + match + ` + name + invalid.character.escape.powershell + + + match + (?:["\x{201C}-\x{201E}]){2} name constant.character.escape.powershell + + + doubleQuotedHereStringEscapes + + patterns + match - "" + `(?:[0abnfrvt\s"\x{201C}-\x{201E}'\x{2018}-\x{201B}$`]|(?=$)) name constant.character.escape.powershell + + match + ` + name + invalid.character.escape.powershell + function begin - ^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) + (?<![\w-])((?i:function|filter|configuration|workflow))(?=\s) beginCaptures - 0 + 1 name - meta.function.powershell + keyword.other.function.powershell - 1 + + end + (?=[//s])|(?<=}) + applyEndPatternLast + + patterns + - name - storage.type.powershell + begin + (?<![\w-])(?:(global|local|script|private)(:))?([\p{L}:_\\/\[\]`-][[`\\\w*\[\]/.?<>=:~!@#$^%+-]]*) + beginCaptures + + 1 + + name + storage.modifier.scope.powershell + + 2 + + name + punctuation.separator.colon.powershell + + 3 + + name + entity.name.function.powershell + + + end + (?=[//s])|(?<=}) + applyEndPatternLast + + patterns + + + begin + { + beginCaptures + + 0 + + name + punctuation.section.braces.begin.powershell + + + end + } + endCaptures + + 0 + + name + punctuation.section.braces.end.powershell + + + name + meta.function.powershell + patterns + + + include + $self + + + + + include + #invocationParameterSet + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!})[^\s{}()]+ + + - 2 - name - storage.modifier.scope.powershell + include + #commentBlock - 3 + + include + #commentLine + + + + invocationParameterSet + + begin + \( + beginCaptures + + 0 name - entity.name.function.powershell + punctuation.section.group.begin.powershell + name + meta.parameters.powershell end - (?=\{|\() + \) + endCaptures + + 0 + + name + punctuation.section.group.end.powershell + + patterns + + match + , + name + punctuation.separator.comma.powershell + include - #commentLine + $self @@ -723,17 +1526,32 @@ punctuation.section.group.begin.powershell - contentName + name interpolated.simple.source.powershell end - \) + (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? endCaptures - 0 + 1 name punctuation.section.group.end.powershell + 2 + + name + variable.other.member.powershell + + 4 + + name + punctuation.definition.comment.powershell + + 3 + + name + comment.line.powershell + patterns @@ -745,13 +1563,97 @@ include #interpolation + + + interpolation + + begin + (\$)(\() + beginCaptures + + 1 + + name + keyword.other.subexpression.powershell + + 2 + + name + punctuation.section.group.begin.powershell + + + name + meta.group.complex.subexpression.powershell + end + (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? + endCaptures + + 1 + + name + punctuation.section.group.end.powershell + + 2 + + name + variable.other.member.powershell + + 4 + + name + punctuation.definition.comment.powershell + + 3 + + name + comment.line.powershell + + + patterns + include + $self + + + comment + #commands + + + comment + #variable + + + comment #interpolatedStringContent + + comment + #function + + + comment + #attribute + + + comment + #type + + + comment + #hashtable + + + comment + #doubleQuotedString + + + comment + #scriptblock + - interpolation + stringInterpolation begin (\$)(\() @@ -760,7 +1662,7 @@ 1 name - punctuation.definition.variable.powershell + keyword.other.subexpression.powershell 2 @@ -768,6 +1670,8 @@ punctuation.section.group.begin.powershell + name + meta.embedded.subexpression.powershell contentName interpolated.complex.source.powershell end @@ -776,23 +1680,55 @@ 0 - name - punctuation.section.group.end.powershell + name + punctuation.section.group.end.powershell + + + patterns + + + comment + #interpolation + + + include + $self + + + comment + #commands + + + comment + #variable + + + comment + #interpolatedStringContent + + + comment + #function + + + comment + #attribute + + + comment + #type - - patterns - - include - $self + comment + #hashtable - include - #interpolation + comment + #doubleQuotedString - include - #interpolatedStringContent + comment + #scriptblock @@ -801,80 +1737,31 @@ patterns - captures - - 1 - - name - constant.numeric.hex.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?0(?:x|X)[0-9a-fA-F_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?(?:[0-9_]+)?\.[0-9_]+(?:(?:e|E)[0-9]+)?(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.octal.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?0(?:b|B)[01_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - captures + beginCaptures 1 name constant.numeric.integer.powershell - 2 + 3 name keyword.other.powershell - match - (?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b + begin + (?:(?<!\w)|\G)([-+]?(?:[0-9]+(?i:(?![ed\.])|(?:\.[0-9]*)?((?:(?i:e)[-+]?[0-9]+)?l))|(?:\.[0-9]+)\g<2>))((?i:[kmgtp]b)?)\b + end + \G - captures + beginCaptures 1 name - constant.numeric.integer.powershell + constant.numeric.hex.powershell 2 @@ -882,16 +1769,18 @@ keyword.other.powershell - match - (?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b + begin + (?:(?<!\w)|\G)([-+]?0(?i:x[0-9a-f_]+l?))((?i:[kmgtp]b)?)\b + end + \G - captures + beginCaptures 1 name - constant.numeric.integer.powershell + constant.numeric.decimal.powershell 2 @@ -899,8 +1788,10 @@ keyword.other.powershell - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b + begin + (?:(?<!\w)|\G)([-+]?(?:(?:[0-9]+)|(?=\.[0-9]))(?:\.[0-9]*)?(?i:(?:e[-+]?[0-9]+)?(?!l)d?))((?i:[kmgtp]b)?)\b + end + \G captures @@ -908,7 +1799,7 @@ 1 name - constant.numeric.integer.powershell + constant.numeric.binary.powershell 2 @@ -916,15 +1807,15 @@ keyword.other.powershell - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b + comment + (?:(?<!\w)|\G)([-+]?0(?i:b[01_]+l?))((?i:[kmgtp]b)?)(?!\w) scriptblock begin - \{ + { beginCaptures 0 @@ -934,14 +1825,29 @@ end - \} + (})((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? endCaptures - 0 + 1 name punctuation.section.braces.end.powershell + 2 + + name + variable.other.member.powershell + + 4 + + name + punctuation.definition.comment.powershell + + 3 + + name + comment.line.powershell + name meta.scriptblock.powershell @@ -955,6 +1861,8 @@ type + comment + This is used by both type and index references begin \[ beginCaptures @@ -966,22 +1874,109 @@ end - \] - endCaptures - - 0 + (?<=])(?!\.(?!\.)|::)|(?=[^\p{L}\[\]\s])|(?=\s(?<=\w)) + applyEndPatternLast + + patterns + + + begin + ](?=\.(?!\.)|::) + end + (?!\G(?=\.(?!\.)|::)) + beginCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + + patterns + + + include + #members + + + + + match + \s+ + + match + ] name punctuation.section.bracket.end.powershell - - patterns - match - (?!\d+|\.)(?:\p{L}|\p{N}|\.)+ + (?i:ref)(?=\]) name - storage.type.powershell + storage.modifier.powershell + + + begin + ((?<![\w-])([\p{L}_]\w*(?:\.\g<2>?)?)(?:`+\d+)?(?:\++\g<1>)?) + beginCaptures + + 0 + + patterns + + + include + #type_keywords + + + match + [^\.+]+ + name + storage.type.powershell + + + match + \. + name + punctuation.accessor.type.powershell.powershell + + + match + \+ + name + keyword.operator.type.powershell + + + + + end + (?=[^\s])|(?<=]) + applyEndPatternLast + + patterns + + + include + #type + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!])[^\s\[\]+]+ + + + + + include + #type include @@ -989,6 +1984,105 @@ + typeAdditive + + + type_keywords + + comment + primitive types and base classes often used + patterns + + + match + (?<![\w-])(?i:type|void|string|(?:ps(?:custom)?)?object|hashtable|single|float|double|decimal|s?byte|bool(?:ean)?|char|valuetype|datetime|array|u?int(?:32|16|64)|int|long)(?!\w) + name + keyword.type.powershell + + + match + (?<![\w-])(?i:system|math|text|convert|regex|xml)(?!\w) + name + support.class.powershell + + + + members + + patterns + + + match + \G(\.|::)([\p{L}_]\w*)(?=\() + captures + + 0 + + name + punctuation.accessor.powershell + + 2 + + name + variable.function.powershell + + + + + begin + \G(\.|::)([\p{L}_]\w*)(?=\.(?!\.)|::) + end + (?!\G(?=\.(?!\.)|::)) + beginCaptures + + 1 + + name + punctuation.accessor.powershell + + 2 + + name + variable.other.object.property.powershell + + + patterns + + + include + #commentLine + + + include + #commentblock + + + include + #members + + + + + begin + \G(\.|::)([\p{L}_]\w*) + end + (?!.\G) + beginCaptures + + 1 + + name + punctuation.accessor.powershell + + 2 + + name + variable.other.property.powershell + + + + + variable patterns @@ -996,221 +2090,254 @@ captures - 0 + 1 name constant.language.powershell - 1 + 2 name punctuation.definition.variable.powershell + 5 + + name + punctuation.definition.comment.powershell + + 4 + + name + comment.line.powershell + comment These are special constants. match - (\$)(?i:(False|Null|True))\b + ((\$)(?i:(:?(?:False|Null|True)))\b)((#).*$)? captures - 0 + 1 name - support.constant.variable.powershell + variable.language.builtin.powershell - 1 + 2 name punctuation.definition.variable.powershell - 3 + 4 name variable.other.member.powershell + 6 + + name + punctuation.definition.comment.powershell + + 5 + + name + comment.line.powershell + comment These are the other built-in constants. match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b + ((\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?\b)((#).*$)? captures - 0 + 1 name - support.constant.automatic.powershell + variable.language.builtin.powershell - 1 + 2 name punctuation.definition.variable.powershell - 3 + 4 name variable.other.member.powershell - - comment - Automatic variables are not constants, but they are read-only. In monokai (default) color schema support.variable doesn't have color, so we use constant. - 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 - - - captures - - 0 - - name - variable.language.powershell - - 1 + 6 name - punctuation.definition.variable.powershell + punctuation.definition.comment.powershell - 3 + 5 name - variable.other.member.powershell + comment.line.powershell - comment - Style preference variables as language variables so that they stand out. 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 + ((\$)(?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))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? captures - 0 - - name - variable.other.readwrite.powershell - 1 name - punctuation.definition.variable.powershell + variable.language.powershell 2 name - storage.modifier.scope.powershell + punctuation.definition.variable.powershell 4 name variable.other.member.powershell + 6 + + name + punctuation.definition.comment.powershell + + 5 + + name + comment.line.powershell + + comment + Style preference variables as language variables so that they stand out. match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? + ((\$)(?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}_]\w*))*\b)?\b)((#).*$)? captures - 0 - - name - variable.other.readwrite.powershell - 1 name - punctuation.definition.variable.powershell + variable.other.readwrite.powershell 2 name - punctuation.section.braces.begin.powershell + punctuation.definition.variable.powershell 3 name storage.modifier.scope.powershell - 5 + 4 name - punctuation.section.braces.end.powershell + support.variable.drive.powershell 6 name variable.other.member.powershell + 8 + + name + punctuation.definition.comment.powershell + + 7 + + name + comment.line.powershell + match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? + ((?i:(\$)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? captures - 0 + 1 name variable.other.readwrite.powershell - 1 + 2 name punctuation.definition.variable.powershell - 2 + 3 name - support.variable.drive.powershell + storage.modifier.scope.powershell 4 name - variable.other.member.powershell + support.variable.drive.powershell + comment + splatting cannot have members and certain characters following, including no line comment match - (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? + ((?i:(\@)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))++)))(?![~`!@#$%^*<>\]\\/+-]) captures - 0 + 1 name variable.other.readwrite.powershell - 1 + 2 name punctuation.definition.variable.powershell - 2 + 3 name - punctuation.section.braces.begin.powershell + punctuation.definition.variable.braces.begin.powershell - 3 + 4 name - support.variable.drive.powershell + storage.modifier.scope.powershell 5 name - punctuation.section.braces.end.powershell + support.variable.drive.powershell - 6 + 7 + + name + punctuation.definition.variable.braces.end.powershell + + 8 name variable.other.member.powershell + 10 + + name + punctuation.definition.comment.powershell + + 9 + + name + comment.line.powershell + match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? + ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?)+:|:)))?+([^`{}]|`[`{}]?)+(\}))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? @@ -1291,10 +2418,12 @@ punctuation.definition.variable.powershell + name + meta.embedded.interpolated.powershell comment These are special constants. match - (\$)(?i:(False|Null|True))\b + (\$)(?i:(:?(?:False|Null|True)))\b captures @@ -1302,23 +2431,18 @@ 0 name - support.constant.variable.powershell + variable.language.builtin.powershell 1 name punctuation.definition.variable.powershell - 3 - - name - variable.other.member.powershell - - comment - These are the other built-in constants. + name + meta.embedded.interpolated.powershell match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b + (\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)))\b captures @@ -1326,23 +2450,20 @@ 0 name - support.variable.automatic.powershell + variable.language.builtin.powershell 1 name punctuation.definition.variable.powershell - 3 - - name - variable.other.member.powershell - + name + meta.embedded.interpolated.powershell comment Automatic variables are not constants, but they are read-only... 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 + (\$)(?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)) captures @@ -1350,23 +2471,20 @@ 0 name - variable.language.powershell + variable.language.builtin.powershell 1 name punctuation.definition.variable.powershell - 3 - - name - variable.other.member.powershell - + name + meta.embedded.interpolated.powershell comment Style preference variables as language variables so that they stand out. 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))\b + (\$)(?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)))\b captures @@ -1386,14 +2504,16 @@ name storage.modifier.scope.powershell - 4 + 3 name - variable.other.member.powershell + support.variable.drive.powershell + name + meta.embedded.interpolated.powershell match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+)) + (?i:(\$)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+)) captures @@ -1411,80 +2531,28 @@ 2 name - storage.modifier.scope.powershell - - 4 - - name - keyword.other.powershell - - 5 - - name - variable.other.member.powershell - - - match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) - - - captures - - 0 - - name - variable.other.readwrite.powershell - - 1 - - name - punctuation.definition.variable.powershell + punctuation.section.braces.begin.powershell - 2 + 3 name - support.variable.drive.powershell + storage.modifier.scope.powershell 4 - - name - variable.other.member.powershell - - - match - (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+)) - - - captures - - 0 - - name - variable.other.readwrite.powershell - - 1 - - name - punctuation.definition.variable.powershell - - 2 - - name - punctuation.section.braces.begin - - 3 name support.variable.drive.powershell - 5 + 6 name - punctuation.section.braces.end + punctuation.section.braces.end.powershell + name + meta.embedded.interpolated.powershell match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) + (?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?)+:|:)))?+([^`{}]|`[`{}]?)+(\})) @@ -1506,7 +2574,7 @@ end - (\}) + (\})((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? endCaptures 1 @@ -1514,42 +2582,34 @@ name punctuation.section.braces.end.powershell + 2 + + name + variable.other.member.powershell + + 4 + + name + punctuation.definition.comment.powershell + + 3 + + name + comment.line.powershell + name meta.hashtable.powershell patterns - captures - - 1 - - name - punctuation.definition.string.begin.powershell - - 2 - - name - variable.other.readwrite.powershell - - 3 - - name - punctuation.definition.string.end.powershell - - 4 - - name - keyword.operator.assignment.powershell - - match - \b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)? + \b(\w+)(?=\s*=) name - meta.hashtable.assignment.powershell + entity.name.variable.property.powershell - include + comment #scriptblock @@ -1561,7 +2621,7 @@ doubleQuotedString begin - (?<!(?<!`)")" + (?:["\x{201C}-\x{201E}]) beginCaptures 0 @@ -1571,7 +2631,9 @@ end - "(?!") + (?:["\x{201C}-\x{201E}]) + applyEndPatternLast + endCaptures 0 @@ -1585,24 +2647,20 @@ patterns - match + comment (?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b include #variableNoProperty - - include - #variable - include #doubleQuotedStringEscapes include - #interpolation + #stringInterpolation match From 63d967da4712b629370bc3662ed6f018327aa50e Mon Sep 17 00:00:00 2001 From: msftrncs Date: Sun, 27 Jan 2019 03:16:37 -0600 Subject: [PATCH 2/6] overhaul variable members into unified accessors --- PowerShellSyntax.tmLanguage | 1629 ++++++++++++++++++++--------------- 1 file changed, 920 insertions(+), 709 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 32d8e89..3aecf04 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -58,10 +58,6 @@ include #hashtable - - include - #doubleQuotedString - include #scriptblock @@ -73,70 +69,8 @@ #argumentModeEscapes - begin - ['\x{2018}-\x{201B}] - beginCaptures - - 0 - - name - punctuation.definition.string.begin.powershell - - - end - ['\x{2018}-\x{201B}] - applyEndPatternLast - - endCaptures - - 0 - - name - punctuation.definition.string.end.powershell - - - name - string.quoted.single.powershell - patterns - - - match - ['\x{2018}-\x{201B}]{2} - name - constant.character.escape.powershell - - - - - begin - @(?:["\x{201C}-\x{201E}])(?=\s*$) - end - ^(?:["\x{201C}-\x{201E}])@ - name - string.quoted.double.heredoc.powershell - patterns - - - include - #variableNoProperty - - - include - #doubleQuotedHereStringEscapes - - - include - #stringInterpolation - - - - - begin - @['\x{2018}-\x{201B}](?=\s*$) - end - ^['\x{2018}-\x{201B}]@ - name - string.quoted.single.heredoc.powershell + include + #quotedStrings_Members include @@ -144,52 +78,67 @@ begin - (@)(\() - beginCaptures - - 1 - - name - keyword.other.array.begin.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - + (?=@\() end - (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? - endCaptures - - 1 - - name - punctuation.section.group.end.powershell - - 2 - - name - variable.other.member.powershell - - 4 - - name - punctuation.definition.comment.powershell - - 3 + (?!.\G) + applyEndPatternLast + + patterns + + begin + (@)(\() + beginCaptures + + 1 + + name + keyword.other.array.begin.powershell + + 2 + + name + punctuation.section.group.begin.powershell + + + end + \) + endCaptures + + 0 + + name + punctuation.section.group.end.powershell + + name - comment.line.powershell + meta.group.array-expression.powershell + patterns + + + include + $self + + - - name - meta.group.array-expression.powershell - patterns - - include - $self + begin + (?<=\))(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + @@ -784,6 +733,14 @@ + + include + #commentBlock + + + include + #commentLine + match [^;\s][^;]+ @@ -1067,6 +1024,25 @@ + + comment + when nothing else matches in usual tokenizing, consume it to prevent other patterns from striking in the middle of what might be a command name. + begin + (?=[^\s]) + end + (?=[(){}|;&\s]) + applyEndPatternLast + + contentName + unquoted.text.powershell + patterns + + + include + #unquotedStrings_text + + + repository @@ -1105,7 +1081,7 @@ commentLine begin - (?:(?<![`\\\w*\[\]/.?=:~!$^%+-])|\G)(#)#* + (#)#* captures 1 @@ -1392,7 +1368,7 @@ begin - (?<![\w-])(?:(global|local|script|private)(:))?([\p{L}:_\\/\[\]`-][[`\\\w*\[\]/.?<>=:~!@#$^%+-]]*) + (?<![\w-])(?:(global|local|script|private)(:))?(?:(?=[\p{L}:_\\/\[\]`-])|(?<=:)(?=["\x{201C}-\x{201E}'\x{2018}-\x{201B}])) beginCaptures 1 @@ -1405,11 +1381,6 @@ name punctuation.separator.colon.powershell - 3 - - name - entity.name.function.powershell - end (?=[//s])|(?<=}) @@ -1419,51 +1390,79 @@ begin - { - beginCaptures - - 0 + \G + end + (?=[(){}|;&\s]) + applyEndPatternLast + + contentName + entity.name.function.powershell + patterns + - name - punctuation.section.braces.begin.powershell + include + #unquotedStrings_text - + + + + begin + (?<!\G)(?<!}) end - } - endCaptures - - 0 + (?=[//s])|(?<=}) + applyEndPatternLast + + patterns + + begin + { + beginCaptures + + 0 + + name + punctuation.section.braces.begin.powershell + + + end + } + endCaptures + + 0 + + name + punctuation.section.braces.end.powershell + + name - punctuation.section.braces.end.powershell + meta.function.powershell + patterns + + + include + $self + + - - name - meta.function.powershell - patterns - include - $self + #invocationParameterSet + + + include + #commentBlock + + + include + #commentLine + + + match + (?<!})[^\s{}()]+ - - include - #invocationParameterSet - - - include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{}()]+ - @@ -1517,139 +1516,129 @@ interpolatedStringContent begin - \( - beginCaptures - - 0 - - name - punctuation.section.group.begin.powershell - - - name - interpolated.simple.source.powershell + (?=\() end - (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? - endCaptures - - 1 - - name - punctuation.section.group.end.powershell - - 2 - - name - variable.other.member.powershell - - 4 - - name - punctuation.definition.comment.powershell - - 3 + (?!.\G) + applyEndPatternLast + + patterns + + begin + \( + beginCaptures + + 0 + + name + punctuation.section.group.begin.powershell + + name - comment.line.powershell - - - patterns - - - include - $self + interpolated.simple.source.powershell + end + \) + endCaptures + + 0 + + name + punctuation.section.group.end.powershell + + + patterns + + + include + $self + + - include - #interpolation + begin + (?<=\))(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + interpolation begin - (\$)(\() - beginCaptures - - 1 - - name - keyword.other.subexpression.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - name - meta.group.complex.subexpression.powershell + (?=\$\() end - (\))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? - endCaptures - - 1 - - name - punctuation.section.group.end.powershell - - 2 - - name - variable.other.member.powershell - - 4 - - name - punctuation.definition.comment.powershell - - 3 - - name - comment.line.powershell - - + (?!.\G) + applyEndPatternLast + patterns - include - $self - - - comment - #commands - - - comment - #variable - - - comment - #interpolatedStringContent - - - comment - #function - - - comment - #attribute - - - comment - #type - - - comment - #hashtable - - - comment - #doubleQuotedString + begin + (\$)(\() + beginCaptures + + 1 + + name + keyword.other.subexpression.powershell + + 2 + + name + punctuation.section.group.begin.powershell + + + name + meta.group.complex.subexpression.powershell + end + \) + endCaptures + + 0 + + name + punctuation.section.group.end.powershell + + + patterns + + + include + $self + + - comment - #scriptblock + begin + (?<=\))(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + @@ -1686,50 +1675,10 @@ patterns - - comment - #interpolation - include $self - - comment - #commands - - - comment - #variable - - - comment - #interpolatedStringContent - - - comment - #function - - - comment - #attribute - - - comment - #type - - - comment - #hashtable - - - comment - #doubleQuotedString - - - comment - #scriptblock - numericConstant @@ -1751,7 +1700,7 @@ begin - (?:(?<!\w)|\G)([-+]?(?:[0-9]+(?i:(?![ed\.])|(?:\.[0-9]*)?((?:(?i:e)[-+]?[0-9]+)?l))|(?:\.[0-9]+)\g<2>))((?i:[kmgtp]b)?)\b + (?:(?<!\w)|\G)([-+]?(?:[0-9]+(?i:(?![ed]|\.(?!\.))|(?:\.[0-9]*)?((?:(?i:e)[-+]?[0-9]+)?l))|(?:\.[0-9]+)\g<2>))((?i:[kmgtp]b)?)\b end \G @@ -1815,106 +1764,193 @@ scriptblock begin - { - beginCaptures - - 0 - - name - punctuation.section.braces.begin.powershell - - - end - (})((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? - endCaptures - - 1 - - name - punctuation.section.braces.end.powershell - - 2 - - name - variable.other.member.powershell - - 4 - - name - punctuation.definition.comment.powershell - - 3 - - name - comment.line.powershell - - - name - meta.scriptblock.powershell - patterns - - - include - $self - - - - type - - comment - This is used by both type and index references - begin - \[ - beginCaptures - - 0 - - name - punctuation.section.bracket.begin.powershell - - + (?={) end - (?<=])(?!\.(?!\.)|::)|(?=[^\p{L}\[\]\s])|(?=\s(?<=\w)) + (?!.\G) applyEndPatternLast - + patterns begin - ](?=\.(?!\.)|::) - end - (?!\G(?=\.(?!\.)|::)) + { beginCaptures 0 name - punctuation.section.bracket.end.powershell + punctuation.section.braces.begin.powershell - patterns + end + } + endCaptures + + 0 + + name + punctuation.section.braces.begin.powershell + + + name + meta.scriptblock.powershell + patterns include - #members + $self - match - \s+ + begin + (?<=})(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + + + + type + + comment + This is used by both type attribute references, attribute references need to be moved here + begin + (?=\[) + end + (?!.\G) + applyEndPatternLast + + patterns + - match + begin + \[ + beginCaptures + + 0 + + name + punctuation.section.bracket.begin.powershell + + + end ] - name - punctuation.section.bracket.end.powershell + endCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + + applyEndPatternLast + + Name + meta.type-reference.powershell + patterns + + + match + (?i:ref)(?=\]) + name + storage.modifier.powershell + + + include + #type_SubType + + + match + [^\s\W]+ + + - match - (?i:ref)(?=\]) - name - storage.modifier.powershell + begin + (?<=])(?=\.(?!\.)|::|\[) + beginCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + include + #type + + + match + [^\s\W]+ + + + + + + type_SubType + + patterns + + + begin + (\[) + beginCaptures + + 0 + + name + punctuation.section.bracket.begin.powershell + + + end + (])|(?>[^\s\p{L},]) + endCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + + applyEndPatternLast + + comment:contentName + meta.type-reference.powershell + patterns + + + include + #type_SubType + + + match + (?<!])[^\s\[\]+]+ + + begin @@ -1958,15 +1994,7 @@ include - #type - - - include - #commentBlock - - - include - #commentLine + #type_SubType match @@ -1976,17 +2004,14 @@ include - #type + #commentBlock include - $self + #commentLine - typeAdditive - - type_keywords comment @@ -1995,7 +2020,7 @@ match - (?<![\w-])(?i:type|void|string|(?:ps(?:custom)?)?object|hashtable|single|float|double|decimal|s?byte|bool(?:ean)?|char|valuetype|datetime|array|u?int(?:32|16|64)|int|long)(?!\w) + (?<![\w-])(?i:type|void|switch|(?:ps(?:custom)?)?object|hashtable|string|single|float|double|decimal|s?byte|bool(?:ean)?|char|valuetype|datetime|array|u?int(?:32|16|64)|int|long)(?!\w) name keyword.type.powershell @@ -2007,148 +2032,249 @@ - members + accessors patterns - - match - \G(\.|::)([\p{L}_]\w*)(?=\() - captures - - 0 - - name - punctuation.accessor.powershell - - 2 - - name - variable.function.powershell - - - begin - \G(\.|::)([\p{L}_]\w*)(?=\.(?!\.)|::) - end - (?!\G(?=\.(?!\.)|::)) + \G(?:\.(?!\.)|::) beginCaptures - 1 + 0 name punctuation.accessor.powershell - 2 - - name - variable.other.object.property.powershell - + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + patterns include - #commentLine + #members include - #commentblock + #commentLine include - #members + #commentBlock + + + match + [^\s\W]+ + + + comment + consume spaces and comments and line ends until the next token appears + begin + \G(?<=\.|::)(?!\S) + end + (?=.) + applyEndPatternLast + + patterns + + + match + \s+ + + + include + #commentLine + + + include + #commentBlock + + begin - \G(\.|::)([\p{L}_]\w*) + (?=\[) end (?!.\G) - beginCaptures - - 1 + applyEndPatternLast + + patterns + + begin + \[ + beginCaptures + + 0 + + name + punctuation.section.bracket.begin.powershell + + + end + ] + endCaptures + + 0 + + name + punctuation.section.bracket.end.powershell + + name - punctuation.accessor.powershell + meta.index.powershell + patterns + + + include + $self + + - 2 - name - variable.other.property.powershell + begin + (?<=])(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + - + + + + include + #commentLine + + + include + #commentBlock - variable + members patterns + match + (?<!\w-)((?i:(foreach|where)(?=[\({]))) + name + support.function.powershell + + + match + [\p{L}_]\w*(?=\() captures - 1 + 0 name - constant.language.powershell + variable.function.powershell - 2 + + + + begin + [\p{L}_]\w*(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + beginCaptures + + 0 name - punctuation.definition.variable.powershell + variable.other.object.property.powershell - 5 + + patterns + - name - punctuation.definition.comment.powershell + include + #accessors - 4 - name - comment.line.powershell + match + [^\s\W]+ - - comment - These are special constants. - match - ((\$)(?i:(:?(?:False|Null|True)))\b)((#).*$)? + - captures + begin + [\p{L}_]\w* + end + (?=[^\s\p{L}]|\n) + beginCaptures - 1 + 0 name - variable.language.builtin.powershell + variable.other.property.powershell - 2 + + patterns + - name - punctuation.definition.variable.powershell + include + #commentLine - 4 - name - variable.other.member.powershell + include + #commentBlock + + + match + [^\s\W]+ - 6 + + + + include + #quotedStrings_Members + + + + variable_inner + + comment + seperate the parts of the variable name and scope them + patterns + + + captures + + 1 name - punctuation.definition.comment.powershell + constant.language.powershell - 5 + 2 name - comment.line.powershell + punctuation.definition.variable.powershell comment - These are the other built-in constants. + These are special constants. match - ((\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?\b)((#).*$)? + ((\$)(?i:(:?(?:False|Null|True)))\b) captures @@ -2163,24 +2289,28 @@ name punctuation.definition.variable.powershell - 4 - - name - variable.other.member.powershell - - 6 + + comment + These are the other built-in constants. + match + ((\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)\b))) + + + captures + + 1 name - punctuation.definition.comment.powershell + variable.language.builtin.powershell - 5 + 2 name - comment.line.powershell + punctuation.definition.variable.powershell 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))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? + ((\$)(?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))) captures @@ -2195,26 +2325,11 @@ name punctuation.definition.variable.powershell - 4 - - name - variable.other.member.powershell - - 6 - - name - punctuation.definition.comment.powershell - - 5 - - name - comment.line.powershell - comment Style preference variables as language variables so that they stand out. 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}_]\w*))*\b)?\b)((#).*$)? + ((\$)(?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)\b))) captures @@ -2237,26 +2352,16 @@ 4 name - support.variable.drive.powershell - - 6 - - name - variable.other.member.powershell - - 8 - - name - punctuation.definition.comment.powershell + punctuation.separator.colon.powershell - 7 + 5 name - comment.line.powershell + support.variable.drive.powershell match - ((?i:(\$)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? + ((?i:(\$)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+))) captures @@ -2277,6 +2382,11 @@ storage.modifier.scope.powershell 4 + + name + punctuation.separator.colon.powershell + + 5 name support.variable.drive.powershell @@ -2285,7 +2395,7 @@ comment splatting cannot have members and certain characters following, including no line comment match - ((?i:(\@)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))++)))(?![~`!@#$%^*<>\]\\/+-]) + ((?i:(\@)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))++)))(?![~`!@#$%^*<>\]\\/+-]) captures @@ -2320,24 +2430,96 @@ name punctuation.definition.variable.braces.end.powershell - 8 + + match + ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?+)+:|:)))?+([^`{}]|`[`{}]?+)+(\}))) + + + + variable + + patterns + + + begin + (?=\$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\}))) + end + (?!.\G) + applyEndPatternLast + + patterns + - name - variable.other.member.powershell + begin + \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\}))(?=\.(?!\.)|::|\[) + beginCaptures + + 0 + + patterns + + + include + #variable_inner + + + + + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + - 10 - name - punctuation.definition.comment.powershell + begin + \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\})) + end + (?!.\G) + applyEndPatternLast + + captures + + 0 + + patterns + + + include + #variable_inner + + + + - 9 + + + + match + @(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))++(?![~`!@#$%^*<>\]\\/"\x{201C}-\x{201E}'\x{2018}-\x{201B}+-]) + captures + + 0 - name - comment.line.powershell + patterns + + + include + #variable_inner + + - match - ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?)+:|:)))?+([^`{}]|`[`{}]?)+(\}))((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?)((#).*$)? @@ -2402,271 +2584,300 @@ variableNoProperty + match + (\$)((?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\})) + captures + + 0 + + patterns + + + include + #variable_inner + + + + + name + meta.embedded.interpolated.powershell + + hashtable + + begin + (?=@\{) + end + (?!.\G) + applyEndPatternLast + patterns - captures + begin + (@)(\{) + beginCaptures - 0 + 1 name - constant.language.powershell + keyword.other.hashtable.begin.powershell - 1 + 2 name - punctuation.definition.variable.powershell + punctuation.section.braces.begin.powershell - name - meta.embedded.interpolated.powershell - comment - These are special constants. - match - (\$)(?i:(:?(?:False|Null|True)))\b - - - captures + end + \} + endCaptures 0 name - variable.language.builtin.powershell - - 1 - - name - punctuation.definition.variable.powershell + punctuation.section.braces.end.powershell name - meta.embedded.interpolated.powershell - match - (\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)))\b + meta.hashtable.powershell + patterns + + + match + \b(\w+)(?=\s*=) + name + entity.name.variable.property.powershell + + + comment + #scriptblock + + + include + $self + + - captures - - 0 + begin + (?<=\})(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + - name - variable.language.builtin.powershell + include + #accessors - 1 - name - punctuation.definition.variable.powershell + match + [^\s\W]+ - - name - meta.embedded.interpolated.powershell - comment - Automatic variables are not constants, but they are read-only... - 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)) + + + + quotedStrings_Members + + begin + (?=@?(['\x{2018}-\x{201B}"\x{201C}-\x{201E}]))(?:(?<!@\g<1>)|\s*$) + end + (?!.\G) + applyEndPatternLast + + patterns + - captures + begin + ['\x{2018}-\x{201B}] + beginCaptures 0 name - variable.language.builtin.powershell + punctuation.definition.string.begin.powershell - 1 + + end + ['\x{2018}-\x{201B}] + applyEndPatternLast + + endCaptures + + 0 name - punctuation.definition.variable.powershell + punctuation.definition.string.end.powershell name - meta.embedded.interpolated.powershell - comment - Style preference variables as language variables so that they stand out. - 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)))\b - - - captures - - 0 + string.quoted.single.powershell + patterns + + match + ['\x{2018}-\x{201B}]{2} name - variable.other.readwrite.powershell + constant.character.escape.powershell - 1 + + + + begin + @(?:["\x{201C}-\x{201E}])(?=\s*$) + end + ^(?:["\x{201C}-\x{201E}])@ + name + string.quoted.double.heredoc.powershell + patterns + - name - punctuation.definition.variable.powershell + include + #variableNoProperty - 2 - name - storage.modifier.scope.powershell + include + #doubleQuotedHereStringEscapes - 3 - name - support.variable.drive.powershell + include + #stringInterpolation - + + + + begin + @['\x{2018}-\x{201B}](?=\s*$) + end + ^['\x{2018}-\x{201B}]@ name - meta.embedded.interpolated.powershell - match - (?i:(\$)(?:(?:(global|local|private|script|using|workflow):|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+)) + string.quoted.single.heredoc.powershell - captures + begin + (?:["\x{201C}-\x{201E}]) + beginCaptures 0 name - variable.other.readwrite.powershell - - 1 - - name - punctuation.definition.variable.powershell + punctuation.definition.string.begin.powershell - 2 + + end + (?:["\x{201C}-\x{201E}]) + applyEndPatternLast + + endCaptures + + 0 name - punctuation.section.braces.begin.powershell + punctuation.definition.string.end.powershell - 3 + + name + string.quoted.double.powershell + patterns + - name - storage.modifier.scope.powershell + include + #variableNoProperty - 4 - name - support.variable.drive.powershell + include + #doubleQuotedStringEscapes - 6 - name - punctuation.section.braces.end.powershell + include + #stringInterpolation - - name - meta.embedded.interpolated.powershell - match - (?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?)+:|:)))?+([^`{}]|`[`{}]?)+(\})) - - - - hashtable - - begin - (@)(\{) - beginCaptures - - 1 - - name - keyword.other.hashtable.begin.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - - end - (\})((?:(?:\.|::)(?:[\p{L}_]\w*))*\b)?((#).*$)? - endCaptures - - 1 - - name - punctuation.section.braces.end.powershell - - 2 - - name - variable.other.member.powershell - - 4 - - name - punctuation.definition.comment.powershell - - 3 - - name - comment.line.powershell - - - name - meta.hashtable.powershell - patterns - - - match - \b(\w+)(?=\s*=) - name - entity.name.variable.property.powershell - - - comment - #scriptblock + - include - $self + begin + (?<=^(['\x{2018}-\x{201B}"\x{201C}-\x{201E}])@|(?<=\g<1>))(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + - doubleQuotedString + unquotedStrings_text - begin - (?:["\x{201C}-\x{201E}]) - beginCaptures - - 0 - - name - punctuation.definition.string.begin.powershell - - - end - (?:["\x{201C}-\x{201E}]) - applyEndPatternLast - - endCaptures - - 0 - - name - punctuation.definition.string.end.powershell - - - name - string.quoted.double.powershell patterns - comment - (?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b - - - include - #variableNoProperty - - - include - #doubleQuotedStringEscapes + begin + ['\x{2018}-\x{201B}] + end + ['\x{2018}-\x{201B}] + applyEndPatternLast + + patterns + + + match + ['\x{2018}-\x{201B}]{2} + name + constant.character.escape.powershell + + - include - #stringInterpolation + begin + ["\x{201C}-\x{201E}] + end + ["\x{201C}-\x{201E}] + applyEndPatternLast + + patterns + + + include + #doubleQuotedStringEscapes + + + begin + \$\( + end + \) + patterns + + + include + #unquotedStrings_text + + + + - match - `\s*$ - name - keyword.other.powershell + begin + \$\( + end + \) + patterns + + + include + #unquotedStrings_text + + From 49649b95e5d6153440a82e85686340a23bb52268 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Sun, 27 Jan 2019 15:15:37 -0600 Subject: [PATCH 3/6] correct type reference meta scope, excess ':' in accessor, variable tweaks --- PowerShellSyntax.tmLanguage | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 3aecf04..cbe1347 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -1858,7 +1858,7 @@ applyEndPatternLast - Name + name meta.type-reference.powershell patterns @@ -1938,7 +1938,7 @@ applyEndPatternLast - comment:contentName + name meta.type-reference.powershell patterns @@ -2038,7 +2038,7 @@ begin - \G(?:\.(?!\.)|::) + \G(?:\.(?!\.)|(?<!:)::) beginCaptures 0 @@ -2421,18 +2421,23 @@ storage.modifier.scope.powershell 5 + + name + punctuation.separator.colon.powershell + + 6 name support.variable.drive.powershell - 7 + 8 name punctuation.definition.variable.braces.end.powershell match - ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow):|((?:[^`{}:]|`[`{}]?+)+:|:)))?+([^`{}]|`[`{}]?+)+(\}))) + ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[^`{}:]|`[`{}]?+)+:|:)))?+([^`{}]|`[`{}]?+)+(\}))) @@ -2442,7 +2447,7 @@ begin - (?=\$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\}))) + (?=\$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\}))) end (?!.\G) applyEndPatternLast @@ -2451,7 +2456,7 @@ begin - \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\}))(?=\.(?!\.)|::|\[) + \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\}))(?=\.(?!\.)|::|\[) beginCaptures 0 @@ -2483,7 +2488,7 @@ begin - \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\})) + \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\})) end (?!.\G) applyEndPatternLast From 21f3e5887182e752cb00453c9193d39cf1f8207e Mon Sep 17 00:00:00 2001 From: msftrncs Date: Mon, 28 Jan 2019 03:50:42 -0600 Subject: [PATCH 4/6] unquoted text needs arg mode escapes, ignore `(space) before funct names --- PowerShellSyntax.tmLanguage | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index cbe1347..2a92945 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -1120,7 +1120,7 @@ match - `(?:['\x{2018}-\x{201B}0abnfrvt"\x{201C}-\x{201E}$`\n]) + `(?:['0abnfrvt\x{2018}-\x{201B}"\x{201C}-\x{201E}$`\n]) name constant.character.escape.powershell @@ -1312,7 +1312,7 @@ match - `(?:[0abnfrvt\s"\x{201C}-\x{201E}$`]|(?=$)) + `(?:[`0abnfrvt\s"\x{201C}-\x{201E}$]) name constant.character.escape.powershell @@ -1336,7 +1336,7 @@ match - `(?:[0abnfrvt\s"\x{201C}-\x{201E}'\x{2018}-\x{201B}$`]|(?=$)) + `(?:[`0abnfrvt\s"\x{201C}-\x{201E}'\x{2018}-\x{201B}$]) name constant.character.escape.powershell @@ -1368,7 +1368,7 @@ begin - (?<![\w-])(?:(global|local|script|private)(:))?(?:(?=[\p{L}:_\\/\[\]`-])|(?<=:)(?=["\x{201C}-\x{201E}'\x{2018}-\x{201B}])) + (?<![\w-])(?:(global|local|script|private)(:))?(?:(?=[\p{L}:_\\/\[\]-]|`(?!\s))|(?<=:)(?=[`"\x{201C}-\x{201E}'\x{2018}-\x{201B}])) beginCaptures 1 @@ -1465,6 +1465,12 @@ + + match + `\s + name + invalid.character.escape.powershell + include #commentBlock @@ -2826,6 +2832,16 @@ patterns + + match + `\s + name + constant.character.escape.powershell + + + include + #argumentModeEscapes + begin ['\x{2018}-\x{201B}] From f6f6fb1e2c15979f072b4329d097d77fa2785ec5 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Mon, 28 Jan 2019 04:23:24 -0600 Subject: [PATCH 5/6] argument mode escapes ran before unquoted text --- PowerShellSyntax.tmLanguage | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 2a92945..9655109 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -62,16 +62,6 @@ include #scriptblock - - comment - Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) - include - #argumentModeEscapes - - - include - #quotedStrings_Members - include #numericConstant @@ -1024,6 +1014,10 @@ + + include + #quotedStrings_Members + comment when nothing else matches in usual tokenizing, consume it to prevent other patterns from striking in the middle of what might be a command name. @@ -1043,6 +1037,12 @@ + + comment + Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) + include + #argumentModeEscapes + repository From 23624de710b6d035c937f5c1a5a716ea8be07d71 Mon Sep 17 00:00:00 2001 From: msftrncs Date: Thu, 31 Jan 2019 02:34:08 -0600 Subject: [PATCH 6/6] numerous corrections and optimizations, supports emdash, unicode escape --- PowerShellSyntax.tmLanguage | 1560 ++++++++++++++++++++++------------- 1 file changed, 972 insertions(+), 588 deletions(-) diff --git a/PowerShellSyntax.tmLanguage b/PowerShellSyntax.tmLanguage index 9655109..505e898 100644 --- a/PowerShellSyntax.tmLanguage +++ b/PowerShellSyntax.tmLanguage @@ -12,23 +12,21 @@ PowerShell patterns - - include - #commentBlock - match - [2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>> + [2-6]>&1|[1-6]?>>? name keyword.operator.redirection.powershell - include - #commands + match + <(?!#) + name + invalid.reserved.redirection.powershell include - #commentLine + #commands include @@ -42,10 +40,6 @@ include #function - - include - #attribute - include #UsingDirective @@ -258,7 +252,7 @@ begin - (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + (?<![\w-])(?!`)([\p{L}_`][\w`+]*(?:\.\g<1>?)?) beginCaptures 0 @@ -309,7 +303,7 @@ begin - (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + (?<![\w-])(?!`)([\p{L}_`][\w`+]*(?:\.\g<1>?)?) beginCaptures 0 @@ -343,63 +337,31 @@ include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{},]+ + #notCode include - #commentBlock - - - include - #commentLine + #notCode include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{},]+ + #notCode include - #commentBlock - - - include - #commentLine + #notCode include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{}:]+ + #notCode @@ -466,10 +428,6 @@ (?=[;{]) patterns - - comment - (?<![;{])\s+ - begin (?i:base) @@ -485,10 +443,6 @@ (?=[;{]) patterns - - comment - (?<![;{])\s+ - include #invocationParameterSet @@ -515,11 +469,7 @@ include - #commentBlock - - - include - #commentLine + #notCode @@ -578,7 +528,7 @@ begin - (?<![\w-])([\p{L}_]\w*(?:\.\g<1>?)?) + (?<![\w-])(?!`)([\p{L}_`][\w`+]*(?:\.\g<1>?)?) beginCaptures 0 @@ -612,39 +562,19 @@ include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{}]+ + #notCode include - #commentBlock - - - include - #commentLine + #notCode include - #commentBlock - - - include - #commentLine - - - match - (?<!})[^\s{}:]+ + #notCode @@ -673,6 +603,12 @@ meta.enumeration.powershell patterns + + match + ; + name + punctuation.terminator.statement.powershell + begin (?<![\w-])([\p{L}_]\w*) @@ -685,7 +621,7 @@ end - (?=[;}\n]) + (?<=;)|(?=[}\n]) patterns @@ -700,7 +636,7 @@ end - (?=[;}\n]) + (?<=;)|(?=[}\n]) patterns @@ -711,456 +647,149 @@ include - #argumentModeEscapes - - - include - #commentBlock - - - include - #commentLine + #notCode include - #commentBlock - - - include - #commentLine - - - match - [^;\s][^;]+ + #notCode include - #argumentModeEscapes - - - include - #commentBlock - - - include - #commentLine + #notCode - begin - (?:(?<!\w)|\G)-(?i:is(?:not)?|as)(?!\p{L}) - beginCaptures - - 0 - - name - keyword.operator.comparison.type.powershell - - - end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - + include + #operators + + + include + #quotedStrings_Members + + + include + #notCode + + + comment + Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) + include + #argumentModeEscapes + + repository + + commentBlock begin - (?:(?<!\w|!)|\G)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) + <# beginCaptures 0 name - keyword.operator.comparison.powershell + punctuation.definition.comment.block.begin.powershell end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - - - - begin - (?:(?<!\w|!)|\G)-(?i:join|split)(?!\p{L}) - beginCaptures + #> + endCaptures 0 name - keyword.operator.unary.powershell + punctuation.definition.comment.block.end.powershell - end - (?!\s) - applyEndPatternLast - + name + comment.block.powershell patterns include - #commentBlock - - - include - #commentLine + #commentEmbeddedDocs + commentLine begin - (?:(?<!\w|!)|\G)-(?i:and|or|not|xor)(?!\p{L})|! - beginCaptures + (#)#* + captures - 0 + 1 name - keyword.operator.logical.powershell + punctuation.definition.comment.powershell end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - - - - begin - (?:(?<!\w|!)|\G)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L}) - beginCaptures + $(?=(\n)?) + endCaptures - 0 + 1 name - keyword.operator.bitwise.powershell + comment.line.powershell - end - (?!\s) - applyEndPatternLast - + name + comment.line.powershell patterns include - #commentBlock + #commentEmbeddedDocs include - #commentLine + #RequiresDirective + argumentModeEscapes - begin - (?:(?<!\w|!)|\G)-(?i:f)(?!\p{L}) - beginCaptures - - 0 + patterns + + match + `(?:[`0abefnrtv"\x{201C}-\x{201E}'\x{2018}-\x{201B}$@#\n]) name - keyword.operator.string-format.powershell + constant.character.escape.powershell - - end - (?!\s) - applyEndPatternLast - - patterns - include - #commentBlock + #unicodeEscape - include - #commentLine + match + ` + name + invalid.character.escape.powershell - - match - (?:(?<!\w|!)|\G)-\p{L}\w* - name - entity.name.parameter.powershell - - - match - \+\+|-- - name - keyword.operator.unary.powershell - + attribute begin - [+%*/-]?=|[+/*%-](?!\p{L}) + (?i:(?:(?:cmdletbinding|alias|flags|outputtype|parameter|validate(?:not(?:null(?:orempty)?)|count|set|script|range|pattern|length)|allow(?:null|empty(?:collection|string))|supportswildcards)(?=\())|ordered) beginCaptures 0 name - keyword.operator.assignment.powershell + support.function.attribute.powershell end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - - - - match - \|\||&&|; - name - punctuation.terminator.statement.powershell - - - begin - &|(?<!\w|!)(?<!\.)\.(?=\s)|,|\| - beginCaptures - - 0 - - name - keyword.operator.other.powershell - - - end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - - - - comment - the range operator is only available after an operand (binary operator) - begin - (?<!^)\s*(\.\.) - beginCaptures - - 1 - - name - keyword.operator.range.powershell - - - end - (?!\s) - applyEndPatternLast - - patterns - - - include - #commentBlock - - - include - #commentLine - - - - - include - #quotedStrings_Members - - - comment - when nothing else matches in usual tokenizing, consume it to prevent other patterns from striking in the middle of what might be a command name. - begin - (?=[^\s]) - end - (?=[(){}|;&\s]) - applyEndPatternLast - - contentName - unquoted.text.powershell - patterns - - - include - #unquotedStrings_text - - - - - comment - Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) - include - #argumentModeEscapes - - - repository - - commentBlock - - begin - <# - beginCaptures - - 0 - - name - punctuation.definition.comment.block.begin.powershell - - - end - #> - endCaptures - - 0 - - name - punctuation.definition.comment.block.end.powershell - - - name - comment.block.powershell - patterns - - - include - #commentEmbeddedDocs - - - - commentLine - - begin - (#)#* - captures - - 1 - - name - punctuation.definition.comment.powershell - - - end - $(?=(\n)?) - endCaptures - - 1 - - name - comment.line.powershell - - - name - comment.line.powershell - patterns - - - include - #commentEmbeddedDocs - - - include - #RequiresDirective - - - - argumentModeEscapes - - patterns - - - match - `(?:['0abnfrvt\x{2018}-\x{201B}"\x{201C}-\x{201E}$`\n]) - name - constant.character.escape.powershell - - - match - ` - name - invalid.character.escape.powershell - - - - attribute - - begin - (\[)\s*\b(?i)(cmdletbinding|alias|flags|ordered|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|supportswildcards|validatescript|validaterange|validatepattern|validatelength)\b - beginCaptures - - 1 - - name - punctuation.section.bracket.begin.powershell - - 2 - - name - support.function.attribute.powershell - - - end - \] - endCaptures - - 0 - - name - punctuation.section.bracket.end.powershell - - - name - meta.attribute.powershell + (?!\G\() + name + meta.attribute.powershell patterns @@ -1188,7 +817,7 @@ match - (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage|ignorecase)\b + (?i)\b(mandatory|valuefrom(?:pipeline(?:bypropertyname)?|remainingarguments)|position|(?:default)?parametersetname|supports(?:shouldprocess|paging)|positionalbinding|help(?:uri|message)|confirmimpact|ignorecase)\b captures 1 @@ -1276,7 +905,7 @@ match - (?:^|\G)(?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))(?:\s*$) + (?:^|\G)(?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELP(?:CATEGORY|TARGETNAME)|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS))(?:\s*$) name comment.documentation.embedded.powershell @@ -1300,22 +929,46 @@ match - (?:^|\G)(?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) + (?:^|\G)(?i:\s*(\.)(PARAMETER|FORWARDHELP(?:CATEGORY|TARGETNAME)|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([\w-]+)) name comment.documentation.embedded.powershell + unicodeEscape + + comment + `u{xxxx} added in PowerShell 6.0 + patterns + + + match + `u\{(?:(?:10)?([0-9a-fA-F]){,4}|0?\g<1>{1,5})} + name + constant.character.escape.powershell + + + match + `u(?:\{[0-9a-fA-F]{,6}.)? + name + invalid.character.escape.powershell + + + doubleQuotedStringEscapes patterns match - `(?:[`0abnfrvt\s"\x{201C}-\x{201E}$]) + `(?:[`0abefnrtv"\x{201C}-\x{201E}$]) name constant.character.escape.powershell + + include + #unicodeEscape + match ` @@ -1336,10 +989,14 @@ match - `(?:[`0abnfrvt\s"\x{201C}-\x{201E}'\x{2018}-\x{201B}$]) + `(?:[`0abefnrtv"\x{201C}-\x{201E}'\x{2018}-\x{201B}$]) name constant.character.escape.powershell + + include + #unicodeEscape + match ` @@ -1368,7 +1025,7 @@ begin - (?<![\w-])(?:(global|local|script|private)(:))?(?:(?=[\p{L}:_\\/\[\]-]|`(?!\s))|(?<=:)(?=[`"\x{201C}-\x{201E}'\x{2018}-\x{201B}])) + (?<![\w-])(?:(global|local|script|private)(:))?(?:(?=[^`"\x{201C}-\x{201E}'\x{2018}-\x{201B}{\(|&<>@#\s]|`(?!\s))|(?<=:)(?=[`"\x{201C}-\x{201E}'\x{2018}-\x{201B}<>@#])) beginCaptures 1 @@ -1392,7 +1049,7 @@ begin \G end - (?=[(){}|;&\s]) + (?=[(){}|,;&\s]) applyEndPatternLast contentName @@ -1451,33 +1108,23 @@ include - #commentBlock + #notCode - include + comment #commentLine - match + comment (?<!})[^\s{}()]+ - - match - `\s - name - invalid.character.escape.powershell - - - include - #commentBlock - include - #commentLine + #notCode @@ -1507,6 +1154,27 @@ patterns + + begin + = + beginCaptures + + 0 + + name + keyword.operator.assignment.enum-member.powershell + + + end + (?<=,)|(?=[)\n]) + patterns + + + include + $self + + + match , @@ -1515,7 +1183,15 @@ include - $self + #variableNoProperty + + + include + #type + + + include + #notCode @@ -1706,18 +1382,35 @@ begin - (?:(?<!\w)|\G)([-+]?(?:[0-9]+(?i:(?![ed]|\.(?!\.))|(?:\.[0-9]*)?((?:(?i:e)[-+]?[0-9]+)?l))|(?:\.[0-9]+)\g<2>))((?i:[kmgtp]b)?)\b + (?:(?<!\w)|\G)([+\x{2013}-\x{2015}-]?(?:[0-9]+(?i:(?![ed]|\.(?!\.))|(?:\.[0-9]*)?((?:(?i:e)[+\x{2013}-\x{2015}-]?[0-9]+)?l))|(?:\.[0-9]+)\g<2>))((?i:[kmgtp]b)?)(?!\w) end - \G - - - beginCaptures - - 1 - - name - constant.numeric.hex.powershell - + (?!.\G) + applyEndPatternLast + + patterns + + + include + #operators + + + include + #commentBlock + + + include + #commentLine + + + + + beginCaptures + + 1 + + name + constant.numeric.hex.powershell + 2 name @@ -1725,9 +1418,26 @@ begin - (?:(?<!\w)|\G)([-+]?0(?i:x[0-9a-f_]+l?))((?i:[kmgtp]b)?)\b + (?:(?<!\w)|\G)([+\x{2013}-\x{2015}-]?0(?i:x[0-9a-f_]+l?))((?i:[kmgtp]b)?)(?!\w) end - \G + (?!.\G) + applyEndPatternLast + + patterns + + + include + #operators + + + include + #commentBlock + + + include + #commentLine + + beginCaptures @@ -1744,9 +1454,26 @@ begin - (?:(?<!\w)|\G)([-+]?(?:(?:[0-9]+)|(?=\.[0-9]))(?:\.[0-9]*)?(?i:(?:e[-+]?[0-9]+)?(?!l)d?))((?i:[kmgtp]b)?)\b + (?:(?<!\w)|\G)([+\x{2013}-\x{2015}-]?(?:(?:[0-9]+)|(?=\.[0-9]))(?:\.[0-9]*)?(?i:(?:e[+\x{2013}-\x{2015}-]?[0-9]+)?(?!l)d?))((?i:[kmgtp]b)?)(?!\w) end - \G + (?!.\G) + applyEndPatternLast + + patterns + + + include + #operators + + + include + #commentBlock + + + include + #commentLine + + captures @@ -1763,7 +1490,7 @@ comment - (?:(?<!\w)|\G)([-+]?0(?i:b[01_]+l?))((?i:[kmgtp]b)?)(?!\w) + (?:(?<!\w)|\G)([+\x{2013}-\x{2015}-]?0(?i:b[01_]+l?))((?i:[kmgtp]b)?)(?!\w) @@ -1874,6 +1601,10 @@ name storage.modifier.powershell + + include + #attribute + include #type_SubType @@ -2025,8 +1756,10 @@ patterns + comment: + [short], [ushort], [uint], [ulong] added PowerShell Core 6.2; match - (?<![\w-])(?i:type|void|switch|(?:ps(?:custom)?)?object|hashtable|string|single|float|double|decimal|s?byte|bool(?:ean)?|char|valuetype|datetime|array|u?int(?:32|16|64)|int|long)(?!\w) + (?<![\w-])(?i:type|void|switch|(?:ps(?:custom)?)?object|hashtable|string|single|float|double|decimal|s?byte|bool(?:ean)?|char|valuetype|datetime|array|u?int(?:32|16|64)|u?int|u?long|u?short)(?!\w) name keyword.type.powershell @@ -2072,7 +1805,7 @@ #commentBlock - match + include [^\s\W]+ @@ -2246,7 +1979,7 @@ #commentBlock - match + include [^\s\W]+ @@ -2263,6 +1996,12 @@ seperate the parts of the variable name and scope them patterns + + match + [$@][^:]*:$ + name + invalid.character.variable.powershell + captures @@ -2280,7 +2019,7 @@ comment These are special constants. match - ((\$)(?i:(:?(?:False|Null|True)))\b) + (([$@])(?i:(:?(?:False|Null|True)))\b) captures @@ -2299,7 +2038,7 @@ comment These are the other built-in constants. match - ((\$)(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)\b))) + (([$@])(?i:(:?(?:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)\b))) captures @@ -2316,7 +2055,7 @@ 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))) + (([$@])(?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))) captures @@ -2335,7 +2074,7 @@ comment Style preference variables as language variables so that they stand out. 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)\b))) + (([$@])(?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)\b))) captures @@ -2343,127 +2082,257 @@ 1 name - variable.other.readwrite.powershell + punctuation.definition.variable.powershell 2 - name - punctuation.definition.variable.powershell + patterns + + + include + #variable_scopeOrDrive + + - 3 + + match + (?:([$@])(?:(?>([\w][\w?]*:|:)?)([\w](?:[\w?]|(?<!:):(?!:))*|[$?^:]))) + name + variable.other.readwrite.powershell + + + + variable_scopeOrDrive + + patterns + + + match + ((?i:global|local|private|script|using|workflow))(`)?(:) + captures + + 1 name storage.modifier.scope.powershell - 4 + 2 name - punctuation.separator.colon.powershell + invalid.character.escape.powershell - 5 + 3 name - support.variable.drive.powershell + punctuation.separator.colon.powershell - match - ((?i:(\$)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))+))) + match + (?i:(alias|Cert|Env|Function|HKCU|HKLM|Variable|WSMan))(`)?(:) captures 1 name - variable.other.readwrite.powershell + keyword.type.drive:powershell 2 name - punctuation.definition.variable.powershell + invalid.character.escape.powershell 3 name - storage.modifier.scope.powershell + punctuation.separator.colon.powershell - 4 + + + + comment + Unknown drive + begin + (?=.) + end + : + endCaptures + + 0 name punctuation.separator.colon.powershell - 5 + + name + storage.type.drive.powershell + patterns + + match + `(?:[`0abefnrtv{}\n]) name - support.variable.drive.powershell + constant.character.escape.powershell - - comment - splatting cannot have members and certain characters following, including no line comment - match - ((?i:(\@)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[\p{L}_]\w*):|:))(?!:))?+((?:\p{L}|\d|[_?]|:(?!:))++)))(?![~`!@#$%^*<>\]\\/+-]) + + include + #unicodeEscape + + + + + variable_bracketed + + begin + (?=\$\{) + end + (?!.\G) + applyEndPatternLast + + patterns + - captures + begin + (\$)(\{) + beginCaptures 1 name - variable.other.readwrite.powershell + punctuation.definition.variable.powershell 2 name - punctuation.definition.variable.powershell + punctuation.definition.variable.braces.begin.powershell - 3 + + end + } + endCaptures + + 0 name - punctuation.definition.variable.braces.begin.powershell + punctuation.definition.variable.braces.end.powershell - 4 + + name + variable.other.readwrite.powershell + patterns + - name - storage.modifier.scope.powershell + comment + this captures up to the first colon, and then matches up the capture + match + \G(?:(?:[^`{}:]|`[`{}]?+)+:|:) + captures + + 0 + + patterns + + + include + #variable_scopeOrDrive + + + + - 5 + match + `(?:[`0abefnrtv{}\n]) name - punctuation.separator.colon.powershell + constant.character.escape.powershell + + + include + #unicodeEscape - 6 + match + ` name - support.variable.drive.powershell + invalid.character.escape.powershell - 8 + match + { name - punctuation.definition.variable.braces.end.powershell + invalid.character.powershell - - match - ((?i:(\$)(\{)(?:(?:(global|local|private|script|using|workflow)(:)|((?:[^`{}:]|`[`{}]?+)+:|:)))?+([^`{}]|`[`{}]?+)+(\}))) + + + + begin + (?<=})(?=\.(?!\.)|::|\[) + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + - variable + variableNoProperty_bracketed + begin + (?=\$\{) + end + (?!.\G) + applyEndPatternLast + patterns begin - (?=\$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\}))) + (\$)(\{) + beginCaptures + + 1 + + name + punctuation.definition.variable.powershell + + 2 + + name + punctuation.definition.variable.braces.begin.powershell + + end - (?!.\G) - applyEndPatternLast - + } + endCaptures + + 0 + + name + punctuation.definition.variable.braces.end.powershell + + + name + variable.other.readwrite.powershell patterns - begin - \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\}))(?=\.(?!\.)|::|\[) - beginCaptures + comment + this captures up to the first colon, and then matches up the capture + match + \G(?:(?:[^`{}:]|`[`{}]?+)+:|:) + captures 0 @@ -2471,30 +2340,86 @@ include - #variable_inner + #variable_scopeOrDrive - end - (?=[^\s\p{L}]|\n) - applyEndPatternLast - - patterns - - - include - #accessors - - - match - [^\s\W]+ - - + + + match + `(?:[`0abefnrtv{}\n]) + name + constant.character.escape.powershell + + + include + #unicodeEscape + + + match + ` + name + invalid.character.escape.powershell + + + match + { + name + invalid.character.powershell + + + + + + variable + + patterns + + + begin + (?=\$(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:]|\{)) + end + (?!.\G) + applyEndPatternLast + + patterns + + + begin + \$(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:])(?=\.(?!\.)|::|\[) + beginCaptures + + 0 + + patterns + + + include + #variable_inner + + + + + end + (?=[^\s\p{L}]|\n) + applyEndPatternLast + + patterns + + + include + #accessors + + + match + [^\s\W]+ + + begin - \$(?:(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?+)+:|:))?+(?:[^`{}]|`[`{}]?+)+(\})) + \$(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:]) end (?!.\G) applyEndPatternLast @@ -2513,11 +2438,50 @@ + + include + #variable_bracketed + + comment + splatting cannot have members and certain characters following, including no line comment match - @(?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))++(?![~`!@#$%^*<>\]\\/"\x{201C}-\x{201E}'\x{2018}-\x{201B}+-]) + (?>@(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:]))(?![~`!@#$%^*<>\]\\/"\x{201C}-\x{201E}'\x{2018}-\x{201B}+-]) + captures + + 0 + + patterns + + + include + #variable_inner + + + + + + + + variableNoProperty + + begin + (?=\$(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:]|\{)) + end + (?!.\G) + applyEndPatternLast + + patterns + + + begin + \$(?:(?>[\w][\w?]*:|:)?(?:[\w](?:[\w?]|:(?!:))*|:(?!:))|[$?^:]) + end + (?!.\G) + applyEndPatternLast + captures 0 @@ -2532,7 +2496,13 @@ + + include + #variableNoProperty_bracketed + + name + meta.embedded.interpolated.powershell UsingDirective @@ -2593,26 +2563,6 @@ - variableNoProperty - - match - (\$)((?:(?:(?:[\p{L}_]\w*):|:)(?!:))?+(?:\p{L}|\d|[_?]|:(?!:))+|\{(?:(?:(?:[^`{}:]|`[`{}]?)+:|:))?+([^`{}]|`[`{}]?)+(\})) - captures - - 0 - - patterns - - - include - #variable_inner - - - - - name - meta.embedded.interpolated.powershell - hashtable begin @@ -2834,7 +2784,83 @@ match - `\s + `(?!\n)\s + name + constant.character.escape.powershell + + + include + #argumentModeEscapes + + + begin + ['\x{2018}-\x{201B}] + end + ['\x{2018}-\x{201B}] + applyEndPatternLast + + patterns + + + match + ['\x{2018}-\x{201B}]{2} + name + constant.character.escape.powershell + + + + + begin + ["\x{201C}-\x{201E}] + end + ["\x{201C}-\x{201E}] + applyEndPatternLast + + patterns + + + include + #doubleQuotedStringEscapes + + + begin + \$\( + end + \) + patterns + + + include + #unquotedStrings_text + + + + + + + begin + \$\( + end + \) + patterns + + + include + #unquotedStrings_text + + + + + + unquotedStrings_text_interpolatedString + + comment + !!!!!!!!!!!!!!!!!!WIP!!! + patterns + + + match + `(?!\n)\s name constant.character.escape.powershell @@ -2902,6 +2928,364 @@ + operators + + patterns + + + begin + (?:(?<!\w)|\G)[\x{2013}-\x{2015}-](?i:is(?:not)?|as)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.comparison.type.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-](?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.comparison.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-](?i:join|split)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.unary.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-](?i:and|or|not|xor)(?!\p{L})|! + beginCaptures + + 0 + + name + keyword.operator.logical.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-](?i:band|bor|bnot|bxor|shl|shr)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.bitwise.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + begin + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-](?i:f)(?!\p{L}) + beginCaptures + + 0 + + name + keyword.operator.string-format.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + match + \+\+|[\x{2013}-\x{2015}-]{2} + name + keyword.operator.unary.powershell + + + match + (?:(?<!\w|!)|\G)[\x{2013}-\x{2015}-]\p{L}\w* + name + entity.name.parameter.powershell + + + begin + [+%*/\x{2013}-\x{2015}-]=?|= + beginCaptures + + 0 + + name + keyword.operator.assignment.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + comment + || and && conditional terminators are reserved + match + \|\||&&|; + name + punctuation.terminator.statement.powershell + + + comment + + match + [,|] + name + punctuation.separator.powershell + + + comment + (dot) source operator, requires trailing space + begin + &|\.(?=\*?[\s,;&|{}\(\)]|$\[p{L}:?_{]) + beginCaptures + + 0 + + name + keyword.operator.other.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + comment + the range operator is only available after an operand (binary operator) + begin + (?<!^)\s*(\.\.) + beginCaptures + + 1 + + name + keyword.operator.range.powershell + + + end + (?!\s) + applyEndPatternLast + + patterns + + + include + #numericConstant + + + include + #commentBlock + + + include + #commentLine + + + + + + notCode + + patterns + + + match + `(?!\n)\s + name + invalid.character.escape.powershell + + + include + #commentBlock + + + include + #commentLine + + + comment + when nothing else matches in usual tokenizing, consume it to prevent other patterns from striking in the middle of what might be a command name. + begin + (?=[^\s\[(){}|,;&]) + alternateBegin + (?=[^\x{2018}-\x{201B}"\x{201C}-\x{201E}\s\[(){}|,;&$@])|(?<=\S)(?=[$@<>]) + end + (?=[(){}|,;&\s]) + applyEndPatternLast + + contentName + unquoted.text.powershell + patterns + + + include + #unquotedStrings_text + + + + + scopeName source.powershell