From c9b31233563038929667791711dc6fcf2ad3409f Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:07 -0500 Subject: [PATCH 01/23] Direct migration to .sublime-syntax --- Support/PowershellSyntax.sublime-syntax | 445 +++++++ Support/PowershellSyntax.tmLanguage | 1548 ----------------------- 2 files changed, 445 insertions(+), 1548 deletions(-) create mode 100644 Support/PowershellSyntax.sublime-syntax delete mode 100644 Support/PowershellSyntax.tmLanguage diff --git a/Support/PowershellSyntax.sublime-syntax b/Support/PowershellSyntax.sublime-syntax new file mode 100644 index 0000000..0927d63 --- /dev/null +++ b/Support/PowershellSyntax.sublime-syntax @@ -0,0 +1,445 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: PowerShell +file_extensions: + - ps1 + - psm1 + - psd1 +scope: source.powershell +contexts: + main: + - match: "<#" + captures: + 0: punctuation.definition.comment.block.begin.powershell + push: + - meta_scope: comment.block.powershell + - match: "#>" + captures: + 0: punctuation.definition.comment.block.end.powershell + pop: true + - include: commentEmbeddedDocs + - match: '[2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>>' + scope: keyword.operator.redirection.powershell + - include: commands + - include: commentLine + - include: variable + - include: interpolatedStringContent + - include: function + - include: attribute + - include: UsingDirective + - include: type + - include: hashtable + - include: doubleQuotedString + - include: scriptblock + - include: doubleQuotedStringEscapes + - match: (? - - - - fileTypes - - ps1 - psm1 - psd1 - - name - PowerShell - 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 - - - - - match - [2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>> - name - keyword.operator.redirection.powershell - - - include - #commands - - - include - #commentLine - - - include - #variable - - - include - #interpolatedStringContent - - - include - #function - - - include - #attribute - - - include - #UsingDirective - - - include - #type - - - include - #hashtable - - - include - #doubleQuotedString - - - include - #scriptblock - - - comment - Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) - include - #doubleQuotedStringEscapes - - - begin - (?<!')' - end - '(?!') - name - string.quoted.single.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - begin - \@"(?=$) - end - ^"@ - name - string.quoted.double.heredoc.powershell - patterns - - - include - #variableNoProperty - - - include - #doubleQuotedStringEscapes - - - include - #interpolation - - - - - begin - \@'(?=$) - end - ^'@ - name - string.quoted.single.heredoc.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - include - #numericConstant - - - 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 - meta.group.array-expression.powershell - patterns - - - include - $self - - - - - begin - (\$)(\() - beginCaptures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - comment - TODO: move to repo; make recursive. - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - name - meta.group.complex.subexpression.powershell - patterns - - - include - $self - - - - - match - (\b(([A-Za-z0-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|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w) - name - keyword.control.powershell - - - match - (?<!\w)(--%)(?!\w) - name - keyword.control.powershell - - - 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)(?!\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 - keyword.other.statement-separator.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 - - name - punctuation.definition.comment.powershell - - - end - $ - name - comment.line.powershell - patterns - - - include - #commentEmbeddedDocs - - - include - #RequiresDirective - - - - attribute - - begin - (\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength)\b - beginCaptures - - 1 - - name - punctuation.section.bracket.begin.powershell - - 2 - - name - support.function.attribute.powershell - - - end - (\]) - endCaptures - - 1 - - 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 - - - include - #variable - - - include - #variableNoProperty - - - include - #hashtable - - - include - #scriptblock - - - include - #doubleQuotedStringEscapes - - - include - #doubleQuotedString - - - include - #type - - - include - #numericConstant - - - include - #doubleQuotedString - - - include - $self - - - match - (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=) - captures - - 1 - - name - variable.parameter.attribute.powershell - - 2 - - name - keyword.operator.assignment.powershell - - - - - begin - (?<!')' - end - '(?!') - name - string.quoted.single.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - - - - commands - - patterns - - - 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 - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:foreach-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:where-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:sort-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:tee-object)(?!\w) - name - support.function.powershell - - - - commentEmbeddedDocs - - patterns - - - captures - - 1 - - name - constant.string.documentation.powershell - - 2 - - name - keyword.operator.documentation.powershell - - - match - (?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS)) - name - comment.documentation.embedded.powershell - - - captures - - 1 - - name - constant.string.documentation.powershell - - 2 - - name - keyword.operator.documentation.powershell - - 3 - - name - keyword.operator.documentation.powershell - - - match - (?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) - name - comment.documentation.embedded.powershell - - - - doubleQuotedStringEscapes - - patterns - - - match - `[0abnfrvt"'$`] - name - constant.character.escape.powershell - - - match - "" - name - constant.character.escape.powershell - - - - function - - begin - ^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) - beginCaptures - - 0 - - name - meta.function.powershell - - 1 - - name - storage.type.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - entity.name.function.powershell - - - end - (?=\{|\() - patterns - - - include - #commentLine - - - - interpolatedStringContent - - begin - \( - beginCaptures - - 0 - - name - punctuation.section.group.begin.powershell - - - contentName - interpolated.simple.source.powershell - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - patterns - - - include - $self - - - include - #interpolation - - - include - #interpolatedStringContent - - - - interpolation - - begin - (\$)(\() - beginCaptures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - contentName - interpolated.complex.source.powershell - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - patterns - - - include - $self - - - include - #interpolation - - - include - #interpolatedStringContent - - - - numericConstant - - 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 - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - - scriptblock - - begin - \{ - beginCaptures - - 0 - - name - punctuation.section.braces.begin.powershell - - - end - \} - endCaptures - - 0 - - name - punctuation.section.braces.end.powershell - - - name - meta.scriptblock.powershell - patterns - - - include - $self - - - - type - - begin - \[ - beginCaptures - - 0 - - name - punctuation.section.bracket.begin.powershell - - - end - \] - endCaptures - - 0 - - name - punctuation.section.bracket.end.powershell - - - patterns - - - match - (?!\d+|\.)(?:\p{L}|\p{N}|\.)+ - name - storage.type.powershell - - - include - $self - - - - variable - - patterns - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - constant.language.powershell - - - comment - These are special constants. - match - (\$)(?i:(False|Null|True))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.variable.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - These are the other built-in constants. - match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.automatic.powershell - - 3 - - name - entity.name.function.invocation.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 - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - variable.language.powershell - - 3 - - name - entity.name.function.invocation.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 - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - 3 - - name - storage.modifier.scope.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end.powershell - - 6 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.drive.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - 3 - - name - support.variable.drive.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end.powershell - - 6 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - - UsingDirective - - match - (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+)) - captures - - 1 - - name - keyword.control.using.powershell - - 2 - - name - keyword.other.powershell - - 3 - - name - variable.parameter.powershell - - - - RequiresDirective - - begin - (?<=#)(?i:(requires))\s - beginCaptures - - 0 - - name - keyword.control.requires.powershell - - - end - $ - name - meta.requires.powershell - patterns - - - match - \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) - name - keyword.other.powershell - - - match - (?<!-)\b\p{L}+|\d+(?:\.\d+)* - name - variable.parameter.powershell - - - include - #hashtable - - - - variableNoProperty - - patterns - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - constant.language.powershell - - - comment - These are special constants. - match - (\$)(?i:(False|Null|True))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.variable.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - These are the other built-in constants. - match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.automatic.powershell - - 3 - - name - entity.name.function.invocation.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 - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - variable.language.powershell - - 3 - - name - entity.name.function.invocation.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 - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+)) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - keyword.other.powershell - - 5 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.drive.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+)) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin - - 3 - - name - support.variable.drive.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end - - - match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) - - - - hashtable - - begin - (@)(\{) - beginCaptures - - 1 - - name - keyword.other.hashtable.begin.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - - end - (\}) - endCaptures - - 1 - - name - punctuation.section.braces.end.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+)? - name - meta.hashtable.assignment.powershell - - - include - #scriptblock - - - include - $self - - - - doubleQuotedString - - begin - (?<!(?<!`)")" - end - "(?!") - name - string.quoted.double.powershell - patterns - - - match - (?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b - - - include - #variableNoProperty - - - include - #variable - - - include - #doubleQuotedStringEscapes - - - include - #interpolation - - - match - `\s*$ - name - keyword.other.powershell - - - - - scopeName - source.powershell - uuid - f8f5ffb0-503e-11df-9879-0800200c9a66 - - From b701521aef72fdb5b906e4ae3e731e76324fa362 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:23 -0500 Subject: [PATCH 02/23] Start rearranging and changing scopes --- Support/PowershellSyntax.sublime-syntax | 411 ++++++++++++------------ 1 file changed, 214 insertions(+), 197 deletions(-) diff --git a/Support/PowershellSyntax.sublime-syntax b/Support/PowershellSyntax.sublime-syntax index 0927d63..54ed60d 100644 --- a/Support/PowershellSyntax.sublime-syntax +++ b/Support/PowershellSyntax.sublime-syntax @@ -2,60 +2,31 @@ --- # http://www.sublimetext.com/docs/3/syntax.html name: PowerShell +scope: source.powershell + file_extensions: - ps1 - psm1 - psd1 -scope: source.powershell + contexts: + main: - - match: "<#" - captures: - 0: punctuation.definition.comment.block.begin.powershell - push: - - meta_scope: comment.block.powershell - - match: "#>" - captures: - 0: punctuation.definition.comment.block.end.powershell - pop: true - - include: commentEmbeddedDocs + - include: comments - match: '[2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>>' scope: keyword.operator.redirection.powershell - include: commands - - include: commentLine - include: variable - - include: interpolatedStringContent + - include: interpolated-string-content - include: function - include: attribute - - include: UsingDirective + - include: using-directive - include: type - include: hashtable - - include: doubleQuotedString - - include: scriptblock - - include: doubleQuotedStringEscapes - - match: (?' + captures: + 0: punctuation.definition.comment.block.end.powershell + pop: true + - include: comment-embedded-docs + + comment-embedded-docs: - match: (?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS)) scope: comment.documentation.embedded.powershell captures: 1: constant.string.documentation.powershell 2: keyword.operator.documentation.powershell - - match: '(?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+))' + - match: (?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) scope: comment.documentation.embedded.powershell captures: 1: constant.string.documentation.powershell 2: keyword.operator.documentation.powershell 3: keyword.operator.documentation.powershell - commentLine: - - match: '(? Date: Sat, 1 Feb 2020 16:15:25 -0500 Subject: [PATCH 03/23] Adapted tests from PowerShell/EditorSyntax --- ...ublime-syntax => PowerShell.sublime-syntax | 89 +- ...e-settings => PowerShell.sublime-settings} | 6 +- .../Symbol List Classes.tmPreferences | 2 +- Tests/syntax_test_Class.ps1 | 125 ++ Tests/syntax_test_PowerShell.ps1 | 1310 +++++++++++++++++ Tests/syntax_text_Function.ps1 | 373 +++++ 6 files changed, 1866 insertions(+), 39 deletions(-) rename Support/PowershellSyntax.sublime-syntax => PowerShell.sublime-syntax (85%) rename Support/{PowershellSyntax.sublime-settings => PowerShell.sublime-settings} (95%) rename Symbol List Functions.tmPreferences => Support/Symbol List Classes.tmPreferences (88%) create mode 100644 Tests/syntax_test_Class.ps1 create mode 100644 Tests/syntax_test_PowerShell.ps1 create mode 100644 Tests/syntax_text_Function.ps1 diff --git a/Support/PowershellSyntax.sublime-syntax b/PowerShell.sublime-syntax similarity index 85% rename from Support/PowershellSyntax.sublime-syntax rename to PowerShell.sublime-syntax index 54ed60d..a6c13f5 100644 --- a/Support/PowershellSyntax.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -9,12 +9,14 @@ file_extensions: - psm1 - psd1 +variables: + bytes_unit: (?i:[kmgtp]b) + contexts: main: - include: comments - - match: '[2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>>' - scope: keyword.operator.redirection.powershell + - include: redirection - include: commands - include: variable - include: interpolated-string-content @@ -60,19 +62,23 @@ contexts: - match: (?&)(1)|([1-6])(>)|([1-6])(>>) + captures: + 1: constant.numeric.decimal.file-descriptor.powershell + 2: keyword.operator.redirection.powershell + 3: constant.numeric.decimal.file-descriptor.powershell + 4: constant.numeric.decimal.file-descriptor.powershell + 5: keyword.operator.redirection.powershell + 6: constant.numeric.decimal.file-descriptor.powershell + 7: keyword.operator.redirection.powershell + - match: '>>?|<\|' + scope: keyword.operator.redirection.powershell + requires-directive: - match: (?<=#)(?i:requires)\s scope: keyword.control.requires.powershell @@ -131,12 +150,10 @@ contexts: scope: punctuation.section.bracket.end.powershell pop: true - match: \( - captures: - 0: punctuation.section.group.begin.powershell + scope: punctuation.section.group.begin.powershell push: - match: \) - captures: - 0: punctuation.section.group.end.powershell + scope: punctuation.section.group.end.powershell pop: true - include: variable - include: variable-no-property @@ -171,13 +188,11 @@ contexts: comment-block: - match: <# - captures: - 0: punctuation.definition.comment.block.begin.powershell + scope: punctuation.definition.comment.block.begin.powershell push: - meta_scope: comment.block.powershell - match: '#>' - captures: - 0: punctuation.definition.comment.block.end.powershell + scope: punctuation.definition.comment.block.end.powershell pop: true - include: comment-embedded-docs @@ -211,17 +226,21 @@ contexts: - include: double-quoted-string - include: single-quoted-string - match: \@"(?=$) + scope: punctuation.definition.string.begin.powershell push: - meta_scope: string.quoted.double.heredoc.powershell - match: ^"@ + scope: punctuation.definition.string.end.powershell pop: true - include: variable-no-property - include: double-quoted-string-escapes - include: interpolation - match: \@'(?=$) + scope: punctuation.definition.string.begin.powershell push: - meta_scope: string.quoted.single.heredoc.powershell - match: ^'@ + scope: punctuation.definition.string.end.powershell pop: true - match: "''" scope: constant.character.escape.powershell @@ -306,7 +325,7 @@ contexts: interpolation: - match: (\$)(\() captures: - 1: keyword.other.variable.definition.powershell + 1: punctuation.definition.variable.powershell 2: punctuation.section.group.begin.powershell push: - meta_content_scope: interpolated.complex.source.powershell @@ -318,31 +337,31 @@ contexts: - include: interpolated-string-content numeric-constant: - - match: ((?:[-+]|\b)0(?i:x)[0-9a-fA-F_]+(?i:u|l|ul|lu)?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)0(?i:x)[0-9a-fA-F_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b captures: - 1: constant.numeric.hex.powershell + 1: constant.numeric.integer.hexadecimal.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)(?:[0-9_]+)?\.[0-9_]+(?:(?i:e)[0-9]+)?(?i:[fdm])?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)(?:[0-9_]+)?\.[0-9_]+(?:(?i:e)[0-9]+)?(?i:[fdm])?)({{bytes_unit}}?)\b captures: 1: constant.numeric.integer.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)0(?:b|B)[01_]+(?i:u|l|ul|lu)?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)0(?:b|B)[01_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b captures: - 1: constant.numeric.octal.powershell + 1: constant.numeric.integer.binary.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+(?:e|E)(?:[0-9_])?+(?i:[fdm])?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)[0-9_]+(?i:e)(?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b captures: 1: constant.numeric.integer.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+\.(?:e|E)(?:[0-9_])?+(?i:[fdm])?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)[0-9_]+\.(?i:e)(?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b captures: 1: constant.numeric.integer.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:[fdm]))((?i:[kmgtp]b)?)\b' + - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:[fdm]))({{bytes_unit}}?)\b captures: 1: constant.numeric.integer.powershell 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:u|l|ul|lu)?)((?i:[kmgtp]b)?)\b + - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b captures: 1: constant.numeric.integer.powershell 2: keyword.other.powershell @@ -377,24 +396,24 @@ contexts: captures: 1: support.constant.variable.powershell 2: punctuation.definition.variable.powershell - 3: entity.name.function.invocation.powershell + 3: variable.other.member.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))((?:\.(?:\p{L}|\d|_)+)*\b)?\b captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell - 3: entity.name.function.invocation.powershell - - 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 + 3: variable.other.member.powershell + - 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 comment: Style preference variables as language variables so that they stand out. captures: 1: punctuation.definition.variable.powershell 2: variable.language.powershell - 3: entity.name.function.invocation.powershell + 3: variable.other.member.powershell - match: (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? captures: 1: punctuation.definition.variable.powershell 2: storage.modifier.scope.powershell 3: variable.other.readwrite.powershell - 4: entity.name.function.invocation.powershell + 4: variable.other.member.powershell - match: (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? captures: 1: punctuation.definition.variable.powershell @@ -402,13 +421,13 @@ contexts: 3: storage.modifier.scope.powershell 4: variable.other.readwrite.powershell 5: punctuation.section.braces.end.powershell - 6: entity.name.function.invocation.powershell + 6: variable.other.member.powershell - match: (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? captures: 1: punctuation.definition.variable.powershell 2: support.variable.drive.powershell 3: variable.other.readwrite.powershell - 4: entity.name.function.invocation.powershell + 4: variable.other.member.powershell - match: (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? captures: 1: punctuation.definition.variable.powershell @@ -416,13 +435,13 @@ contexts: 3: support.variable.drive.powershell 4: variable.other.readwrite.powershell 5: punctuation.section.braces.end.powershell - 6: entity.name.function.invocation.powershell + 6: variable.other.member.powershell variable-no-property: - match: (\$)(?i:False|Null|True)\b scope: constant.language.powershell captures: - 1: keyword.other.variable.definition.powershell + 1: punctuation.definition.variable.powershell - match: (\$)(?i:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID)\b scope: support.constant.variable.powershell captures: @@ -448,11 +467,11 @@ contexts: 3: variable.other.readwrite.powershell 4: keyword.other.powershell 5: entity.name.function.invocation.powershell - - match: (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+)) + - match: (?i:(\$)((?:\p{L}|\d|_)+:)?(?:\p{L}|\d|_)+) + scope: variable.other.readwrite.powershell captures: 1: punctuation.definition.variable.powershell 2: support.variable.drive.powershell - 3: variable.other.readwrite.powershell - match: (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) captures: 1: punctuation.definition.variable.powershell diff --git a/Support/PowershellSyntax.sublime-settings b/Support/PowerShell.sublime-settings similarity index 95% rename from Support/PowershellSyntax.sublime-settings rename to Support/PowerShell.sublime-settings index f7b4ee9..f0ce3a5 100644 --- a/Support/PowershellSyntax.sublime-settings +++ b/Support/PowerShell.sublime-settings @@ -1,4 +1,4 @@ -{ - "word_wrap": false, - "translate_tabs_to_spaces": true +{ + "word_wrap": false, + "translate_tabs_to_spaces": true } \ No newline at end of file diff --git a/Symbol List Functions.tmPreferences b/Support/Symbol List Classes.tmPreferences similarity index 88% rename from Symbol List Functions.tmPreferences rename to Support/Symbol List Classes.tmPreferences index b13ff01..5999bfd 100644 --- a/Symbol List Functions.tmPreferences +++ b/Support/Symbol List Classes.tmPreferences @@ -5,7 +5,7 @@ name Symbol List: Functions scope - source.powershell meta.function + source.powershell entity.name.class settings showInSymbolList diff --git a/Tests/syntax_test_Class.ps1 b/Tests/syntax_test_Class.ps1 new file mode 100644 index 0000000..74df9f1 --- /dev/null +++ b/Tests/syntax_test_Class.ps1 @@ -0,0 +1,125 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" +using namespace system.management.automation +# <- keyword.control.using +# ^^^^^^^^^ keyword.other +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter + +# Define a class +class TypeName +# <- storage.type +# ^ entity.name.class +{ + # Property with validate set + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [ValidateSet("val1", "Val2")] + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [string] $P1 + # <- punctuation.section.bracket.begin + # ^^^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^^ variable.other.readwrite + + # Static property + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^^^ comment.line + static [hashtable] $P2 + #^^^^^ storage.modifier + # ^ punctuation.section.bracket.begin + # ^^^^^^^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^^ variable.other.readwrite + + # Hidden property does not show as result of Get-Member + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line + hidden [int] $P3 + #^^^^^ storage.modifier + # ^ punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^^ variable.other.readwrite + + # Constructor + # <- punctuation.definition.comment + # ^^^^^^^^^^^ comment.line + TypeName ([string] $s) { + # ^ punctuation.section.group.begin + # ^ punctuation.section.bracket.begin + # ^^^^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.section.group.end + $this.P1 = $s + # <- punctuation.definition.variable + # ^ variable.language + # ^^ variable.other.member + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + } + + # Static method + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^ comment.line + static [void] MemberMethod1([hashtable] $h) { + # <- storage.modifier + # ^ punctuation.section.bracket.begin + # ^^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.section.group.begin + # ^ punctuation.section.bracket.begin + # ^^^^^^^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.section.group.end + [TypeName]::P2 = $h + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + } + + # Instance method + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^^^ comment.line + [int] MemberMethod2([int] $i) { + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.section.group.begin + # ^ punctuation.section.bracket.begin + # ^^^ storage.type + # ^ punctuation.section.bracket.end + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.section.group.end + $this.P3 = $i + # <- punctuation.definition.variable + # ^^^ variable.language + # ^^ variable.other.member + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + return $this.P3 + # <- keyword.control + # ^ punctuation.definition.variable + # ^^^^ variable.language + # ^^ variable.other.member + } +} diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 new file mode 100644 index 0000000..ef9dfd9 --- /dev/null +++ b/Tests/syntax_test_PowerShell.ps1 @@ -0,0 +1,1310 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" +using namespace System.Management.Automation +# <- keyword.control.using +# ^ keyword.other +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter +#Requires -PSSnapin DiskSnapin -Version 1.2 +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +# ^^^^^^^^ meta.requires keyword.other +# ^^^ meta.requires variable.parameter +#Requires -PSSnapin DiskSnapin +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +#Requires -Version 3 +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^ meta.requires variable.parameter +#Requires -Version 3.0 +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^ meta.requires variable.parameter +#Requires -Version 3 -RunAsAdministrator +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^ meta.requires variable.parameter +# ^^^^^^^^^^^^^^^^^^^ meta.requires keyword.other +#Requires -RunAsAdministrator +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^^^^^^^^^^^^ meta.requires keyword.other +#Requires -Modules PSWorkflow +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +#Requires -Modules PSWorkflow -ThisIsInvalid +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +# ^^^^^^^^^^^^^^ meta.requires +#Requires -Modules PSWorkflow, ActiveDirectory +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +# ^^^^^^^^^^^^^^^ meta.requires variable.parameter +#Requires -Modules PSWorkflow,ActiveDirectory +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +# ^^^^^^^^^^^^^^^ meta.requires variable.parameter +#Requires -ShellId MyLocalShell +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^^^ meta.requires variable.parameter +#Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"} +# <- punctuation.definition.comment +# ^ meta.requires keyword.control.requires +# ^^^^^^^^ meta.requires keyword.other +# ^^^^^^^^^^ meta.requires variable.parameter +# ^^^^^^^^^^ meta.requires meta.hashtable variable.other.readwrite +# ^ meta.requires meta.hashtable +# ^^^^^^^^^^^^^^^^ meta.requires meta.hashtable string.quoted.double +# ^ meta.requires meta.hashtable punctuation.terminator.statement +# ^^^^^^^^^^^^^ meta.requires meta.hashtable variable.other.readwrite +# ^ meta.requires meta.hashtable +# ^^^^^^^^^ meta.requires meta.hashtable string.quoted.double + +throw "Do not run this file!" +# <- keyword.control +# ^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double + +# Stop parsing +& tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment +# <- keyword.operator.other +# ^^^^^^^^ support.function +# ^ ^ keyword.operator.assignment +# ^^^ keyword.control +# ^^ ^^ ^^ ^^ ^ ^ string.unquoted + +# Automatic variables +$_, $$, $^, $? +# <- punctuation.definition.variable +#^ variable.language +# ^ punctuation.definition.variable +# ^^ variable.language +# ^ punctuation.definition.variable +# ^^ variable.language +# ^ punctuation.definition.variable +# ^^ variable.language +$args +# <- punctuation.definition.variable +#^^^^ support.variable.automatic +$error +# <- punctuation.definition.variable +# ^^^^ support.constant.variable +$home +# <- punctuation.definition.variable +# ^^^ support.constant.variable +$foreach +# <- punctuation.definition.variable +#^^^^^^^ support.variable.automatic + +# Normal variables +$variable +# <- punctuation.definition.variable +# ^ variable.other.readwrite +$script:variable +# <- punctuation.definition.variable variable.other.readwrite +# ^ storage.modifier.scope +# ^ variable.other.readwrite +$ENV:ComputerName +# <- punctuation.definition.variable variable.other.readwrite +# ^ support.variable.drive +# ^ variable.other.readwrite +${variable} +# <- punctuation.definition.variable variable.other.readwrite + # <- punctuation.section.braces.begin +# ^^^^^^^^ variable.other.readwrite +# ^ punctuation.section.braces.end +${script:variable} +# <- punctuation.definition.variable variable.other.readwrite + # <- punctuation.section.braces.begin +# ^ storage.modifier.scope +# ^ variable.other.readwrite +# ^ punctuation.section.braces.end + +# Variable properties should be highlighted +$variable.Name +# <- variable.other.readwrite punctuation.definition.variable +#^^^^^^^^ variable.other.readwrite +# ^^^^^ - variable.other.readwrite +# ^^^^ variable.other.member + +# In double-quoted strings, only the variable should be highlighted, not the property +"This is my $variable.Name!" +# <- punctuation.definition.string.begin +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.definition.variable +# ^^^^^^^^ variable.other.readwrite +# ^ punctuation.definition.string.end + +# When used in a subexpression, both should be highlighted +"This is my $($variable.Name)!" +# <- punctuation.definition.string.begin +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.definition.variable +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end +# ^^^^^^^^ variable.other.readwrite +# ^^^^ variable.other.member +# ^ punctuation.definition.string.end + +# $ENV:ComputerName should be highlighted +"This is the name of my computer: $ENV:ComputerName" +# <- punctuation.definition.string.begin +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.definition.variable +# ^^^^ support.variable.drive +# ^^^^^^^^^^^^ variable.other.readwrite +# ^ punctuation.definition.string.end + +# Here as well +"This is the name of my computer: ${ENV:ComputerName}" +# <- punctuation.definition.string.begin +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.definition.variable +# ^ punctuation.section.braces.begin +# ^^^^ support.variable.drive +# ^^^^^^^^^^^^ variable.other.readwrite +# ^ punctuation.definition.string.end + +# @splat references only work in argument mode, should not highlight in strings +"This is a @double quoted string." +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ - punctuation.definition.variable +# ^^^^^^ - variable.other.readwrite + +# double check scopes for automatic variables in strings +"$_ $$ $Pwd" +#^^ variable.language +# ^^ variable.language +# ^^^^ variable.language + +# Single quotes string +'This is a string' +# <- punctuation.definition.string.begin +#^^^^^^^^^^^^^^^^^ string.quoted.single +# ^ punctuation.definition.string.end + +# Hashtable +$properties = @{ +# <- punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ keyword.other.hashtable.begin +# ^ punctuation.section.braces.begin + Name = 'Name' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^ meta.hashtable string.quoted.single + Something = $else + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # Atom-grammar-test is not tokenizing this correctly... Need to test in Atom - TODO + Number = 16 + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^ meta.hashtable constant.numeric.integer + from = 'hello world' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^^^^^^^^^^^^ meta.hashtable string.quoted.single + hash = @{ + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^ keyword.other.hashtable.begin + # ^ punctuation.section.braces.begin + hello = 'world' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^^^^^^ meta.hashtable string.quoted.single + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# Spatting + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + +# ScriptBlock + {Invoke-Something @properties} +# ^ punctuation.section.braces.begin +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.braces.end +{ +# <- punctuation.section.braces.begin + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +} +# <- punctuation.section.braces.end +$sb = { +# <- punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ punctuation.section.braces.begin + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +} +# <- punctuation.section.braces.end + +# Arrays +$a1 = @(1,2,3,4) +# <- variable.other.readwrite punctuation.definition.variable +#^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end +# ^^^^^^^ meta.group.array-expression +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +$a2 = ('one','two','three','four') +# <- variable.other.readwrite punctuation.definition.variable +#^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ punctuation.section.group.begin +# ^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^^ string.quoted.single +# ^ punctuation.section.group.end +$a3 = $one, $two, $three, $four +# <- variable.other.readwrite punctuation.definition.variable +# ^ ^ ^ ^ punctuation.definition.variable +# ^ ^ ^ ^ ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ ^ ^ keyword.operator.other +$a1[0] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.bracket.begin +# ^ constant.numeric.integer +# ^ punctuation.section.bracket.end +$a2[-1] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.bracket.begin +# ^^ constant.numeric.integer +# ^ punctuation.section.bracket.end +$a3[1..2] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.bracket.begin +# ^ ^ constant.numeric.integer +# ^^ keyword.operator.range +# ^ punctuation.section.bracket.end + @(@($a)) +# ^ ^ keyword.other.array.begin +# ^ ^ punctuation.section.group.begin +# ^ punctuation.definition.variable variable.other.readwrite +# ^ variable.other.readwrite +# ^^ punctuation.section.group.end + @(($i = 10); (++$j)) +# ^ keyword.other.array.begin +# ^^ ^ punctuation.section.group.begin +# ^ ^ punctuation.definition.variable variable.other.readwrite +# ^ ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ punctuation.terminator.statement +# ^^ keyword.operator.assignment +# ^ ^^ punctuation.section.group.end + @($i = 10) +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable variable.other.readwrite +# ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ punctuation.section.group.end + $i[($y - 1) + $x] +# ^ ^ ^ punctuation.definition.variable variable.other.readwrite +# ^ ^ ^ variable.other.readwrite +# ^ punctuation.section.bracket.begin +# ^ punctuation.section.group.begin +# ^ ^ keyword.operator.assignment +# ^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ punctuation.section.bracket.end + +# Single quoted strings + 'This is a single quoted string.' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + '$This is a single ''quoted'' string.' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +# ^^ constant.character.escape +# ^^ constant.character.escape + 'This is a + single quoted string.' +# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + 'This #also' +# ^^^^^^^^^^^^ string.quoted.single + '$(Invoke-Something)' +# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + 'This "string" is nice.' +# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single + +# Double quoted strings + "This is a double quoted string." +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double + "$This is a double ""quoted"" string." +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^ variable.language +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^^^ support.variable.automatic + "This is a + double quoted string." +# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double + "This #also" +# ^^^^^^^^^^^^ string.quoted.double + "$(Invoke-Something)" +# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.definition.variable +# ^ punctuation.section.group.begin +# ^ interpolated.complex.source support.function +# ^ punctuation.section.group.end + "This 'string' is nice." +# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double + +# Double quoted here-string +@" +# <- string.quoted.double.heredoc + # <- string.quoted.double.heredoc +$This is a 'double quoted' +# <- punctuation.definition.variable +#^^^^ variable.language +Isn't it "nice"?? +There is no @platting here! +# ^ - punctuation.definition.variable +# ^ - variable.other.readwrite +"@ +# <- string.quoted.double.heredoc + # <- string.quoted.double.heredoc + +# Numeric constants + -3 +# ^^ constant.numeric.integer + .5 +# ^^ constant.numeric.integer + +.5 +# ^^^ constant.numeric.integer + 1. +# ^ constant.numeric.integer +# ^ - constant + 1.d +# ^^^ constant.numeric.integer + 1.lGB +# ^^^ constant.numeric.integer +# ^^ keyword.other + 1.e+12d +# ^^^ constant.numeric.integer +# ^ keyword.operator +# ^^^ constant.numeric.integer + 1e+12d +# ^^ constant.numeric.integer +# ^ keyword.operator +# ^^^ constant.numeric.integer + 1.5 +# ^^^ constant.numeric.integer + -1.5 +# ^^^^ constant.numeric.integer + -3 + -2 +# ^^ constant.numeric.integer +# ^ keyword.operator +# ^^ constant.numeric.integer + -3+-2 +# ^^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^ keyword.operator + 3++2 +# ^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^ keyword.operator + +2 +# ^^ constant.numeric.integer + -3+- +# ^^ constant.numeric.integer +# ^^ keyword.operator + 10/-10 +# ^^ constant.numeric.integer +# ^^^ constant.numeric.integer +# ^ keyword.operator + 10/-10D +# ^^ constant.numeric.integer +# ^^^^ constant.numeric.integer +# ^ keyword.operator + -10.002L +# ^^^^^^^^ constant.numeric.integer + $x..5.40D +# ^ punctuation.definition.variable +# ^^ variable.other.readwrite +# ^^ keyword.operator.range +# ^^^^^ constant.numeric.integer + -500..-495 +# ^^^^ constant.numeric.integer +# ^^^^ constant.numeric.integer +# ^^ keyword.operator.range + $true..3 +# ^ punctuation.definition.variable +# ^^^^ constant.language +# ^^ keyword.operator.range +# ^ constant.numeric.integer + -2..$null +# ^^ constant.numeric.integer +# ^^ keyword.operator.range +# ^^^^^ constant.language +# ^ punctuation.definition.variable + -3..3 +# ^^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^ keyword.operator.range + 1..3 +# ^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^ keyword.operator.range + 6,10,-3 +# ^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^ punctuation.separator.sequence -constant +# ^ punctuation.separator.sequence -constant + 0x476 +# ^^^^^ constant.numeric.integer.hexadecimal + +0x20 +# ^^^^^ constant.numeric.integer.hexadecimal + -0x20 +# ^^^^^ constant.numeric.integer.hexadecimal + +# Types +[string] +# <- punctuation.section.bracket.begin +# ^ storage.type +# ^ punctuation.section.bracket.end +[string[]] +# <- punctuation.section.bracket.begin +# ^ storage.type +# ^ punctuation.section.bracket.begin +# ^^ punctuation.section.bracket.end +[int32] +# <- punctuation.section.bracket.begin +# ^^^^ storage.type +# ^ punctuation.section.bracket.end +[System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] +# <- punctuation.section.bracket.begin +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.type +# ^^^^^^^^^^^^^ storage.type +# ^^^^^^^^^^ storage.type +# ^^ storage.type +# ^^ punctuation.section.bracket.begin +# ^ punctuation.section.bracket.begin +# ^ punctuation.section.bracket.end +# ^^^ punctuation.section.bracket.end +[System.Array+SZArrayEnumerator] +# <- punctuation.section.bracket.begin +# ^^^^^^^^^^^ storage.type +# ^^^^^^^^^^^^^^^^^ storage.type +# ^ keyword.operator +# ^ punctuation.section.bracket.end +[int]::MinValue +# <- punctuation.section.bracket.begin +# ^ storage.type +# ^ punctuation.section.bracket.end +[System.DateTime]::Parse('2016/09/21') +# <- punctuation.section.bracket.begin +# ^^^^^^^^^^^^^^ storage.type +# ^ punctuation.section.bracket.end +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end + +# Commands (functions) +Invoke-Something -foobar +# <- support.function +# ^ keyword.operator +Invoke-Something -foobar value +# <- support.function +# ^ keyword.operator +Invoke-Something -foobar:$true +# <- support.function +# ^ keyword.operator +# ^ punctuation.definition.variable +# ^^^^ constant.language +Invoke-Something -foobar: $true +# <- support.function +# ^ keyword.operator +Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose +# <- support.function +# ^ ^ ^ ^ ^ keyword.operator +# ^^ constant.numeric.integer +# ^ source +Invoke-Something (1..20 | Invoke-Something) -p2 'value' +# <- support.function +Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch +# <- support.function +# ^ ^ ^ keyword.operator +# ^^ constant.numeric.integer +# ^ keyword.operator.other +# ^ support.function +# ^ source +Invoke-Something -p1 { +# <- support.function +# ^ keyword.operator +# ^ punctuation.section.braces.begin + Invoke-Something -foobar:$true +# ^ support.function +# ^ keyword.operator +# ^ punctuation.definition.variable +# ^^^^ constant.language +} | Invoke-Something +# <- punctuation.section.braces.end +# ^ keyword.operator.logical.pipe +# ^ support.function +Invoke-Something -p1 value ` +# <- support.function +# ^ keyword.operator +# ^ punctuation.separator.continuation + -p2 14.4 ` +# ^ keyword.operator +# ^^^^ constant.numeric.integer +# ^ punctuation.separator.continuation + -p3 $value | Invoke-Something -verbose +# ^ keyword.operator +# ^ keyword.operator +# ^ punctuation.definition.variable +# ^ keyword.operator.logical.pipe +# ^^^^^^^^^^^^^^^^ support.function + +# Commands (Built-in variables) +ls *.ps1 -recurse +# ^ keyword.operator +# ^ keyword.operator + +# Commands (executable files) +. .\scripts\myscript.ps1 -parameter 'value' +# <- keyword.operator.other +# ^ keyword.operator +# ^^^^^^^ string.quoted.single +& tool.exe +# <- keyword.operator.other +# ^^^^^^^^ support.function +something.cmd +# <- support.function +øyvind.com # this should also highlight - TODO + +# switch +switch ("fourteen") {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch -CaseSensitive ("fourteen") {} +# <- keyword.control +# ^ keyword.operator +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch -Regex ("fourteen") {} +# <- keyword.control +# ^ keyword.operator +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch -Wildcard ($a) {} +# <- keyword.control +# ^ keyword.operator +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch -regex -file .\somefile.txt {} +# <- keyword.control +# ^ keyword.operator +# ^ keyword.operator +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch (3) {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +switch (4, 2) {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ constant.numeric.integer +# ^ constant.numeric.integer +# ^ punctuation.separator +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end + +switch -Regex -File $filePath { +# <- keyword.control +# ^ keyword.operator +# ^ keyword.operator +# ^ punctuation.definition.variable +# ^ meta.scriptblock punctuation.section.braces.begin + '.' {} +# ^^^ string.quoted.single +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +} +# <- meta.scriptblock punctuation.section.braces.end + +switch -Wildcard -CaseSensitive ($something) { +# <- keyword.control +# ^ keyword.operator +# ^ keyword.operator +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin + '.' {} +# ^^^ string.quoted.single +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +} +# <- meta.scriptblock punctuation.section.braces.end + +switch ('this') { +# <- keyword.control +# ^ punctuation.section.group.begin +# ^^^^^^ string.quoted.single +# ^ punctuation.section.group.end +# ^ meta.scriptblock punctuation.section.braces.begin + 'this' {} +# ^^^^^^ string.quoted.single +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.scriptblock punctuation.section.braces.end +} +# <- meta.scriptblock punctuation.section.braces.end + +# Functions and filters +functioN MyFunction{} +# <- storage.type +# ^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function My-Function {} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +Function My.Function{} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function My-Function.Other{} +# <- storage.type +# ^^^^^^^^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function Some.other.function{} +# <- storage.type +# ^^^^^^^^^^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +FUNCTION MyFunction2 {} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function New-File { } +# <- storage.type +# ^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function New-File ($Name) { } +# <- storage.type +# ^^^^^^^^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function NewFile($Name) { } +# <- storage.type +# ^^^^^^^ entity.name.function +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +filter myfilter($param) {} +# <- storage.type +# ^^^^^^^^ entity.name.function +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +Filter my-Filter ($param){} +# <- storage.type +# ^^^^^^^^^ entity.name.function +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + +# Note that the # in the path should highlight as a comment! +function Test-Drive([string]$roman) { +# <- storage.type +# ^^^^^^^^^^ entity.name.function +# ^ punctuation.section.group.begin +# ^ punctuation.section.bracket.begin +# ^^^^^^ storage.type +# ^ punctuation.section.bracket.end +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin + $roman | c:\users\Me\Documents\Programming\F#\test.exe $roman +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.logical.pipe +# ^ punctuation.definition.comment +# ^^^^ comment.line +} +# <- punctuation.section.braces.end + +function Verb-Noun +# <- meta.function storage.type +# ^ meta.function entity.name.function +{ +# <- punctuation.section.braces.begin + + Param + # <- keyword.control + ( + # <- punctuation.section.group.begin + # Param1 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(Mandatory=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipeline=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell + # ^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipelineByPropertyName = $true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + ValueFromRemainingArguments=$false, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + Position=0, + #^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ constant.numeric.integer + # ^ punctuation.separator + SupportsPaging, + #^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ punctuation.separator + ParameterSetName = 'Parameter Set 1')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + # ^ - meta.attribute + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [ValidateNotNull()] + #^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [ValidateCount(0,5)] + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [ValidateSet("sun", "moon", "earth")] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + [Alias("p1")] + #^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + $Param1 + # <- punctuation.definition.variable + # ^ variable.other.readwrite + ) + # <- punctuation.section.group.end + + # Do Something.... + +} +# <- punctuation.section.braces.end + +# Class +class Vehicle { +# <- storage.type.class +# ^^^^^^^ entity.name.class +# ^ punctuation.section.braces.begin + Vehicle() {} +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + Vehicle([string]$Owner) { +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.braces.begin + $this.Owner = $Owner + } + + [int]$Mileage +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + [int]$Age +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + [string]$Owner +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + + [void]Drive([int]$NumberOfMiles) { +# ^^^^ storage.type +# ^^^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + $this.Mileage += $NumberOfMiles +# ^^^^^ variable.language +# ^ punctuation.definition.variable +# ^^^^^^^ variable.other.member +# ^^ keyword.operator.assignment + + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# Control words +foreach ($item in $collection) { +# <- keyword.control +# ^ punctuation.section.group.begin +# ^^ keyword.control +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.definition.variable +# ^ punctuation.definition.variable +} +# <- punctuation.section.braces.end + +try { } +# <- keyword.control +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +catch { } +# <- keyword.control +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + +# Reserved words +Configuration Crazyness { +# <- storage.type +# ^ entity.name.function +# ^ punctuation.section.braces.begin + Node Whatever { +# ^ punctuation.section.braces.begin + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# Redirection +notepad.exe > log.txt +# <- support.function +# ^ keyword.operator.redirection +notepad.exe 1> log.txt +# <- support.function +# ^ keyword.operator.redirection +notepad.exe 2>&1 +# <- support.function +# ^^ keyword.operator.redirection +notepad.exe 3>&1 +# <- support.function +# ^^ keyword.operator.redirection +notepad.exe 4>&1 +# <- support.function +# ^^ keyword.operator.redirection +notepad.exe 5>&1 +# <- support.function +# ^^ keyword.operator.redirection +notepad.exe 6>&1 +# <- support.function +# ^^ keyword.operator.redirection +notepad.exe 2>&1> log.txt +# <- support.function +# ^^ keyword.operator.redirection +# ^ keyword.operator.redirection + +# Operators +if (10 -cgt 100) { } +# <- keyword.control +# ^ punctuation.section.group.begin +# ^^ constant.numeric.integer +# ^^^^ keyword.operator.comparison +# ^^^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +$a -is $b +# ^^^ keyword.operator.logical +$b -contains $c +# ^^^^^^^^^ keyword.operator.logical +$x -notcontains $c +# ^^^^^^^^^^^^ keyword.operator.logical +$c -in $b +# ^^^ keyword.operator.logical +$c -notin $x +# ^^^^^^ keyword.operator.logical +$a -match $b +# ^^^^^^ keyword.operator.logical +$a -notmatch $b +# ^^^^^^^^^ keyword.operator.logical +$x -like $c +# ^^^^^ keyword.operator.logical +100 -and 0 +# ^^^^ keyword.operator.logical +# ^ constant.numeric.integer +$a -ceq 4 -and $a -ine $d -or +# ^^^^ keyword.operator.comparison +# ^ constant.numeric.integer +# ^^^^ keyword.operator.logical +# ^ punctuation.definition.variable +# ^^^^ keyword.operator.comparison +# ^^^ keyword.operator.logical +$c -is [Type] +# ^^^ keyword.operator.logical +# ^ storage.type +$c -isnot [Type] +# ^^^^^^ keyword.operator.logical +# ^ storage.type +$c -as [Type] +# ^ keyword.operator.comparison +# ^ storage.type +$k = $y -bor $k +# ^ keyword.operator.assignment +# ^ keyword.operator.bitwise +$x = $y -band $x +# ^ keyword.operator.assignment +# ^ keyword.operator.bitwise +$z = -bnot $x +# ^ keyword.operator.assignment +# ^ keyword.operator.bitwise +$l = 1 -shl 10 +# ^ keyword.operator.assignment +# ^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^^^^ keyword.operator.bitwise +$r = 10 -shr 1 +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^^^ keyword.operator.bitwise +$k = $y -xor $b +# ^ keyword.operator.assignment +# ^ keyword.operator.logical +$k = $y -bxor $b +# ^ keyword.operator.assignment +# ^ keyword.operator.bitwise +$a -icontains $c +# ^^^^^^^^^^ keyword.operator.logical +$a -ccontains $c +# ^^^^^^^^^^ keyword.operator.logical +$a -iNotContains $c +# ^^^^^^^^^^^^^ keyword.operator.logical +$a -cNotContains $c +# ^^^^^^^^^^^^^ keyword.operator.logical +$a -cmatch $c +# ^^^^^^^ keyword.operator.logical +$x -iMatch $c +# ^^^^^^^ keyword.operator.logical +$x -iNotMatch $c +# ^^^^^^^^^^ keyword.operator.logical +$a -iLike $b +# ^^^^^^ keyword.operator.logical +$b -cLike $c +# ^^^^^^ keyword.operator.logical +"hey" -cgt "Hey" +# ^^^^ keyword.operator.comparison +"Hey" -igt "hey" +# ^^^^ keyword.operator.comparison +"hey" -cge "Hey" +# ^^^^ keyword.operator.comparison +"Hey" -ige "hey" +# ^^^^ keyword.operator.comparison +"HEY" -clt "hey" +# ^^^^ keyword.operator.comparison +"HEY" -ilt "hey" +# ^^^^ keyword.operator.comparison +"HEY" -cle "hey" +# ^^^^ keyword.operator.comparison +"HEY" -ile "hey" +# ^^^^ keyword.operator.comparison + +# format + "{0:N2}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:D8}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:C2}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:P0}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:X0}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + (1.11).ToString("#.#") +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.begin +# ^^^^ constant.numeric.integer +# ^ string.quoted.double + "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 +# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format +# ^^^ constant.numeric.integer + ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) +# ^^^^^^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format +# ^^ keyword.operator.string-format + "{0:R}" -f (1mb/2.0) +# ^^ keyword.other +# ^ keyword.operator.string-format + "{0:00.0}" -f 4.12341234 +# ^ keyword.operator.string-format + "{0:##.#}" -f 4.12341234 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:#,#.#}" -f 1234.121234 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:##,,.000}" -f 1048576 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{this is not a #comment}" +# ^ - comment + "{0:##.#E000}" -f 2.71828 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:#.00'##'}" -f 2.71828 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:POS;NEG;ZERO}" -f -14 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:$## Please}" -f 14 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0,-8:P1}" -f 1.75 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 +# ^ keyword.operator.string-format + '{0:00000.000}' -f 7.125 +# ^ string.quoted.single +# ^ keyword.operator.string-format + +# Misc test cases +Test-Function -Class ClassName +# ^ - storage.type +New-Object -TypeName System.Diagnostics.Process +# ^^^^^^^ - keyword.control +New-Object -TypeName System.Data +# ^^^^ - keyword.control +@("any","array","has").foreach({ $_ }) +# <- keyword.other.array.begin +# ^ meta.group.array-expression +# ^ keyword.control +# ^ meta.scriptblock +@('any','array','has').foreach{ $_ } +# <- keyword.other.array.begin +# ^ meta.group.array-expression +# ^ keyword.control +# ^ meta.scriptblock +@("any","array","has").where({ $_.Length -gt 3 }) +# <- keyword.other.array.begin +# ^ meta.group.array-expression +# ^ keyword.control +# ^ meta.scriptblock +@("any","array","has").where{ $_.Length -gt 3 } +# <- keyword.other.array.begin +# ^ meta.group.array-expression +# ^ keyword.control +# ^ meta.scriptblock +$file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" +# <- punctuation.definition.variable +# ^ support.function +# ^ support.variable.drive +# ^ variable.other.readwrite +# ^ string.quoted.double punctuation.definition.variable +# ^ storage.type +$ScriptBlock | Out-File $file -Force +# <- punctuation.definition.variable +# ^ keyword.operator.other +# ^ punctuation.definition.variable +# ^ keyword.operator.assignment +workflow w1 {} +# <- storage.type +# ^ entity.name.function +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +Workflow work { sequence {} } +# <- storage.type +# ^ entity.name.function +# ^ punctuation.section.braces.begin +# ^^^^^^^^ keyword.control +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +# ^ punctuation.section.braces.end +get-thing | Out-WithYou > $null # destroy +# ^^^^^^^ support.function +# ^^^^^^^^^^^ support.function +# ^ keyword.operator.logical.pipe +# ^ keyword.operator.redirection +# ^ punctuation.definition.variable +# ^ constant.language +# ^ punctuation.definition.comment +"Escaped chars: `", `n, `$, `b, `t, `e, `u{10ffff}, `"" +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^ constant.character.escape +# ^^^^^^^^^^ constant.character.escape +# ^^ constant.character.escape +'But here they''re not escape chars: `", `n, `$, `b, `"' +# ^^ constant.character.escape +# ^^^^^^^^^^^^^^^^^^^ - constant +"When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" +# ^ ^ punctuation.definition.variable +# ^ keyword.operator.logical.pipe +# ^ ^ meta.group.complex.subexpression punctuation.section.group.begin +# ^ storage.type +# ^ ^ meta.group.complex.subexpression punctuation.section.group.end +"This is the Debugreference variable: $DebugPreference" +# <- string.quoted.double +# ^ variable.language + +$ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName $PSSessionConfigurationName $PSSessionOption $ProgressPreference $VerbosePreference $WarningPreference $WhatIfPreference +# <- variable.language +# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language +# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language +# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language diff --git a/Tests/syntax_text_Function.ps1 b/Tests/syntax_text_Function.ps1 new file mode 100644 index 0000000..35d5f25 --- /dev/null +++ b/Tests/syntax_text_Function.ps1 @@ -0,0 +1,373 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" +using module Microsoft.Management +# <- keyword.control.using +# ^ keyword.other +# ^ variable.parameter + +<# +# <- punctuation.definition.comment.block.begin + .Synopsis + # <- constant.string.documentation + # ^ keyword.operator.documentation + Short description + .DESCRIPTION + # <- constant.string.documentation + # ^ keyword.operator.documentation + Long description + .EXAMPLE + # <- constant.string.documentation + # ^ keyword.operator.documentation + Example of how to use this cmdlet + .EXAMPLE + # <- constant.string.documentation + # ^ keyword.operator.documentation + Another example of how to use this cmdlet + .INPUTS + # <- constant.string.documentation + # ^ keyword.operator.documentation + Inputs to this cmdlet (if any) + .OUTPUTS + # <- constant.string.documentation + # ^ keyword.operator.documentation + Output from this cmdlet (if any) + .NOTES + # <- constant.string.documentation + # ^ keyword.operator.documentation + General notes + .COMPONENT + # <- constant.string.documentation + # ^ keyword.operator.documentation + The component this cmdlet belongs to + .ROLE + # <- constant.string.documentation + # ^ keyword.operator.documentation + The role this cmdlet belongs to + .FUNCTIONALITY + # <- constant.string.documentation + # ^ keyword.operator.documentation + The functionality that best describes this cmdlet + + This should not be considered documentaton -> .role + # ^ - keyword.operator.documentation +#> +# <- punctuation.definition.comment.block.end +function Verb-Noun { +# <- meta.function storage.type +# ^ meta.function entity.name.function + [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + SupportsShouldProcess = $true, + # ^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.attribute constant.language + PositionalBinding = $false, + # ^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^^ meta.attribute constant.language + HelpUri = 'http://www.microsoft.com/', + # ^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + ConfirmImpact = 'Medium')] + # ^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [Alias()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [OutputType([String])] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.bracket.begin + # ^^^^^^ meta.attribute storage.type + # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + Param + # <- keyword.control + ( + # <- punctuation.section.group.begin + # Param1 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(Mandatory=$true, + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.attribute constant.language + # ^ meta.attribute keyword.operator.other + ValueFromPipeline=$true, + # ^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.attribute constant.language + # ^ meta.attribute keyword.operator.other + ValueFromPipelineByPropertyName = $true, + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.attribute constant.language + # ^ meta.attribute keyword.operator.other + ValueFromRemainingArguments=$false, + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^^ meta.attribute constant.language + # ^ meta.attribute keyword.operator.other + Position=0, + # ^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute keyword.operator.other + ParameterSetName = 'Parameter Set 1')] + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateNotNullOrEmpty()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateNotNull()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateNotNullOrEmpty()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateCount(0,5)] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute keyword.operator.other + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateSet("sun", "moon", "earth")] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^ meta.attribute string.quoted.double + # ^ meta.attribute keyword.operator.other + # ^^^^^^ meta.attribute string.quoted.double + # ^ meta.attribute keyword.operator.other + # ^^^^^^^ meta.attribute string.quoted.double + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [Alias("p1")] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^ meta.attribute string.quoted.double + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + $Param1, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ keyword.operator.other + + # Param2 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [AllowNull()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [AllowEmptyCollection()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [AllowEmptyString()] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateScript({$true})] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.scriptblock meta.attribute + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.scriptblock constant.language + # ^ meta.scriptblock meta.attribute + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateRange(0,5)] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute keyword.operator.other + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [int32] + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + $Param2, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ keyword.operator.other + + # Param3 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Another Parameter Set')] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidatePattern("[a-z]*")] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^ meta.attribute string.quoted.double + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateLength(0,15)] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute constant.numeric.integer + # ^ meta.attribute keyword.operator.other + # ^^ meta.attribute constant.numeric.integer + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [String] + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + $Param3, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ keyword.operator.other + + # Param4 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute meta.scriptblock + # ^^^^^^^^^ meta.scriptblock support.function + # ^ meta.scriptblock punctuation.definition.variable + # ^ meta.scriptblock support.variable.automatic + # ^ meta.attribute meta.scriptblock + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [string] + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + $Param4, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ keyword.operator.other + + # Param5 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + [ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting + # <- meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.bracket.end + # ^ comment.line punctuation.definition.comment + # ^ comment.line + [string] + # <- punctuation.section.bracket.begin + # ^ storage.type + # ^ punctuation.section.bracket.end + $Param5 + # <- punctuation.definition.variable + # ^ variable.other.readwrite + ) + # <- punctuation.section.group.end + + Begin + # <- keyword.control + { + } + Process { + # <- keyword.control + if ($pscmdlet.ShouldProcess("Target", "Operation")) { + # <- keyword.control + # ^ punctuation.section.group.begin + # ^ punctuation.definition.variable + # ^^^^^^^^ variable.language + # ^^^^^^^^^^^^^ variable.other.member + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.group.end + } + } + End { + # <- keyword.control + + } +} From 46adfadc02403ab6f75a21888fc520b597af3be5 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:27 -0500 Subject: [PATCH 04/23] Push a little further to scope rectification --- PowerShell.sublime-syntax | 141 ++++++++-------- Tests/syntax_test_PowerShell.ps1 | 230 +++++++++++++++++++-------- Tests/syntax_text_Function.ps1 | 265 +++++++++++++++++-------------- 3 files changed, 385 insertions(+), 251 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index a6c13f5..02d0623 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -50,42 +50,46 @@ contexts: scope: punctuation.section.group.end.powershell pop: true - include: main - - match: (\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b) - scope: support.function.powershell - - match: (? $null # destroy # ^^ constant.character.escape # ^^^^^^^^^^^^^^^^^^^ - constant "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" -# ^ ^ punctuation.definition.variable +# ^ punctuation.definition.variable # ^ keyword.operator.logical.pipe -# ^ ^ meta.group.complex.subexpression punctuation.section.group.begin -# ^ storage.type -# ^ ^ meta.group.complex.subexpression punctuation.section.group.end -"This is the Debugreference variable: $DebugPreference" -# <- string.quoted.double -# ^ variable.language +# ^ meta.group.complex.subexpression punctuation.section.group.begin +# ^^^^^^ storage.type +# ^ meta.group.complex.subexpression punctuation.section.group.begin +# ^ meta.group.complex.subexpression punctuation.section.group.end +# ^ meta.group.complex.subexpression punctuation.section.group.end +# ^ punctuation.definition.variable +"This is the DebugPreference variable: $DebugPreference" +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^ variable.language + + $ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^ variable.language - punctuation + $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation -$ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName $PSSessionConfigurationName $PSSessionOption $ProgressPreference $VerbosePreference $WarningPreference $WhatIfPreference -# <- variable.language -# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language -# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language -# ^ variable.language ^ variable.language ^ variable.language ^ variable.language ^ variable.language + $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation + $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^ variable.language - punctuation + $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $PSSessionConfigurationName $PSSessionOption $ProgressPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $VerbosePreference $WarningPreference $WhatIfPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^ variable.language - punctuation diff --git a/Tests/syntax_text_Function.ps1 b/Tests/syntax_text_Function.ps1 index 35d5f25..ffedabf 100644 --- a/Tests/syntax_text_Function.ps1 +++ b/Tests/syntax_text_Function.ps1 @@ -7,44 +7,44 @@ using module Microsoft.Management <# # <- punctuation.definition.comment.block.begin .Synopsis - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Short description .DESCRIPTION - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Long description .EXAMPLE - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Example of how to use this cmdlet .EXAMPLE - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Another example of how to use this cmdlet .INPUTS - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Inputs to this cmdlet (if any) .OUTPUTS - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation Output from this cmdlet (if any) .NOTES - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation General notes .COMPONENT - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation The component this cmdlet belongs to .ROLE - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation The role this cmdlet belongs to .FUNCTIONALITY - # <- constant.string.documentation - # ^ keyword.operator.documentation + # <- punctuation.definition.keyword + # ^ keyword.other.documentation The functionality that best describes this cmdlet This should not be considered documentaton -> .role @@ -104,155 +104,174 @@ function Verb-Noun { # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(Mandatory=$true, - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^ meta.attribute punctuation.definition.variable - # ^^^^ meta.attribute constant.language - # ^ meta.attribute keyword.operator.other + #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator ValueFromPipeline=$true, - # ^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^ meta.attribute punctuation.definition.variable - # ^^^^ meta.attribute constant.language - # ^ meta.attribute keyword.operator.other + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell + # ^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator ValueFromPipelineByPropertyName = $true, - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^ meta.attribute punctuation.definition.variable - # ^^^^ meta.attribute constant.language - # ^ meta.attribute keyword.operator.other + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator ValueFromRemainingArguments=$false, - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^ meta.attribute punctuation.definition.variable - # ^^^^^ meta.attribute constant.language - # ^ meta.attribute keyword.operator.other + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator Position=0, - # ^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute keyword.operator.other + #^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ constant.numeric.integer + # ^ punctuation.separator ParameterSetName = 'Parameter Set 1')] - # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + # ^ - meta.attribute [ValidateNotNullOrEmpty()] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [ValidateNotNull()] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [ValidateNotNullOrEmpty()] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [ValidateCount(0,5)] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute keyword.operator.other - # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [ValidateSet("sun", "moon", "earth")] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^^^^ meta.attribute string.quoted.double - # ^ meta.attribute keyword.operator.other - # ^^^^^^ meta.attribute string.quoted.double - # ^ meta.attribute keyword.operator.other - # ^^^^^^^ meta.attribute string.quoted.double - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [Alias("p1")] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^^^^ meta.attribute string.quoted.double - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.bracket.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end $Param1, # <- punctuation.definition.variable # ^ variable.other.readwrite - # ^ keyword.operator.other + # ^ punctuation.separator # Param2 help description # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(ParameterSetName='Parameter Set 1')] - # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute - # ^ meta.attribute keyword.operator.assignment - # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ support.function.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end + # ^ - meta.attribute [AllowNull()] + #^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end [AllowEmptyCollection()] + #^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end [AllowEmptyString()] + #^^^^^^^^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end [ValidateScript({$true})] + #^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.scriptblock meta.attribute - # ^ meta.attribute punctuation.definition.variable - # ^^^^ meta.scriptblock constant.language - # ^ meta.scriptblock meta.attribute - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ meta.attribute + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ meta.attribute + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [ValidateRange(0,5)] + #^^^^^^^^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute keyword.operator.other - # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.bracket.end [int32] # <- punctuation.section.bracket.begin - # ^ storage.type + #^^^^^ storage.type # ^ punctuation.section.bracket.end $Param2, # <- punctuation.definition.variable # ^ variable.other.readwrite - # ^ keyword.operator.other + # ^ punctuation.separator # Param3 help description # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(ParameterSetName='Another Parameter Set')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute # <- meta.attribute punctuation.section.bracket.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin @@ -273,18 +292,18 @@ function Verb-Noun { # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute constant.numeric.integer - # ^ meta.attribute keyword.operator.other + # ^ punctuation.separator # ^^ meta.attribute constant.numeric.integer # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end [String] # <- punctuation.section.bracket.begin - # ^ storage.type + #^^^^^^ storage.type # ^ punctuation.section.bracket.end $Param3, # <- punctuation.definition.variable - # ^ variable.other.readwrite - # ^ keyword.operator.other + #^^^^^^ variable.other.readwrite + # ^ punctuation.separator # Param4 help description # <- comment.line punctuation.definition.comment @@ -305,7 +324,7 @@ function Verb-Noun { # ^ meta.attribute meta.scriptblock # ^^^^^^^^^ meta.scriptblock support.function # ^ meta.scriptblock punctuation.definition.variable - # ^ meta.scriptblock support.variable.automatic + # ^ meta.scriptblock variable.language # ^ meta.attribute meta.scriptblock # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end @@ -316,7 +335,7 @@ function Verb-Noun { $Param4, # <- punctuation.definition.variable # ^ variable.other.readwrite - # ^ keyword.operator.other + # ^ punctuation.separator # Param5 help description # <- comment.line punctuation.definition.comment From a0a24e9360dd3b7634a63bbdbefbc485e2c332d4 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:30 -0500 Subject: [PATCH 05/23] Overhaul numbers and option flags --- PowerShell.sublime-syntax | 145 ++++++++---- ..._Function.ps1 => syntax_test_Function.ps1} | 1 + Tests/syntax_test_PowerShell.ps1 | 207 +++++++++++------- 3 files changed, 231 insertions(+), 122 deletions(-) rename Tests/{syntax_text_Function.ps1 => syntax_test_Function.ps1} (99%) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 02d0623..f4753e1 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -10,6 +10,10 @@ file_extensions: - psd1 variables: + dec_digits: (?:[\d_]*\d) + dec_exponent: (?:[eE][-+]?{{dec_digits}}) + float_suffix: '(?i:[fdm])' + integer_suffix: '(?i:ul?|lu?)' bytes_unit: (?i:[kmgtp]b) contexts: @@ -64,30 +68,51 @@ contexts: # This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. scope: storage.modifier.powershell - match: \b((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b - # capture should be entity.name.type, but it doesn't provide a good color in the default schema. captures: 1: storage.type.class.powershell 2: meta.class.powershell entity.name.class.powershell - - match: \B-(?i:as)\b + - match: \B(-)(?i:as)\b scope: keyword.operator.cast.powershell - - match: \B-(?i:[ic]?(?:eq|ne|[gl][te]))(?!\p{L}) + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te]))(?!\p{L}) scope: keyword.operator.comparison.powershell - - match: \B-(?i:[ic]?(?:not)?(?:like|match|contains|in))(?!\p{L}) + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in))(?!\p{L}) scope: keyword.operator.logical.powershell - - match: \B-(?i:join|split|replace)(?!\p{L})|! + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:join|split|replace)(?!\p{L})|! scope: keyword.operator.string.powershell - - match: \B-(?i:is(?:not)?)\b + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:is(?:not)?)\b scope: keyword.operator.logical.powershell - - match: \B-(?i:and|or|not|xor)(?!\p{L})|! + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:and|or|not|xor)(?!\p{L})|! scope: keyword.operator.logical.powershell - - match: \B-(?i:band|bor|bnot|bxor|sh[lr])(?!\p{L}) + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr])(?!\p{L}) scope: keyword.operator.bitwise.powershell - - match: \B-(?i:f)(?!\p{L}) + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:f)(?!\p{L}) scope: keyword.operator.string-format.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B([-/])[\p{L}](?:[\w-]*\w)? + scope: variable.parameter.option.powershell + captures: + 1: punctuation.definition.parameter.powershell - match: '[+/*%-]?=' scope: keyword.operator.assignment.powershell - match: (?:\+\+|--)(?![ \t]*\d) scope: keyword.operator.assignment.powershell + - match: '[+-](?=\.?\d)' + scope: keyword.operator.unary.powershell - match: '[+/*%-]' scope: keyword.operator.arithmetic.powershell - match: \|\||&& @@ -102,7 +127,7 @@ contexts: scope: keyword.operator.logical.pipe.powershell - match: '&|\B\.(?= )' scope: keyword.operator.other.powershell - - match: (?&)(1)|([1-6])(>)|([1-6])(>>) + # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection + - match: ([2-6*])(>&)(1) captures: 1: constant.numeric.decimal.file-descriptor.powershell 2: keyword.operator.redirection.powershell 3: constant.numeric.decimal.file-descriptor.powershell - 4: constant.numeric.decimal.file-descriptor.powershell - 5: keyword.operator.redirection.powershell - 6: constant.numeric.decimal.file-descriptor.powershell - 7: keyword.operator.redirection.powershell - - match: '>>?|<\|' + - match: ([1-6*])(>>?) + captures: + 1: constant.numeric.decimal.file-descriptor.powershell + 2: keyword.operator.redirection.powershell + - match: '>>?' scope: keyword.operator.redirection.powershell + # - match: <+ + # scope: invalid.illegal.powershell requires-directive: - match: (?<=#)(?i:requires)\s @@ -349,35 +377,44 @@ contexts: - include: interpolated-string-content numeric-constant: - - match: ((?:[-+]|\b)0(?i:x[0-9a-f_]+)(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b + - match: \b((0[xX])[\h_]*\h({{integer_suffix}})?)({{bytes_unit}})?\b captures: 1: constant.numeric.integer.hexadecimal.powershell - 2: keyword.other.powershell - - match: ((?:[-+]|\b)(?:[0-9_]+)?(\.)[0-9_]+(?:(?i:e)[0-9]+)?(?i:[fdm])?)({{bytes_unit}}?)\b - captures: - 1: constant.numeric.float.decimal.powershell - 2: punctuation.separator.decimal.powershell - 3: keyword.other.unit.powershell - - match: ((?:[-+]|\b)0[bB][01_]+(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b + 2: punctuation.definition.numeric.base.powershell + 3: storage.type.numeric.powershell + 4: keyword.other.unit.powershell + - match: \b((0[bB])[01_]*[01]({{integer_suffix}})?)({{bytes_unit}})?\b captures: 1: constant.numeric.integer.binary.powershell - 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+[eE](?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b + 2: punctuation.definition.numeric.base.powershell + 3: storage.type.numeric.powershell + 4: keyword.other.unit.powershell + - match: |- + (?x: + \b( + {{dec_digits}} + (?: + (?: + (?:(\.(?!\.)){{dec_digits}}?){{dec_exponent}}? + |{{dec_exponent}} + ) + ({{float_suffix}})? + |({{float_suffix}}) + ) + ) + ({{bytes_unit}})? + )\b captures: - 1: constant.numeric.integer.powershell - 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+\.[eE](?:[0-9_])?+(?i:[fdm])?)({{bytes_unit}}?)\b - captures: - 1: constant.numeric.integer.powershell - 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:[fdm]))({{bytes_unit}}?)\b - captures: - 1: constant.numeric.integer.powershell - 2: keyword.other.powershell - - match: ((?:[-+]|\b)[0-9_]+[\.]?(?i:u|l|ul|lu)?)({{bytes_unit}}?)\b + 1: constant.numeric.float.decimal.powershell + 2: punctuation.separator.decimal.powershell + 3: storage.type.numeric.powershell + 4: storage.type.numeric.powershell + 5: keyword.other.unit.powershell + - match: \b((?:0|[1-9]{{dec_digits}}?)({{integer_suffix}})?)({{bytes_unit}})?\b captures: - 1: constant.numeric.integer.powershell - 2: keyword.other.powershell + 1: constant.numeric.integer.decimal.powershell + 2: storage.type.numeric.powershell + 3: keyword.other.unit.powershell script-block: - match: \{ @@ -410,7 +447,22 @@ contexts: 1: support.constant.variable.powershell 2: punctuation.definition.variable.powershell 3: variable.other.member.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))((?:\.(?:\p{L}|\d|_)+)*\b)?\b + - match: |- + (?x: + ( + (\$) + (?: + [$^?_] + |(?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}|\d|_)+)*\b)? + ) captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell @@ -459,7 +511,18 @@ contexts: scope: support.constant.variable.powershell captures: 1: 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 + - match: |- + (?x: + (\$) + (?: + [$^?_] + |(?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 + ) + ) scope: variable.language.powershell captures: 1: punctuation.definition.variable.powershell diff --git a/Tests/syntax_text_Function.ps1 b/Tests/syntax_test_Function.ps1 similarity index 99% rename from Tests/syntax_text_Function.ps1 rename to Tests/syntax_test_Function.ps1 index ffedabf..2b1efdb 100644 --- a/Tests/syntax_text_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -1,4 +1,5 @@ # SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + using module Microsoft.Management # <- keyword.control.using # ^ keyword.other diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index 29d30df..5a6d4d5 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -84,8 +84,10 @@ throw "Do not run this file!" & tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment # <- keyword.operator.other # ^^^^^^^^ variable.function -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^^ variable.parameter.option # ^^^ keyword.control # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted - constant - variable - comment @@ -94,7 +96,7 @@ $_, $$, $^, $? # <- punctuation.definition.variable #^ variable.language # ^ punctuation.definition.variable -# ^^ variable.language +# ^^ variable.language # ^ punctuation.definition.variable # ^^ variable.language # ^ punctuation.definition.variable @@ -322,7 +324,7 @@ $a2[-1] # <- variable.other.readwrite punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.bracket.begin -# ^^ constant.numeric.integer +# ^ constant.numeric.integer # ^ punctuation.section.bracket.end $a3[1..2] # <- variable.other.readwrite punctuation.definition.variable @@ -433,75 +435,87 @@ There is no @platting here! # Numeric constants -3 -# ^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^ constant.numeric.integer .5 # ^^ constant.numeric.float +.5 -# ^^^ constant.numeric.float +# ^ keyword.operator.unary +# ^^ constant.numeric.float 1. -# ^ constant.numeric.integer -# ^ - constant +# ^^ constant.numeric.float 1.d -# ^^^ constant.numeric.integer +# ^^^ constant.numeric.float 1.lGB # ^^^ constant.numeric.integer -# ^^ keyword.other +# ^^ keyword.other.unit 1.e+12d -# ^^^^^^^ constant.numeric.integer +# ^^^^^^^ constant.numeric.float 1e+12d -# ^^^^^^ constant.numeric.integer +# ^^^^^^ constant.numeric.float 1.5 # ^^^ constant.numeric.float -1.5 -# ^^^^ constant.numeric.float +# ^ keyword.operator.unary +# ^^^ constant.numeric.float -3 + -2 -# ^^ constant.numeric.integer -# ^ keyword.operator -# ^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer -3+-2 -# ^^ constant.numeric.integer -# ^^ constant.numeric.integer -# ^ keyword.operator +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer 3++2 # ^ constant.numeric.integer -# ^^ constant.numeric.integer -# ^ keyword.operator +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer +2 -# ^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^ constant.numeric.integer -3+- -# ^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^ constant.numeric.integer # ^^ keyword.operator 10/-10 # ^^ constant.numeric.integer -# ^^^ constant.numeric.integer +# ^^ constant.numeric.integer # ^ keyword.operator 10/-10D # ^^ constant.numeric.integer -# ^^^^ constant.numeric.integer +# ^^^ constant.numeric.float # ^ keyword.operator -10.002L -# ^^^^^^^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^^^^^^^ constant.numeric.float $x..5.40D # ^ punctuation.definition.variable # ^^ variable.other.readwrite # ^^ keyword.operator.range # ^^^^^ constant.numeric.float -500..-495 -# ^^^^ constant.numeric.integer -# ^^^^ constant.numeric.integer +# ^ keyword.operator.unary +# ^^^ constant.numeric.integer # ^^ keyword.operator.range +# ^ keyword.operator.unary +# ^^^ constant.numeric.integer $true..3 # ^ punctuation.definition.variable # ^^^^ constant.language # ^^ keyword.operator.range # ^ constant.numeric.integer -2..$null -# ^^ constant.numeric.integer +# ^ constant.numeric.integer # ^^ keyword.operator.range # ^^^^^ constant.language # ^ punctuation.definition.variable -3..3 -# ^^ constant.numeric.integer +# ^ constant.numeric.integer # ^ constant.numeric.integer # ^^ keyword.operator.range 1..3 @@ -511,15 +525,15 @@ There is no @platting here! 6,10,-3 # ^ constant.numeric.integer # ^^ constant.numeric.integer -# ^^ constant.numeric.integer +# ^ constant.numeric.integer # ^ punctuation.separator.sequence -constant # ^ punctuation.separator.sequence -constant 0x476 # ^^^^^ constant.numeric.integer.hexadecimal +0x20 -# ^^^^^ constant.numeric.integer.hexadecimal +# ^^^^ constant.numeric.integer.hexadecimal -0x20 -# ^^^^^ constant.numeric.integer.hexadecimal +# ^^^^ constant.numeric.integer.hexadecimal # Types [string] @@ -565,45 +579,53 @@ There is no @platting here! # Commands (functions) Invoke-Something -foobar # <- support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option Invoke-Something -foobar value # <- support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option Invoke-Something -foobar:$true # <- support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option # ^ punctuation.definition.variable # ^^^^ constant.language Invoke-Something -foobar: $true # <- support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose # <- support.function -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option # ^^ constant.numeric.integer -# ^ keyword.operator -# ^ keyword.operator # ^^^^^^ - keyword -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option Invoke-Something (1..20 | Invoke-Something) -p2 'value' # <- support.function Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch # <- support.function -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option # ^^ constant.numeric.integer # ^ keyword.operator.logical.pipe # ^ support.function -# ^ keyword.operator -# ^^^^^^ - keyword +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option - keyword Invoke-Something -p1 { # <- support.function -# ^ keyword.operator -# ^ punctuation.section.braces.begin +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option Invoke-Something -foobar:$true # ^ support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option # ^ punctuation.definition.variable # ^^^^ constant.language } | Invoke-Something @@ -612,15 +634,19 @@ Invoke-Something -p1 { # ^ support.function Invoke-Something -p1 value ` # <- support.function -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option # ^ punctuation.separator.continuation -p2 14.4 ` -# ^ keyword.operator -# ^^^^ constant.numeric.integer +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^^^^ constant.numeric.float # ^ punctuation.separator.continuation -p3 $value | Invoke-Something -verbose -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^^^^^ variable.parameter.option # ^ punctuation.definition.variable # ^ keyword.operator.logical.pipe # ^^^^^^^^^^^^^^^^ support.function @@ -628,12 +654,14 @@ Invoke-Something -p1 value ` # Commands (Built-in variables) ls *.ps1 -recurse # ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^^ variable.parameter.option # Commands (executable files) . .\scripts\myscript.ps1 -parameter 'value' # <- keyword.operator.other -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^^^^ variable.parameter.option # ^^^^^^^ string.quoted.single & tool.exe # <- keyword.operator.other @@ -652,7 +680,8 @@ switch ("fourteen") {} # ^ meta.scriptblock punctuation.section.braces.end switch -CaseSensitive ("fourteen") {} # <- keyword.control -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^^^^^^^^ variable.parameter.option # ^ punctuation.section.group.begin # ^ string.quoted.double # ^ punctuation.section.group.end @@ -660,7 +689,8 @@ switch -CaseSensitive ("fourteen") {} # ^ meta.scriptblock punctuation.section.braces.end switch -Regex ("fourteen") {} # <- keyword.control -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option # ^ punctuation.section.group.begin # ^ string.quoted.double # ^ punctuation.section.group.end @@ -668,7 +698,8 @@ switch -Regex ("fourteen") {} # ^ meta.scriptblock punctuation.section.braces.end switch -Wildcard ($a) {} # <- keyword.control -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^^^ variable.parameter.option # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ punctuation.section.group.end @@ -676,8 +707,10 @@ switch -Wildcard ($a) {} # ^ meta.scriptblock punctuation.section.braces.end switch -regex -file .\somefile.txt {} # <- keyword.control -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^ variable.parameter.option # ^ meta.scriptblock punctuation.section.braces.begin # ^ meta.scriptblock punctuation.section.braces.end switch (3) {} @@ -699,8 +732,10 @@ switch (4, 2) {} switch -Regex -File $filePath { # <- keyword.control -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^ variable.parameter.option # ^ punctuation.definition.variable # ^ meta.scriptblock punctuation.section.braces.begin '.' {} @@ -716,8 +751,10 @@ switch -Regex -File $filePath { switch -Wildcard -CaseSensitive ($something) { # <- keyword.control -# ^ keyword.operator -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^^^^^^^^^^^ variable.parameter.option # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ variable.other.readwrite @@ -1047,28 +1084,31 @@ Configuration Crazyness { # Redirection notepad.exe > log.txt -# <- support.function +#^^^^^^^^^^ variable.function # ^ keyword.operator.redirection notepad.exe 1> log.txt -# <- support.function +#^^^^^^^^^^ variable.function +# ^ keyword.operator.redirection +notepad.exe *> log.txt +#^^^^^^^^^^ variable.function # ^ keyword.operator.redirection notepad.exe 2>&1 -# <- support.function -# ^^ keyword.operator.redirection -notepad.exe 3>&1 -# <- support.function +#^^^^^^^^^^ variable.function # ^^ keyword.operator.redirection +notepad.exe 3>&1 +#^^^^^^^^^^ variable.function +# ^^ keyword.operator.redirection notepad.exe 4>&1 -# <- support.function +#^^^^^^^^^^ variable.function # ^^ keyword.operator.redirection notepad.exe 5>&1 -# <- support.function +#^^^^^^^^^^ variable.function # ^^ keyword.operator.redirection notepad.exe 6>&1 -# <- support.function +#^^^^^^^^^^ variable.function # ^^ keyword.operator.redirection notepad.exe 2>&1> log.txt -# <- support.function +#^^^^^^^^^^ variable.function # ^^ keyword.operator.redirection # ^ keyword.operator.redirection @@ -1115,7 +1155,7 @@ $c -isnot [Type] # ^^^^^^ keyword.operator.logical # ^ storage.type $c -as [Type] -# ^ keyword.operator.comparison +# ^^^ keyword.operator.cast # ^ storage.type $k = $y -bor $k # ^ keyword.operator.assignment @@ -1196,24 +1236,27 @@ $b -cLike $c (1.11).ToString("#.#") # ^ punctuation.section.group.begin # ^ punctuation.section.group.begin -# ^^^^ constant.numeric.integer +# ^^^^ constant.numeric.float # ^ string.quoted.double "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 # ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double # ^^ keyword.operator.string-format # ^^^ constant.numeric.integer ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) -# ^^^^^^^^^^^^^ string.quoted.double # ^^ keyword.operator.string-format +# ^^^^ constant.numeric.float +# ^^^^^^^^^^^^^ string.quoted.double # ^^ keyword.operator.string-format "{0:R}" -f (1mb/2.0) -# ^^ keyword.other # ^ keyword.operator.string-format +# ^ constant.numeric.integer +# ^^ keyword.other.unit "{0:00.0}" -f 4.12341234 # ^ keyword.operator.string-format "{0:##.#}" -f 4.12341234 # ^ string.quoted.double # ^ keyword.operator.string-format +# ^^^^^^^^^^ constant.numeric.float.decimal "{0:#,#.#}" -f 1234.121234 # ^ string.quoted.double # ^ keyword.operator.string-format @@ -1245,7 +1288,7 @@ $b -cLike $c # Misc test cases Test-Function -Class ClassName -# ^ - storage.type +# ^^^^^ - storage.type New-Object -TypeName System.Diagnostics.Process # ^^^^^^^ - keyword.control New-Object -TypeName System.Data @@ -1281,7 +1324,8 @@ $ScriptBlock | Out-File $file -Force # <- punctuation.definition.variable # ^ keyword.operator.logical.pipe # ^ punctuation.definition.variable -# ^ keyword.operator +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option workflow w1 {} # <- storage.type # ^ entity.name.function @@ -1303,6 +1347,7 @@ get-thing | Out-WithYou > $null # destroy # ^ punctuation.definition.variable # ^ constant.language # ^ punctuation.definition.comment +# ^^^^^^^^^ comment.line "Escaped chars: `", `n, `$, `b, `t, `e, `u{10ffff}, `"" #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double # ^^ constant.character.escape From 07acf9124db61dc82b0c0c2b95cc6486179b0743 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:32 -0500 Subject: [PATCH 06/23] Replace silly non-cap groups with `\w`. Further tweak numbers --- PowerShell.sublime-syntax | 57 +++++++++++++++++--------------- Tests/syntax_test_PowerShell.ps1 | 17 ++++++++-- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index f4753e1..74bfa3c 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -54,7 +54,7 @@ contexts: scope: punctuation.section.group.end.powershell pop: true - include: main - - match: \b(?:[A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat)\b + - match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b scope: variable.function.powershell - match: \b(?:(?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w) scope: keyword.control.powershell @@ -67,23 +67,24 @@ contexts: - match: \b(?i:hidden|static)\b # This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. scope: storage.modifier.powershell - - match: \b((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b + - match: \b((?i:class)|%|\?)(?:\s)+([\w-]+)\b captures: 1: storage.type.class.powershell 2: meta.class.powershell entity.name.class.powershell + # Operators... - match: \B(-)(?i:as)\b scope: keyword.operator.cast.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te]))(?!\p{L}) + - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te]))\b scope: keyword.operator.comparison.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in))(?!\p{L}) + - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in))\b scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:join|split|replace)(?!\p{L})|! + - match: \B(-)(?i:join|split|replace)\b scope: keyword.operator.string.powershell captures: 1: punctuation.definition.keyword.powershell @@ -91,22 +92,24 @@ contexts: scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:and|or|not|xor)(?!\p{L})|! + - match: \B(-)(?i:and|or|not|xor)\b|! scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr])(?!\p{L}) + - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr])\b scope: keyword.operator.bitwise.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:f)(?!\p{L}) + - match: \B(-)(?i:f)\b scope: keyword.operator.string-format.powershell captures: 1: punctuation.definition.keyword.powershell + # Flags/Options/Parameters - match: \B([-/])[\p{L}](?:[\w-]*\w)? scope: variable.parameter.option.powershell captures: 1: punctuation.definition.parameter.powershell + # operators continue... - match: '[+/*%-]?=' scope: keyword.operator.assignment.powershell - match: (?:\+\+|--)(?![ \t]*\d) @@ -117,14 +120,14 @@ contexts: scope: keyword.operator.arithmetic.powershell - match: \|\||&& scope: keyword.operator.logical.powershell + - match: \| + scope: keyword.operator.logical.pipe.powershell - match: ; scope: punctuation.terminator.statement.powershell - match: \` scope: punctuation.separator.continuation.line.powershell - match: ',' scope: punctuation.separator.sequence.powershell - - match: \| - scope: keyword.operator.logical.pipe.powershell - match: '&|\B\.(?= )' scope: keyword.operator.other.powershell - match: \.\.(?=\-?\d|\(|\$) @@ -213,7 +216,7 @@ contexts: pop: true commands: - - 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 + - match: (?:[\w\\:-]*\\)?\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 # "Verb-Noun pattern:" scope: support.function.powershell - match: \b(?i:(?:foreach|where|sort|tee)-object)\b @@ -391,16 +394,17 @@ contexts: 4: keyword.other.unit.powershell - match: |- (?x: - \b( - {{dec_digits}} + ( + \b{{dec_digits}} (?: (?: - (?:(\.(?!\.)){{dec_digits}}?){{dec_exponent}}? + (?:(\.(?!\.))\d*){{dec_exponent}}? # No `_` after the `.` |{{dec_exponent}} ) ({{float_suffix}})? |({{float_suffix}}) ) + |(\.)\d+ ) ({{bytes_unit}})? )\b @@ -409,7 +413,8 @@ contexts: 2: punctuation.separator.decimal.powershell 3: storage.type.numeric.powershell 4: storage.type.numeric.powershell - 5: keyword.other.unit.powershell + 5: punctuation.separator.decimal.powershell + 6: keyword.other.unit.powershell - match: \b((?:0|[1-9]{{dec_digits}}?)({{integer_suffix}})?)({{bytes_unit}})?\b captures: 1: constant.numeric.integer.decimal.powershell @@ -433,7 +438,7 @@ contexts: - match: \] scope: punctuation.section.bracket.end.powershell pop: true - - match: (?!\d+|\.)(?:\p{L}|\p{N}|\.)+ + - match: (?!\d+|\.)[\p{L}\p{N}.]+ scope: storage.type.powershell - include: main @@ -442,7 +447,7 @@ contexts: scope: constant.language.powershell captures: 1: punctuation.definition.variable.powershell - - match: ((\$)(?i:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b + - match: ((\$)(?i:Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.\w+)*\b)?\b captures: 1: support.constant.variable.powershell 2: punctuation.definition.variable.powershell @@ -461,25 +466,25 @@ contexts: )\b ) ) - ((?:\.(?:\p{L}|\d|_)+)*\b)? + ((?:\.\w+)*\b)? ) captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell 3: variable.other.member.powershell - - 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 + - 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))((?:\.\w+)*\b)?\b comment: Style preference variables as language variables so that they stand out. captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell 3: variable.other.member.powershell - - match: ((\$|@)(?i:(global|local|private|script|using|workflow):(?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? + - match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+))((?:\.\w+)*\b)? captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: storage.modifier.scope.powershell 4: variable.other.member.powershell - - match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? + - match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))((?:\.\w+)*\b)? captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell @@ -487,13 +492,13 @@ contexts: 4: storage.modifier.scope.powershell 6: punctuation.section.braces.end.powershell 7: variable.other.member.powershell - - match: ((?i:(\$|@)((?:\p{L}|\d|_)+:)?(?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? + - match: ((?i:(\$|@)(\w+:)?\w+))((?:\.\w+)*\b)? captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: support.variable.drive.powershell 4: variable.other.member.powershell - - match: ((?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})))((?:\.(?:\p{L}|\d|_)+)*\b)? + - match: ((?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})))((?:\.\w+)*\b)? captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell @@ -530,7 +535,7 @@ contexts: scope: variable.language.powershell captures: 1: punctuation.definition.variable.powershell - - match: (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+)) + - match: (?i:(\$|@)(global|local|private|script|using|workflow):(\w+)) captures: 1: punctuation.definition.variable.powershell 2: storage.modifier.scope.powershell @@ -543,12 +548,12 @@ contexts: 3: variable.other.readwrite.powershell 4: keyword.other.powershell 5: entity.name.function.invocation.powershell - - match: (?i:(\$)((?:\p{L}|\d|_)+:)?(?:\p{L}|\d|_)+) + - match: (?i:(\$)(\w+:)?\w+) scope: variable.other.readwrite.powershell captures: 1: punctuation.definition.variable.powershell 2: support.variable.drive.powershell - - match: (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) + - match: (?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})) captures: 1: punctuation.definition.variable.powershell 2: punctuation.section.braces.begin diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index 5a6d4d5..3b85608 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -448,6 +448,9 @@ There is no @platting here! # ^^^ constant.numeric.float 1.lGB # ^^^ constant.numeric.integer +# ^^ keyword.other.unit + 1.dGB +# ^^^ constant.numeric.float # ^^ keyword.other.unit 1.e+12d # ^^^^^^^ constant.numeric.float @@ -510,11 +513,13 @@ There is no @platting here! # ^^ keyword.operator.range # ^ constant.numeric.integer -2..$null +# ^ keyword.operator.unary # ^ constant.numeric.integer # ^^ keyword.operator.range # ^^^^^ constant.language # ^ punctuation.definition.variable -3..3 +# ^ keyword.operator.unary # ^ constant.numeric.integer # ^ constant.numeric.integer # ^^ keyword.operator.range @@ -524,15 +529,20 @@ There is no @platting here! # ^^ keyword.operator.range 6,10,-3 # ^ constant.numeric.integer -# ^^ constant.numeric.integer -# ^ constant.numeric.integer # ^ punctuation.separator.sequence -constant +# ^^ constant.numeric.integer # ^ punctuation.separator.sequence -constant +# ^ constant.numeric.integer 0x476 +# ^^ punctuation.definition.numeric.base # ^^^^^ constant.numeric.integer.hexadecimal +0x20 +# ^ keyword.operator.unary +# ^^ punctuation.definition.numeric.base # ^^^^ constant.numeric.integer.hexadecimal -0x20 +# ^ keyword.operator.unary +# ^^ punctuation.definition.numeric.base # ^^^^ constant.numeric.integer.hexadecimal # Types @@ -668,7 +678,8 @@ ls *.ps1 -recurse # ^^^^^^^^ variable.function something.cmd #^^^^^^^^^^^^ variable.function -øyvind.com # this should also highlight - TODO + øyvind.com +#^^^^^^^^^^ variable.function # switch switch ("fourteen") {} From 9571835c2d703d77833fee69a0e23def2c92f934 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:33 -0500 Subject: [PATCH 07/23] New Regex-Eng compatible. Most of the tests pass. --- PowerShell.sublime-syntax | 105 +++++++++++++++++++++---------- Tests/syntax_test_PowerShell.ps1 | 6 +- 2 files changed, 75 insertions(+), 36 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 74bfa3c..545db73 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -12,8 +12,8 @@ file_extensions: variables: dec_digits: (?:[\d_]*\d) dec_exponent: (?:[eE][-+]?{{dec_digits}}) - float_suffix: '(?i:[fdm])' - integer_suffix: '(?i:ul?|lu?)' + float_suffix: (?i:[fdm]) + integer_suffix: (?i:ul?|lu?) bytes_unit: (?i:[kmgtp]b) contexts: @@ -155,7 +155,8 @@ contexts: # scope: invalid.illegal.powershell requires-directive: - - match: (?<=#)(?i:requires)\s + # TODO: add back `(?<=#)`-equivalent match + - match: (?i:requires)\s scope: keyword.control.requires.powershell push: - meta_scope: meta.requires.powershell @@ -253,14 +254,11 @@ contexts: 3: markup.underline.link.powershell comment-line: - - match: (? Date: Sat, 1 Feb 2020 16:15:36 -0500 Subject: [PATCH 08/23] Rebuild `#Requires` --- PowerShell.sublime-syntax | 22 ++++--- Tests/syntax_test_PowerShell.ps1 | 107 ++++++++++++++++--------------- 2 files changed, 66 insertions(+), 63 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 545db73..a2d68ce 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -156,19 +156,21 @@ contexts: requires-directive: # TODO: add back `(?<=#)`-equivalent match - - match: (?i:requires)\s - scope: keyword.control.requires.powershell + - match: (#)((?i:requires))\s + captures: + 1: punctuation.definition.keyword.powershell + 2: keyword.control.import.require.powershell push: - meta_scope: meta.requires.powershell - - match: $ + - match: \n|$ pop: true - include: hashtable - - match: \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) - scope: keyword.other.powershell - - match: '-' - # Intentional no-scope match to skip leading `-`s below - - match: \b\p{L}+|\d+(?:\.\d+)* - scope: variable.parameter.powershell + - match: (-)(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) + scope: variable.parameter.option.powershell + captures: + 1: punctuation.definition.variable.powershell + - match: ',' + scope: punctuation.separator.powershell using-directive: - match: \b(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+)) @@ -254,6 +256,7 @@ contexts: 3: markup.underline.link.powershell comment-line: + - include: requires-directive - match: '#' scope: punctuation.definition.comment.powershell push: @@ -261,7 +264,6 @@ contexts: - match: \n|$ pop: true - include: comment-embedded-docs - - include: requires-directive strings: - include: double-quoted-string diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index a8be199..d272f09 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -4,70 +4,71 @@ using namespace System.Management.Automation # ^ keyword.other # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter #Requires -PSSnapin DiskSnapin -Version 1.2 -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter -# ^^^^^^^^ meta.requires keyword.other -# ^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter +# ^^^^^^^^ variable.parameter #Requires -PSSnapin DiskSnapin -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter #Requires -Version 3 -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter #Requires -Version 3.0 -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter #Requires -Version 3 -RunAsAdministrator -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^ meta.requires variable.parameter -# ^^^^^^^^^^^^^^^^^^^ meta.requires keyword.other +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^^^^^^^^^^^^^^^^^^^ variable.parameter #Requires -RunAsAdministrator -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^^^^^^^^^^^^ meta.requires keyword.other +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter #Requires -Modules PSWorkflow -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter #Requires -Modules PSWorkflow -ThisIsInvalid -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter -# ^^^^^^^^^^^^^^ meta.requires +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^^^^^^^^ - variable.parameter #Requires -Modules PSWorkflow, ActiveDirectory -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter -# ^^^^^^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator #Requires -Modules PSWorkflow,ActiveDirectory -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter -# ^^^^^^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator #Requires -ShellId MyLocalShell -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter #Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"} -# <- punctuation.definition.comment -# ^ meta.requires keyword.control.requires -# ^^^^^^^^ meta.requires keyword.other -# ^^^^^^^^^^ meta.requires variable.parameter +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator # ^^^^^^^^^^ meta.requires meta.hashtable variable.other.readwrite # ^ meta.requires meta.hashtable # ^^^^^^^^^^^^^^^^ meta.requires meta.hashtable string.quoted.double From 1aca5da943e1c43ec0698322eab8d580ee46b5f5 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:38 -0500 Subject: [PATCH 09/23] Fixup integers with MB --- PowerShell.sublime-syntax | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index a2d68ce..199d754 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -12,7 +12,7 @@ file_extensions: variables: dec_digits: (?:[\d_]*\d) dec_exponent: (?:[eE][-+]?{{dec_digits}}) - float_suffix: (?i:[fdm]) + float_suffix: (?i:[fdm](?!b)) integer_suffix: (?i:ul?|lu?) bytes_unit: (?i:[kmgtp]b) @@ -496,7 +496,6 @@ contexts: ) ((?:\.\w+)*\b)?\b ) - comment: Style preference variables as language variables so that they stand out. captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell From d83caa62600cf7f311f03dacb1a9a5c7df44b3b4 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:40 -0500 Subject: [PATCH 10/23] Tinker with support files --- CONTRIBUTING.md | 19 +++++++++++-------- PowerShell.sublime-project | 11 ++--------- PowerShell.sublime-syntax | 5 +++++ README.md | 5 ++--- Snippets/Powershell.sublime-completions | 16 ++++++++-------- Support/PowerShell.sublime-settings | 6 ++++-- Tests/syntax_test_PowerShell.ps1 | 1 + 7 files changed, 33 insertions(+), 30 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e742607..1660549 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Contributing -Thanks for taking an insterest in contributing to the PowerShell package for +Thanks for taking an interest in contributing to the PowerShell package for Sublime Text 3! @@ -17,15 +17,17 @@ To build development versions, first you need a configuration file in This file must contain the following information: - { - "pathToSublimeText": "...\sublime_text.exe", - "pathToSublimeTextData": "...\ - } +``` json +{ + "pathToSublimeText": "...\\sublime_text.exe", + "pathToSublimeTextData": "...\\" +} +``` #### Using Sublime Text -1. Press Ctrl+Shift+B to open the build systems menu. +1. Press Ctrl+Shift+B to open the build systems menu. 2. Select 'PowerShell: Build Dev Version' @@ -33,8 +35,9 @@ This file must contain the following information: From the project's root: - .\bin\BuildFolder.ps1 -verbose - +``` pwsh +.\bin\BuildFolder.ps1 -verbose +``` #### Running Tests diff --git a/PowerShell.sublime-project b/PowerShell.sublime-project index a56dd4b..9d0052b 100644 --- a/PowerShell.sublime-project +++ b/PowerShell.sublime-project @@ -3,14 +3,7 @@ [ { "follow_symlinks": true, - "path": "." - } + "path": ".", + }, ], - - "build_systems": [ - { - "name": "PowerShell: Build Dev Version", - "shell_cmd": "powershell.exe -noninteractive -file $project_path/bin/BuildFolder.ps1" - } - ] } diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 199d754..5551c1c 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -9,6 +9,11 @@ file_extensions: - psm1 - psd1 +first_line_match: | + (?x) + ^\#!.*\b(?:pwsh|powershell)\b + | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*- + variables: dec_digits: (?:[\d_]*\d) dec_exponent: (?:[eE][-+]?{{dec_digits}}) diff --git a/README.md b/README.md index fbc18b5..c35ed0a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Adds support for the MS PowerShell programming language. 1. Install [package control][package_control] for Sublime Text. 1. Install the **PowerShell** package: - 1. Press Ctrl + Shift + P (Cmd + Shift + P on Mac) + 1. Press Ctrl+Shift+P (Cmd+Shift+P on Mac) 1. Select 'Install Package' 1. Select 'PowerShell' @@ -20,8 +20,7 @@ You want to contribute? Awesome! Take a look at [CONTRIBUTING.md](CONTRIBUTING.m ### EditorSyntax -Syntax highlighting is provided by the project [EditorSyntax][]. -Issues about the grammar should be opened in **EditorSyntax** instead of this repo. +Syntax highlighting is adapted from the [EditorSyntax][] project. [package_control]: https://sublime.wbond.net/installation [EditorSyntax]: https://github.com/PowerShell/EditorSyntax diff --git a/Snippets/Powershell.sublime-completions b/Snippets/Powershell.sublime-completions index 2776a2f..b3d9dd8 100644 --- a/Snippets/Powershell.sublime-completions +++ b/Snippets/Powershell.sublime-completions @@ -2,16 +2,16 @@ "scope": "source.powershell", "completions": [ - { "trigger": "dict", "contents": "@{$1$0}" }, - { "trigger": "arr", "contents": "@($0)" }, - { "trigger": "req", "contents": "#requires -$0" }, - { "trigger": "reqp", "contents": "#requires -pssnapin $0" }, - { "trigger": "reqv", "contents": "#requires -version ${0:2}" }, + { "trigger": "dict\thashtable", "contents": "@{$1$0}" }, + { "trigger": "arr\tarray", "contents": "@($0)" }, + { "trigger": "req\trequires", "contents": "#requires -$0" }, + { "trigger": "reqp\trequires", "contents": "#requires -pssnapin $0" }, + { "trigger": "reqv\trequires", "contents": "#requires -version ${0:2}" }, { "trigger": "void", "contents": "[void] ($1)$0" }, { "trigger": "sb", "contents": "\\${$1}$0" }, - { "trigger": "wd", "contents": "write-debug -message \"$1\"$0" }, - { "trigger": "wh", "contents": "write-host \"$1\"" }, - { "trigger": "ww", "contents": "write-warning $0" }, + { "trigger": "wd\twrite-debug", "contents": "write-debug -message \"$1\"$0" }, + { "trigger": "wh\twrite-host", "contents": "write-host \"$1\"" }, + { "trigger": "ww\twrite-warning", "contents": "write-warning $0" }, { "trigger": "param", "contents": "param(\\$${1:paramName})" } ] } diff --git a/Support/PowerShell.sublime-settings b/Support/PowerShell.sublime-settings index f0ce3a5..77a3a3b 100644 --- a/Support/PowerShell.sublime-settings +++ b/Support/PowerShell.sublime-settings @@ -1,4 +1,6 @@ { "word_wrap": false, - "translate_tabs_to_spaces": true -} \ No newline at end of file + "translate_tabs_to_spaces": true, + // Skip `-` in word separators + "word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}`~?", +} diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index d272f09..6b983c2 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -618,6 +618,7 @@ Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose # ^^^ variable.parameter.option Invoke-Something (1..20 | Invoke-Something) -p2 'value' # <- support.function +# ^^ keyword.operator.range Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch # <- support.function # ^ punctuation.definition.parameter From 43a437b7e8308ca3b1e14f2f4bbc42d61de94deb Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 1 Feb 2020 16:15:45 -0500 Subject: [PATCH 11/23] Escape characters are valid without string quoting --- PowerShell.sublime-syntax | 14 +++++++------- Tests/syntax_test_PowerShell.ps1 | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 5551c1c..1735d03 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -36,7 +36,7 @@ contexts: - include: hashtable - include: strings - include: script-block - # - include: double-quoted-string-escapes + - include: escape-characters - include: numeric-constant - match: (@)(\() captures: @@ -204,7 +204,7 @@ contexts: - include: variable-no-property - include: hashtable - include: script-block - - include: double-quoted-string-escapes + - include: escape-characters - include: double-quoted-string - include: type - include: numeric-constant @@ -281,7 +281,7 @@ contexts: scope: punctuation.definition.string.end.powershell pop: true - include: variable-no-property - - include: double-quoted-string-escapes + - include: escape-characters - include: interpolation - match: \@'(?=$) scope: punctuation.definition.string.begin.powershell @@ -309,7 +309,9 @@ contexts: scope: punctuation.definition.string.begin.powershell push: - meta_scope: string.quoted.double.powershell - - include: double-quoted-string-escapes + - match: '""' + scope: constant.character.escape.powershell + - include: escape-characters - match: '"' scope: punctuation.definition.string.end.powershell pop: true @@ -320,13 +322,11 @@ contexts: - match: '`\s*$' scope: keyword.other.powershell - double-quoted-string-escapes: + escape-characters: - match: '`[0abenfrvt"''$`]' scope: constant.character.escape.powershell - match: '`u\{\h+\}' scope: constant.character.escape.powershell - - match: '""' - scope: constant.character.escape.powershell function: - match: ^(?:\s*)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index 6b983c2..b4355cc 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -428,8 +428,7 @@ $This is a 'double quoted' #^^^^ variable.language Isn't it "nice"?? There is no @platting here! -# ^ - punctuation.definition.variable -# ^ - variable.other.readwrite +# ^^^^^^^^^ - variable - punctuation "@ # <- string.quoted.double.heredoc # <- string.quoted.double.heredoc @@ -1306,6 +1305,10 @@ New-Object -TypeName System.Diagnostics.Process # ^^^^^^^ - keyword.control New-Object -TypeName System.Data # ^^^^ - keyword.control +echo `"test`" +# ^^^^^^^^^ - string.quoted +# ^^ constant.character.escape +# ^^ constant.character.escape @("any","array","has").foreach({ $_ }) # <- keyword.other.array.begin # ^ meta.group.array-expression From 1cddc0b631ce516fc8b6a7306fe7d2ec84d61ff1 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Tue, 4 Feb 2020 15:44:23 -0500 Subject: [PATCH 12/23] Break keyword.control into semantic scopes. Use kebab_break. Readability --- PowerShell.sublime-syntax | 174 ++++++++++++++++++++++++------- Tests/syntax_test_Function.ps1 | 16 +-- Tests/syntax_test_PowerShell.ps1 | 77 +++++++------- 3 files changed, 184 insertions(+), 83 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 1735d03..996a474 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -20,9 +20,18 @@ variables: float_suffix: (?i:[fdm](?!b)) integer_suffix: (?i:ul?|lu?) bytes_unit: (?i:[kmgtp]b) + kebab_break: (?![\w-]) contexts: + pop-before-newline: + - match: (?=\n|$) + pop: true + + pop-at-newline: + - match: \n|$ + pop: true + main: - include: comments - include: redirection @@ -61,67 +70,120 @@ contexts: - include: main - match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b scope: variable.function.powershell - - match: \b(?:(?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w) + # Exceptions + - match: \b(?i:throw){{kebab_break}} + scope: keyword.control.exception.raise.powershell + - match: \b(?i:try){{kebab_break}} + scope: keyword.control.exception.try.powershell + - match: \b(?i:catch|trap){{kebab_break}} + scope: keyword.control.exception.catch.powershell + - match: \b(?i:finally){{kebab_break}} + scope: keyword.control.exception.finally.powershell + # Conditionals + - match: \b(?i:if){{kebab_break}} + scope: keyword.control.conditional.if.powershell + - match: \b(?i:elseif){{kebab_break}} + scope: keyword.control.conditional.elseif.powershell + - match: \b(?i:else){{kebab_break}} + scope: keyword.control.conditional.else.powershell + - match: \b(?i:switch){{kebab_break}} + scope: keyword.control.conditional.switch.powershell + - match: \? + scope: keyword.control.conditional.select.powershell + - match: \b(?i:where(?!-object)){{kebab_break}} + scope: keyword.control.conditional.select.powershell + # Begin/End + - match: \b(?i:begin){{kebab_break}} + scope: keyword.context.block.begin.powershell + - match: \b(?i:end){{kebab_break}} + scope: keyword.context.block.end.powershell + # Loops + - match: \b(?i:for|foreach(?!-object)){{kebab_break}} + scope: keyword.control.loop.for.powershell + - match: \b(?i:do){{kebab_break}} + scope: keyword.control.loop.do-while.powershell + - match: \b(?i:while){{kebab_break}} + scope: keyword.control.loop.while.powershell + - match: \b(?i:until){{kebab_break}} + scope: keyword.control.loop.repeat-until.powershell + # Flow + - match: \b(?i:break){{kebab_break}} + scope: keyword.control.flow.break.powershell + - match: \b(?i:continue){{kebab_break}} + scope: keyword.control.flow.continue.powershell + - match: \b(?i:exit){{kebab_break}} + scope: keyword.control.flow.exit.powershell + - match: \b(?i:return){{kebab_break}} + scope: keyword.control.flow.return.powershell + # Declaration + - match: \b(?i:var){{kebab_break}} + # scope: storage.type.variable.powershell + scope: keyword.declaration.variable.powershell + - match: \b(?i:(?:dynamic)?param){{kebab_break}} + scope: keyword.declaration.parameter.powershell # This scope is not standard + # Uncategorized keywords + - match: \b(?i:data|default|define|from|in|inlinescript|parallel|process){{kebab_break}} scope: keyword.control.powershell - match: \B--%\B scope: keyword.control.powershell push: - meta_content_scope: string.unquoted.powershell - - match: (?=\n|$) - pop: true + - include: pop-before-newline - match: \b(?i:hidden|static)\b # This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. scope: storage.modifier.powershell - - match: \b((?i:class)|%|\?)(?:\s)+([\w-]+)\b + - match: \b((?i:class))\s+([\w-]+)\b captures: 1: storage.type.class.powershell 2: meta.class.powershell entity.name.class.powershell # Operators... - - match: \B(-)(?i:as)\b + - match: \B(-)(?i:as){{kebab_break}} scope: keyword.operator.cast.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te]))\b + - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te])){{kebab_break}} scope: keyword.operator.comparison.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in))\b + - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in)){{kebab_break}} scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:join|split|replace)\b + - match: \B(-)(?i:join|split|replace){{kebab_break}} scope: keyword.operator.string.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:is(?:not)?)\b + - match: \B(-)(?i:is(?:not)?){{kebab_break}} scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:and|or|not|xor)\b|! + - match: \B(-)(?i:and|or|not|xor){{kebab_break}}|! # <-- note `!` scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr])\b + - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr]){{kebab_break}} scope: keyword.operator.bitwise.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:f)\b + - match: \B(-)(?i:f){{kebab_break}} scope: keyword.operator.string-format.powershell captures: 1: punctuation.definition.keyword.powershell # Flags/Options/Parameters - - match: \B([-/])[\p{L}](?:[\w-]*\w)? + - match: \B([-/])\p{L}(?:[\w-]*\w)? scope: variable.parameter.option.powershell captures: 1: punctuation.definition.parameter.powershell - # operators continue... + # Operators continue... - match: '[+/*%-]?=' scope: keyword.operator.assignment.powershell - match: (?:\+\+|--)(?![ \t]*\d) scope: keyword.operator.assignment.powershell - - match: '[+-](?=\.?\d)' + - match: '[+-](?=\.?\d)' # This is sort of heuristic scope: keyword.operator.unary.powershell - - match: '[+/*%-]' + - match: '[+/*-]' + scope: keyword.operator.arithmetic.powershell + - match: '%(?!\s*\{)' scope: keyword.operator.arithmetic.powershell - match: \|\||&& scope: keyword.operator.logical.powershell @@ -129,7 +191,7 @@ contexts: scope: keyword.operator.logical.pipe.powershell - match: ; scope: punctuation.terminator.statement.powershell - - match: \` + - match: \`(?=\n|$) scope: punctuation.separator.continuation.line.powershell - match: ',' scope: punctuation.separator.sequence.powershell @@ -167,8 +229,7 @@ contexts: 2: keyword.control.import.require.powershell push: - meta_scope: meta.requires.powershell - - match: \n|$ - pop: true + - include: pop-at-newline - include: hashtable - match: (-)(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) scope: variable.parameter.option.powershell @@ -185,7 +246,14 @@ contexts: 3: variable.parameter.powershell attribute: - - match: (\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength)\b + - match: |- + (?xi: + (\[)\s* + (CmdletBinding|Alias|OutputType|Parameter + |Validate(?:Count|NotNull(?:OrEmpty)?|Range|Pattern|Length|Set|Script) + |Allow(?:Null|Empty(?:Collection|String)) + )\b + ) captures: 1: punctuation.section.bracket.begin.powershell 2: support.function.attribute.powershell @@ -209,7 +277,14 @@ contexts: - include: type - include: numeric-constant - include: main - - match: (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=) + - match: |- + (?xi: + \b(Mandatory|ValueFromPipeline(?:ByPropertyName)? + |ValueFromRemainingArguments|Position + |(?:Default)?ParameterSetName|SupportsShouldProcess + |PositionalBinding|HelpUri|ConfirmImpact|HelpMessage) + \s*(=) + ) captures: 1: variable.parameter.attribute.powershell 2: keyword.operator.assignment.powershell @@ -224,11 +299,28 @@ contexts: pop: true commands: - - match: (?:[\w\\:-]*\\)?\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 - # "Verb-Noun pattern:" + # "Verb-Noun pattern:" + - match: |- + (?x: + (?:[\w\\:-]*\\)? # Path stuff + \b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close # "Official" Verbs + |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 + ) + \-\w+? # Any "noun" + (?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff + ) scope: support.function.powershell + # Builtin cmdlets with reserved verbs - match: \b(?i:(?:foreach|where|sort|tee)-object)\b - # Builtin cmdlets with reserved verbs scope: support.function.powershell comment-block: @@ -242,18 +334,25 @@ contexts: - include: comment-embedded-docs comment-embedded-docs: - - match: ^\s*(\.)(?i:(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS)) + # TODO + # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help + - match: |- + (?xi: + ^\s*(\.) + (Component|Description|Example|ForwardHelpTargetName|Functionality + |Inputs|Notes|Outputs|RemoteHelpRunSpace|Role|Synopsis) + ) scope: comment.documentation.embedded.powershell captures: 1: punctuation.definition.keyword.documentation.powershell 2: keyword.other.documentation.powershell - - match: ^\s*(\.)(?i:(PARAMETER)\s+([a-z0-9-_]+)) + - match: ^\s*(\.)(?i:(Parameter)\s+([a-z0-9-_]+)) scope: comment.documentation.embedded.powershell captures: 1: punctuation.definition.keyword.documentation.powershell 2: keyword.other.documentation.param.powershell 3: variable.parameter.powershell - - match: ^\s*(\.)(?i:(FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) + - match: ^\s*(\.)(?i:(ForwardHelpTargetName|ForwardHelpCategory|ExternalHelp|Link)\s+([a-z0-9-_]+)) scope: comment.documentation.embedded.powershell captures: 1: punctuation.definition.keyword.documentation.powershell @@ -266,8 +365,7 @@ contexts: scope: punctuation.definition.comment.powershell push: - meta_scope: comment.line.powershell - - match: \n|$ - pop: true + - include: pop-at-newline - include: comment-embedded-docs strings: @@ -431,16 +529,19 @@ contexts: 3: keyword.other.unit.powershell script-block: - - match: \{ - scope: punctuation.section.braces.begin.powershell + - match: (%)?(\{) + captures: + 1: keyword.control.loop.for.powershell + 2: punctuation.section.braces.begin.powershell push: - - meta_scope: meta.scriptblock.powershell + - meta_scope: meta.block.powershell - match: \} scope: punctuation.section.braces.end.powershell pop: true - include: main type: + # TODO: push a maybe-static-members context - match: \[ scope: punctuation.section.bracket.begin.powershell push: @@ -585,14 +686,13 @@ contexts: 1: punctuation.definition.variable.powershell 2: storage.modifier.scope.powershell 3: variable.other.readwrite.powershell - 4: entity.name.function.invocation.powershell - match: (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) captures: 1: punctuation.definition.variable.powershell - 2: storage.modifier.scope.powershell - 3: variable.other.readwrite.powershell - 4: keyword.other.powershell - 5: entity.name.function.invocation.powershell + 2: punctuation.section.braces.begin + 3: storage.modifier.scope.powershell + 4: variable.other.readwrite.powershell + 5: punctuation.section.braces.end - match: (?i:(\$)(\w+:)?\w+) scope: variable.other.readwrite.powershell captures: diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 index 2b1efdb..ed71723 100644 --- a/Tests/syntax_test_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -98,7 +98,7 @@ function Verb-Noun { # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end Param - # <- keyword.control + #^^^^^ keyword.declaration.parameter ( # <- punctuation.section.group.begin # Param1 help description @@ -322,11 +322,11 @@ function Verb-Noun { # <- meta.attribute punctuation.section.bracket.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute meta.scriptblock - # ^^^^^^^^^ meta.scriptblock support.function - # ^ meta.scriptblock punctuation.definition.variable - # ^ meta.scriptblock variable.language - # ^ meta.attribute meta.scriptblock + # ^ meta.attribute meta.block + # ^^^^^^^^^ meta.block support.function + # ^ meta.block punctuation.definition.variable + # ^ meta.block variable.language + # ^ meta.attribute meta.block # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.bracket.end [string] @@ -370,7 +370,7 @@ function Verb-Noun { # <- punctuation.section.group.end Begin - # <- keyword.control + #^^^^^ keyword.context.block.begin { } Process { @@ -387,7 +387,7 @@ function Verb-Noun { } } End { - # <- keyword.control + #^^^ keyword.context.block.end } } diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index b4355cc..efa4457 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -152,6 +152,7 @@ $variable.Name #^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double # ^ punctuation.definition.variable # ^^^^^^^^ variable.other.readwrite +# ^^^^^ - variable - punctuation # ^ punctuation.definition.string.end # When used in a subexpression, both should be highlighted @@ -188,7 +189,7 @@ $variable.Name "This is a @double quoted string." # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double # ^ - punctuation.definition.variable -# ^^^^^^ - variable.other.readwrite +# ^^^^^^^ - variable # double check scopes for automatic variables in strings "$_ $$ $Pwd" @@ -688,8 +689,8 @@ switch ("fourteen") {} # ^ punctuation.section.group.begin # ^ string.quoted.double # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch -CaseSensitive ("fourteen") {} # <- keyword.control # ^ punctuation.definition.parameter @@ -697,8 +698,8 @@ switch -CaseSensitive ("fourteen") {} # ^ punctuation.section.group.begin # ^ string.quoted.double # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch -Regex ("fourteen") {} # <- keyword.control # ^ punctuation.definition.parameter @@ -706,8 +707,8 @@ switch -Regex ("fourteen") {} # ^ punctuation.section.group.begin # ^ string.quoted.double # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch -Wildcard ($a) {} # <- keyword.control # ^ punctuation.definition.parameter @@ -715,23 +716,23 @@ switch -Wildcard ($a) {} # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch -regex -file .\somefile.txt {} # <- keyword.control # ^ punctuation.definition.parameter # ^^^^^^ variable.parameter.option # ^ punctuation.definition.parameter # ^^^^ variable.parameter.option -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch (3) {} # <- keyword.control # ^ punctuation.section.group.begin # ^ constant.numeric.integer # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch (4, 2) {} # <- keyword.control # ^ punctuation.section.group.begin @@ -739,8 +740,8 @@ switch (4, 2) {} # ^ constant.numeric.integer # ^ punctuation.separator # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end switch -Regex -File $filePath { # <- keyword.control @@ -749,17 +750,17 @@ switch -Regex -File $filePath { # ^ punctuation.definition.parameter # ^^^^ variable.parameter.option # ^ punctuation.definition.variable -# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.begin '.' {} # ^^^ string.quoted.single -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end default {} # ^^^^^^^ keyword.control -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end } -# <- meta.scriptblock punctuation.section.braces.end +# <- meta.block punctuation.section.braces.end switch -Wildcard -CaseSensitive ($something) { # <- keyword.control @@ -771,34 +772,34 @@ switch -Wildcard -CaseSensitive ($something) { # ^ punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.begin '.' {} # ^^^ string.quoted.single -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end default {} # ^^^^^^^ keyword.control -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end } -# <- meta.scriptblock punctuation.section.braces.end +# <- meta.block punctuation.section.braces.end switch ('this') { # <- keyword.control # ^ punctuation.section.group.begin # ^^^^^^ string.quoted.single # ^ punctuation.section.group.end -# ^ meta.scriptblock punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.begin 'this' {} # ^^^^^^ string.quoted.single -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end default {} # ^^^^^^^ keyword.control -# ^ meta.scriptblock punctuation.section.braces.begin -# ^ meta.scriptblock punctuation.section.braces.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end } -# <- meta.scriptblock punctuation.section.braces.end +# <- meta.block punctuation.section.braces.end # Functions and filters functioN MyFunction{} @@ -897,7 +898,7 @@ function Verb-Noun # <- punctuation.section.braces.begin Param - # <- keyword.control + #^^^^^ keyword.declaration.parameter ( # <- punctuation.section.group.begin # Param1 help description @@ -1313,22 +1314,22 @@ echo `"test`" # <- keyword.other.array.begin # ^ meta.group.array-expression # ^ keyword.control -# ^ meta.scriptblock +# ^ meta.block @('any','array','has').foreach{ $_ } # <- keyword.other.array.begin # ^ meta.group.array-expression # ^ keyword.control -# ^ meta.scriptblock +# ^ meta.block @("any","array","has").where({ $_.Length -gt 3 }) # <- keyword.other.array.begin # ^ meta.group.array-expression # ^ keyword.control -# ^ meta.scriptblock +# ^ meta.block @("any","array","has").where{ $_.Length -gt 3 } # <- keyword.other.array.begin # ^ meta.group.array-expression # ^ keyword.control -# ^ meta.scriptblock +# ^ meta.block $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" # <- punctuation.definition.variable # ^ support.function From 5236ffd4bf25b0124a28e1da84b2ae5327e48fc8 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Tue, 4 Feb 2020 17:03:45 -0500 Subject: [PATCH 13/23] Push a context for membership --- PowerShell.sublime-syntax | 73 ++++++++++++++----- Tests/syntax_test_Class.ps1 | 42 +++++------ Tests/syntax_test_Function.ps1 | 119 ++++++++++++++++--------------- Tests/syntax_test_PowerShell.ps1 | 117 ++++++++++++++++++------------ 4 files changed, 210 insertions(+), 141 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 996a474..4c11b3b 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -34,6 +34,9 @@ contexts: main: - include: comments + - include: expressions + + expressions: - include: redirection - include: commands - include: variable @@ -255,12 +258,12 @@ contexts: )\b ) captures: - 1: punctuation.section.bracket.begin.powershell + 1: punctuation.section.brackets.begin.powershell 2: support.function.attribute.powershell push: - meta_scope: meta.attribute.powershell - match: \] - scope: punctuation.section.bracket.end.powershell + scope: punctuation.section.brackets.end.powershell pop: true - match: \( scope: punctuation.section.group.begin.powershell @@ -368,6 +371,41 @@ contexts: - include: pop-at-newline - include: comment-embedded-docs + static-members: + # - meta_content_scope: debug.in.static-members + - match: '::' + scope: punctuation.accessor.double-colon.powershell + set: members + + members: + # - meta_content_scope: debug.in.members + - match: (?=\.\.) + pop: true + - match: \.(?=\w) + scope: punctuation.accessor.dot.powershell + - match: (\w+)(\() + captures: + 1: meta.function-call.powershell variable.function.powershell + 2: meta.function-call.arguments.powershell punctuation.section.arguments.begin.powershell + push: + - meta_content_scope: meta.function-call.arguments.powershell + - match: \) + scope: meta.function-call.arguments.powershell punctuation.section.arguments.end.powershell + pop: true + - include: expressions + - match: \w+ + scope: variable.other.member.powershell + - match: \[ + scope: punctuation.section.brackets.begin.powershell + push: + - meta_scope: meta.brackets.indexer.powershell + - match: \] + scope: punctuation.section.brackets.end.powershell + pop: true + - include: expressions + - match: '' + pop: true + strings: - include: double-quoted-string - include: single-quoted-string @@ -543,10 +581,13 @@ contexts: type: # TODO: push a maybe-static-members context - match: \[ - scope: punctuation.section.bracket.begin.powershell + scope: punctuation.section.brackets.begin.powershell push: + - match: \](?=::) + scope: punctuation.section.brackets.end.powershell + set: static-members - match: \] - scope: punctuation.section.bracket.end.powershell + scope: punctuation.section.brackets.end.powershell pop: true - match: (?!\d+|\.)[\p{L}\p{N}.]+ scope: storage.type.powershell @@ -564,12 +605,11 @@ contexts: |PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable) |ShellID) ) - ((?:\.\w+)*\b)?\b ) captures: 1: support.constant.variable.powershell 2: punctuation.definition.variable.powershell - 3: variable.other.member.powershell + push: members - match: |- (?x:( (\$) @@ -581,12 +621,11 @@ contexts: |Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b ) ) - ((?:\.\w+)*\b)? ) captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell - 3: variable.other.member.powershell + push: members - match: |- (?x:( (\$) @@ -600,40 +639,40 @@ contexts: |SessionConfigurationName|SessionOption) |ErrorView|FormatEnumerationLimit|OFS|OutputEncoding) ) - ((?:\.\w+)*\b)?\b ) captures: 1: variable.language.powershell 2: punctuation.definition.variable.powershell - 3: variable.other.member.powershell - - match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+))((?:\.\w+)*\b)? + push: members + - match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+)) captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: storage.modifier.scope.powershell - 4: variable.other.member.powershell - - match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\}))((?:\.\w+)*\b)? + push: members + - match: ((\$)(\{)((?i:global|local|private|script|using|workflow)):([^}]*[^}`])(\})) captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: punctuation.section.braces.begin.powershell 4: storage.modifier.scope.powershell 6: punctuation.section.braces.end.powershell - 7: variable.other.member.powershell - - match: ((?i:(\$|@)(\w+:)?\w+))((?:\.\w+)*\b)? + push: members + - match: ((?i:(\$|@)(\w+:)?\w+)) captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: support.variable.drive.powershell 4: variable.other.member.powershell - - match: ((?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})))((?:\.\w+)*\b)? + push: members + - match: ((?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\}))) captures: 1: variable.other.readwrite.powershell 2: punctuation.definition.variable.powershell 3: punctuation.section.braces.begin.powershell 4: support.variable.drive.powershell 6: punctuation.section.braces.end.powershell - 7: variable.other.member.powershell + push: members variable-no-property: - match: (\$)(?i:True|False|Null)\b diff --git a/Tests/syntax_test_Class.ps1 b/Tests/syntax_test_Class.ps1 index 74df9f1..7b015b2 100644 --- a/Tests/syntax_test_Class.ps1 +++ b/Tests/syntax_test_Class.ps1 @@ -14,18 +14,18 @@ class TypeName # ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line [ValidateSet("val1", "Val2")] # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^^^ string.quoted.double # ^ punctuation.separator # ^^^^^^ string.quoted.double # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [string] $P1 - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^^ variable.other.readwrite @@ -34,9 +34,9 @@ class TypeName # ^^^^^^^^^^^^^^^ comment.line static [hashtable] $P2 #^^^^^ storage.modifier - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^^^^^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^^ variable.other.readwrite @@ -45,9 +45,9 @@ class TypeName # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line hidden [int] $P3 #^^^^^ storage.modifier - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^^ variable.other.readwrite @@ -56,9 +56,9 @@ class TypeName # ^^^^^^^^^^^ comment.line TypeName ([string] $s) { # ^ punctuation.section.group.begin - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.group.end @@ -76,20 +76,22 @@ class TypeName # ^^^^^^^^^^^^^ comment.line static [void] MemberMethod1([hashtable] $h) { # <- storage.modifier - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.section.group.begin - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^^^^^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.group.end [TypeName]::P2 = $h - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end + # ^^ punctuation.accessor.double-colon + # ^^ variable.other.member # ^ keyword.operator.assignment # ^ punctuation.definition.variable # ^ variable.other.readwrite @@ -99,13 +101,13 @@ class TypeName # <- punctuation.definition.comment # ^^^^^^^^^^^^^^^ comment.line [int] MemberMethod2([int] $i) { - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.section.group.begin - # ^ punctuation.section.bracket.begin + # ^ punctuation.section.brackets.begin # ^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.group.end diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 index ed71723..bbb424e 100644 --- a/Tests/syntax_test_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -56,7 +56,7 @@ function Verb-Noun { # <- meta.function storage.type # ^ meta.function entity.name.function [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute variable.parameter.attribute @@ -81,22 +81,22 @@ function Verb-Noun { # ^ meta.attribute keyword.operator.assignment # ^ meta.attribute string.quoted.single # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [Alias()] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [OutputType([String])] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute punctuation.section.bracket.begin + # ^ meta.attribute punctuation.section.brackets.begin # ^^^^^^ meta.attribute storage.type - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end Param #^^^^^ keyword.declaration.parameter ( @@ -106,7 +106,7 @@ function Verb-Noun { # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(Mandatory=$true, #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^^^^^^ variable.parameter.attribute @@ -147,42 +147,42 @@ function Verb-Noun { # ^ keyword.operator.assignment # ^^^^^^^^^^^^^^^^^ string.quoted.single # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ - meta.attribute [ValidateNotNullOrEmpty()] #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateNotNull()] #^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateNotNullOrEmpty()] #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateCount(0,5)] #^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ constant.numeric.integer # ^ punctuation.separator # ^ constant.numeric.integer # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateSet("sun", "moon", "earth")] #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^ string.quoted.double @@ -191,15 +191,15 @@ function Verb-Noun { # ^ punctuation.separator # ^^^^^^^ string.quoted.double # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [Alias("p1")] #^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^ string.quoted.double # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param1, # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -215,32 +215,32 @@ function Verb-Noun { # ^ keyword.operator.assignment # ^^^^^^^^^^^^^^^^ string.quoted.single # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ - meta.attribute [AllowNull()] #^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [AllowEmptyCollection()] #^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [AllowEmptyString()] #^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [ValidateScript({$true})] #^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ meta.attribute @@ -248,21 +248,21 @@ function Verb-Noun { # ^^^^ constant.language # ^ meta.attribute # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateRange(0,5)] #^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ constant.numeric.integer # ^ punctuation.separator # ^ constant.numeric.integer # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [int32] - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin #^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param2, # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -273,34 +273,34 @@ function Verb-Noun { # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(ParameterSetName='Another Parameter Set')] #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute # ^ meta.attribute keyword.operator.assignment # ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [ValidatePattern("[a-z]*")] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^^^^^^^^ meta.attribute string.quoted.double # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [ValidateLength(0,15)] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute constant.numeric.integer # ^ punctuation.separator # ^^ meta.attribute constant.numeric.integer # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [String] - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin #^^^^^^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param3, # <- punctuation.definition.variable #^^^^^^ variable.other.readwrite @@ -310,16 +310,16 @@ function Verb-Noun { # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(ParameterSetName='Parameter Set 1')] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute # ^ meta.attribute keyword.operator.assignment # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^ meta.attribute meta.block @@ -328,11 +328,11 @@ function Verb-Noun { # ^ meta.block variable.language # ^ meta.attribute meta.block # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [string] - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param4, # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -342,27 +342,27 @@ function Verb-Noun { # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(ParameterSetName='Parameter Set 1')] - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute # ^ meta.attribute keyword.operator.assignment # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end [ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting - # <- meta.attribute punctuation.section.bracket.begin + # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute # ^ meta.attribute punctuation.section.group.begin # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.bracket.end + # ^ meta.attribute punctuation.section.brackets.end # ^ comment.line punctuation.definition.comment # ^ comment.line [string] - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ storage.type - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param5 # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -380,9 +380,12 @@ function Verb-Noun { # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^^^^^^^^ variable.language - # ^^^^^^^^^^^^^ variable.other.member - # ^ punctuation.section.group.begin - # ^ punctuation.section.group.end + # ^^^^^^^^^^^^^ variable.function + # ^ punctuation.section.arguments.begin + # ^^^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^^^^^^ string.quoted.double + # ^ punctuation.section.arguments.end # ^ punctuation.section.group.end } } diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index efa4457..c5c29a4 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -143,9 +143,22 @@ ${script:variable} $variable.Name # <- variable.other.readwrite punctuation.definition.variable #^^^^^^^^ variable.other.readwrite +# ^ punctuation.accessor.dot # ^^^^^ - variable.other.readwrite # ^^^^ variable.other.member +# Variable properties should be highlighted +$variable.Name.Method( ) +# <- variable.other.readwrite punctuation.definition.variable +#^^^^^^^^ variable.other.readwrite +# ^ punctuation.accessor.dot +# ^^^^ variable.other.member +# ^ punctuation.accessor.dot +# ^^^^^^ meta.function-call variable.function +# ^^^ meta.function-call.arguments +# ^^^^^^^^^^^^^^^ - variable.other.readwrite +# ^ - meta.function-call + # In double-quoted strings, only the variable should be highlighted, not the property "This is my $variable.Name!" # <- punctuation.definition.string.begin @@ -163,6 +176,7 @@ $variable.Name # ^ punctuation.section.group.begin # ^ punctuation.section.group.end # ^^^^^^^^ variable.other.readwrite +# ^ punctuation.accessor.dot # ^^^^ variable.other.member # ^ punctuation.definition.string.end @@ -319,23 +333,26 @@ $a3 = $one, $two, $three, $four $a1[0] # <- variable.other.readwrite punctuation.definition.variable # ^ variable.other.readwrite -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.begin # ^ constant.numeric.integer -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end +# ^^^ meta.brackets.indexer $a2[-1] # <- variable.other.readwrite punctuation.definition.variable # ^ variable.other.readwrite -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.begin # ^ constant.numeric.integer -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end +# ^^^^ meta.brackets.indexer $a3[1..2] # <- variable.other.readwrite punctuation.definition.variable # ^ variable.other.readwrite -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.begin # ^ constant.numeric.integer # ^^ keyword.operator.range # ^ constant.numeric.integer -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end +# ^^^^^^ meta.brackets.indexer @(@($a)) # ^ keyword.other.array.begin # ^ punctuation.section.group.begin @@ -369,7 +386,7 @@ $a3[1..2] $i[($y - 1) + $x] # ^ variable.other.readwrite punctuation.definition.variable # ^^ variable.other.readwrite -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.begin # ^ punctuation.section.group.begin # ^ variable.other.readwrite punctuation.definition.variable # ^^ variable.other.readwrite @@ -379,7 +396,8 @@ $a3[1..2] # ^ keyword.operator.arithmetic # ^ variable.other.readwrite punctuation.definition.variable # ^^ variable.other.readwrite -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end +# ^^^^^^^^^^^^^^^ meta.brackets.indexer # Single quoted strings 'This is a single quoted string.' @@ -548,44 +566,49 @@ There is no @platting here! # Types [string] -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^ storage.type -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end [string[]] -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^ storage.type -# ^ punctuation.section.bracket.begin -# ^^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.begin +# ^^ punctuation.section.brackets.end [int32] -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^^^^ storage.type -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end [System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.type -# ^^ punctuation.section.bracket.begin +# ^^ punctuation.section.brackets.begin # ^^^^^^^^^^^^^ storage.type # ^^^^^^^^ storage.type -# ^ punctuation.section.bracket.end -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.end +# ^ punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^ storage.type -# ^^^ punctuation.section.bracket.end +# ^^^ punctuation.section.brackets.end [System.Array+SZArrayEnumerator] -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^^^^^^^^^^^ storage.type # ^^^^^^^^^^^^^^^^^ storage.type # ^ keyword.operator -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end [int]::MinValue -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^ storage.type -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end +# ^^ punctuation.accessor.double-colon +# ^^^^^^^^ variable.other.member [System.DateTime]::Parse('2016/09/21') -# <- punctuation.section.bracket.begin +# <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^ storage.type -# ^ punctuation.section.bracket.end -# ^ punctuation.section.group.begin -# ^ punctuation.section.group.end +# ^ punctuation.section.brackets.end +# ^^ punctuation.accessor.double-colon +# ^^^^^ meta.function-call variable.function +# ^^^^^^^^^^^^^^ meta.function-call.arguments +# ^ punctuation.section.arguments.begin +# ^ punctuation.section.arguments.end # Commands (functions) Invoke-Something -foobar @@ -875,9 +898,9 @@ function Test-Drive([string]$roman) { # <- storage.type # ^^^^^^^^^^ entity.name.function # ^ punctuation.section.group.begin -# ^ punctuation.section.bracket.begin +# ^ punctuation.section.brackets.begin # ^^^^^^ storage.type -# ^ punctuation.section.bracket.end +# ^ punctuation.section.brackets.end # ^ punctuation.definition.variable # ^ variable.other.readwrite # ^ punctuation.section.group.end @@ -906,7 +929,7 @@ function Verb-Noun # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line [Parameter(Mandatory=$true, #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^^^^^^ variable.parameter.attribute @@ -951,42 +974,42 @@ function Verb-Noun # ^ keyword.operator.assignment # ^^^^^^^^^^^^^^^^^ string.quoted.single # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end # ^ - meta.attribute [ValidateNotNullOrEmpty()] #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateNotNull()] #^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateNotNullOrEmpty()] #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateCount(0,5)] #^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^^^^^^^^^^^^ support.function.attribute # ^ punctuation.section.group.begin # ^ constant.numeric.integer # ^ punctuation.separator # ^ constant.numeric.integer # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [ValidateSet("sun", "moon", "earth")] #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^ string.quoted.double @@ -995,15 +1018,15 @@ function Verb-Noun # ^ punctuation.separator # ^^^^^^^ string.quoted.double # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end [Alias("p1")] #^^^^^^^^^^^^ meta.attribute - # <- punctuation.section.bracket.begin + # <- punctuation.section.brackets.begin # ^ support.function.attribute # ^ punctuation.section.group.begin # ^^^^ string.quoted.double # ^ punctuation.section.group.end - # ^ punctuation.section.bracket.end + # ^ punctuation.section.brackets.end $Param1 # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -1383,8 +1406,10 @@ get-thing | Out-WithYou > $null # destroy # ^ keyword.operator.logical.pipe # ^ meta.group.complex.subexpression punctuation.section.group.begin # ^^^^^^ storage.type -# ^ meta.group.complex.subexpression punctuation.section.group.begin -# ^ meta.group.complex.subexpression punctuation.section.group.end +# ^^ punctuation.accessor.double-colon +# ^^^^^^ meta.function-call variable.function +# ^ meta.group.complex.subexpression punctuation.section.arguments.begin +# ^ meta.group.complex.subexpression punctuation.section.arguments.end # ^ meta.group.complex.subexpression punctuation.section.group.end # ^ punctuation.definition.variable "This is the DebugPreference variable: $DebugPreference" From 300ebcf0fddf02340d48187f4fd36093e8454b03 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sat, 10 Apr 2021 11:49:25 -0400 Subject: [PATCH 14/23] Multiline regex formatting --- PowerShell.sublime-syntax | 184 ++++++++++++++++++------------- Tests/syntax_test_PowerShell.ps1 | 2 +- 2 files changed, 108 insertions(+), 78 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 4c11b3b..77c3a1f 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -10,9 +10,10 @@ file_extensions: - psd1 first_line_match: | - (?x) + (?x: ^\#!.*\b(?:pwsh|powershell)\b | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*- + ) variables: dec_digits: (?:[\d_]*\d) @@ -252,9 +253,13 @@ contexts: - match: |- (?xi: (\[)\s* - (CmdletBinding|Alias|OutputType|Parameter - |Validate(?:Count|NotNull(?:OrEmpty)?|Range|Pattern|Length|Set|Script) - |Allow(?:Null|Empty(?:Collection|String)) + ( + CmdletBinding | Alias | OutputType | Parameter + | Validate + (?: + Count | NotNull(?:OrEmpty)? | Range | Pattern | Length | Set + | Script) + | Allow(?: Null | Empty(?: Collection | String )) )\b ) captures: @@ -282,10 +287,12 @@ contexts: - include: main - match: |- (?xi: - \b(Mandatory|ValueFromPipeline(?:ByPropertyName)? - |ValueFromRemainingArguments|Position - |(?:Default)?ParameterSetName|SupportsShouldProcess - |PositionalBinding|HelpUri|ConfirmImpact|HelpMessage) + \b( + Mandatory | ValueFromPipeline(?:ByPropertyName)? + | ValueFromRemainingArguments | Position + | (?:Default)?ParameterSetName | SupportsShouldProcess + | PositionalBinding | HelpUri | ConfirmImpact | HelpMessage + ) \s*(=) ) captures: @@ -306,17 +313,21 @@ contexts: - match: |- (?x: (?:[\w\\:-]*\\)? # Path stuff - \b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close # "Official" Verbs - |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 + \b(?i: + Add | Approve | Assert | Backup | Block | Build | Checkpoint # "Official" Verbs + | 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 ) \-\w+? # Any "noun" (?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff @@ -342,8 +353,11 @@ contexts: - match: |- (?xi: ^\s*(\.) - (Component|Description|Example|ForwardHelpTargetName|Functionality - |Inputs|Notes|Outputs|RemoteHelpRunSpace|Role|Synopsis) + ( + Component | Description | Example | ForwardHelpTargetName + | Functionality | Inputs | Notes | Outputs | RemoteHelpRunSpace + | Role | Synopsis + ) ) scope: comment.documentation.embedded.powershell captures: @@ -542,14 +556,14 @@ contexts: (?: (?: (?:(\.(?!\.))\d*) # No `_` after the `.` - {{dec_exponent}}? - |{{dec_exponent}} + {{dec_exponent}}? + | {{dec_exponent}} ) ({{float_suffix}})? - |({{float_suffix}}) + | ({{float_suffix}}) ) - |\b{{dec_digits}}\.(?!\.) - |(\.)\d+ + | \b{{dec_digits}}\.(?!\.) + | (\.)\d+ ) ({{bytes_unit}}\b)? ) @@ -599,50 +613,57 @@ contexts: captures: 1: punctuation.definition.variable.powershell - match: |- - (?x:( - (\$) - (?i:ExecutionContext|Host|Home|Is(?:CoreCLR|Linux|Windows|MacOS) - |PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable) - |ShellID) + (?xi: + (\$) + (?: + ExecutionContext | Host | Home | IsCoreCLR | IsLinux | IsWindows + | IsMacOS | PID | Profile | PsCommandPath | PsHome | PsScriptRoot + | PsUiCulture | PsVersionTable | ShellID ) ) + scope: support.constant.variable.powershell captures: - 1: support.constant.variable.powershell - 2: punctuation.definition.variable.powershell + 1: punctuation.definition.variable.powershell push: members - match: |- - (?x:( - (\$) - (?: - [$^?_] - |(?i:Args|ConsoleFileName|Error|Event|EventArgs|EventSubscriber - |ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel - |Ps(?:BoundParameters|Cmdlet|Culture|DebugContext|Item)|Pwd - |Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b - ) + (?xi: + (\$) + (?: + [$^?_] + | (?: + Args | ConsoleFileName | Error | Event | EventArgs + | EventSubscriber | ForEach | Input | LastExitCode | Matches + | MyInvocation | NestedPromptLevel | PsBoundParameters | PsCmdlet + | PsCulture | PsDebugContext | PsItem | Pwd | Sender | SourceArgs + | SourceEventArgs | StackTrace | Switch | This + )\b ) ) + scope: variable.language.powershell captures: - 1: variable.language.powershell - 2: punctuation.definition.variable.powershell + 1: punctuation.definition.variable.powershell push: members - match: |- - (?x:( + (?xi: (\$) - (?i: - (?:Confirm|Debug|ErrorAction|Information|Progress|Verbose|Warning # *Preference - |WhatIf)Preference - |Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count - |Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event - |Ps(?:DebugContext|DefaultParameterValues|EmailServer # Ps* - |ModuleAutoloadingPreference|SenderInfo|SessionApplicationName - |SessionConfigurationName|SessionOption) - |ErrorView|FormatEnumerationLimit|OFS|OutputEncoding) + (?: + (?: + Confirm | Debug | ErrorAction | Information | Progress | Verbose # *Preference + | Warning | WhatIf + ) + Preference + | Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count + | Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event + | PsDebugContext | PsDefaultParameterValues | PsEmailServer + | PsModuleAutoloadingPreference | PsSenderInfo + | PsSessionApplicationName | PsSessionConfigurationName + | PsSessionOption | ErrorView | FormatEnumerationLimit | OFS + | OutputEncoding ) ) + scope: variable.language.powershell captures: - 1: variable.language.powershell - 2: punctuation.definition.variable.powershell + 1: punctuation.definition.variable.powershell push: members - match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+)) captures: @@ -680,43 +701,52 @@ contexts: captures: 1: punctuation.definition.variable.powershell - match: |- - (?x: + (?xi: (\$) - (?i:ExecutionContext|Host|Home|Is(?:CoreCLR|Linux|Windows|MacOS) - |PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable) - |ShellID - )\b + (?: + ExecutionContext | Host | Home | IsCoreCLR | IsLinux | IsWindows + | IsMacOS | PID | Profile | PsCommandPath | PsHome | PsScriptRoot + | PsUiCulture | PsVersionTable | ShellID + ) ) scope: support.constant.variable.powershell captures: 1: punctuation.definition.variable.powershell - match: |- - (?x: + (?xi: (\$) (?: [$^?_] - |(?i:Args|ConsoleFileName|Error|Event|EventArgs|EventSubscriber - |ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel - |Ps(?:BoundParameters|Cmdlet|Culture|DebugContext|Item)|Pwd - |Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b + | (?: + Args | ConsoleFileName | Error | Event | EventArgs + | EventSubscriber | ForEach | Input | LastExitCode | Matches + | MyInvocation | NestedPromptLevel | PsBoundParameters | PsCmdlet + | PsCulture | PsDebugContext | PsItem | Pwd | Sender | SourceArgs + | SourceEventArgs | StackTrace | Switch | This + )\b ) ) scope: variable.language.powershell captures: 1: punctuation.definition.variable.powershell - match: |- - (?x: + (?xi: (\$) - (?i: - (?:Confirm|Debug|ErrorAction|Information|Progress|Verbose|Warning # *Preference - |WhatIf)Preference - |Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count - |Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event - |Ps(?:DebugContext|DefaultParameterValues|EmailServer # Ps* - |ModuleAutoloadingPreference|SenderInfo|SessionApplicationName - |SessionConfigurationName|SessionOption) - |ErrorView|FormatEnumerationLimit|OFS|OutputEncoding) - )\b + (?: + (?: + Confirm | Debug | ErrorAction | Information | Progress | Verbose # *Preference + | Warning | WhatIf + ) + Preference + | Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count + | Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event + | PsDebugContext | PsDefaultParameterValues | PsEmailServer + | PsModuleAutoloadingPreference | PsSenderInfo + | PsSessionApplicationName | PsSessionConfigurationName + | PsSessionOption | ErrorView | FormatEnumerationLimit | OFS + | OutputEncoding + ) + ) scope: variable.language.powershell captures: 1: punctuation.definition.variable.powershell diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index c5c29a4..b706cc0 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -199,7 +199,7 @@ $variable.Name.Method( ) # ^^^^^^^^^^^^ variable.other.readwrite # ^ punctuation.definition.string.end -# @splat references only work in argument mode, should not highlight in strings +# The @splat references only work in argument mode, should not highlight in strings "This is a @double quoted string." # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double # ^ - punctuation.definition.variable From f5b84617d0dd970e7e5f5cfe194941cc37bf7041 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Sun, 11 Apr 2021 13:40:23 -0400 Subject: [PATCH 15/23] Fix first_line_match NL chomp --- PowerShell.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 77c3a1f..97c92fe 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -9,7 +9,7 @@ file_extensions: - psm1 - psd1 -first_line_match: | +first_line_match: |- (?x: ^\#!.*\b(?:pwsh|powershell)\b | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*- From 60b2779ea8a48bdaa7b500aa51b6b7a4beb87f92 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 16 Apr 2021 19:32:06 -0400 Subject: [PATCH 16/23] License dates --- LICENSE.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index 51a8c4c..0a8767a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,5 @@ -Copyright (c) 2011 Guillermo López-Anglada +Copyright (c) 2011-2015 Guillermo López-Anglada + 2020-2021 Michael Lyons Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From 4462d171a25c58c08cc7c425cedb721d965ca8a6 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 16 Apr 2021 19:51:16 -0400 Subject: [PATCH 17/23] Convert ISE Nostalgia to sublime-color-scheme --- ISE Nostalgia.sublime-color-scheme | 151 ++++++++++++++++ ISE Nostalgia.tmTheme | 280 ----------------------------- 2 files changed, 151 insertions(+), 280 deletions(-) create mode 100644 ISE Nostalgia.sublime-color-scheme delete mode 100644 ISE Nostalgia.tmTheme diff --git a/ISE Nostalgia.sublime-color-scheme b/ISE Nostalgia.sublime-color-scheme new file mode 100644 index 0000000..c94b433 --- /dev/null +++ b/ISE Nostalgia.sublime-color-scheme @@ -0,0 +1,151 @@ +{ + "name": "ISE Nostalgia", + "author": "Guillermo L\u00f3pez-Anglada", + "variables": + { + "blue": "#87beff", + "blue2": "#add6ff", + "blue3": "#5ab1cd", + "blue4": "#585cf6", + "blue5": "#0000ff", + "blue6": "#6d79de", + "blue7":"#21439C", + "green": "#006400", + "green2": "#06960e", + "grey": "#a9a9a9", + "grey2": "#7f7f7f", + "grey3": "#292929", + "grey4": "#70727E", + "purple": "#8a2be2", + "purple2": "#801e92", + "purple3": "#aa69b6", + "red": "#6b0000", + "red2": "#ff4500", + "red3": "#b85b44", + "white": "#ffffff", + "white2": "#fef8da", + "white3": "#e3f1ff", + "yellow": "#ffff00", + }, + "globals": + { + "foreground": "var(purple)", + "background": "var(white)", + "caret": "var(grey2)", + // "invisibles": "var(grey2)", + "line_highlight": "var(white2)", + "selection": "var(blue2)", + "selection_border": "var(blue)", + "inactive_selection": "var(white3)", + "gutter_foreground": "var(blue3)", + }, + "rules": + [ + { + "name": "Comment", + "scope": "comment", + "foreground": "var(green)", + "font_style": "normal", + }, + { + "name": "Keyword", + "scope": "keyword, storage", + "foreground": "var(grey3)", + }, + { + "name": "Number", + "scope": "constant.numeric", + "foreground": "var(purple2)", + }, + { + "name": "Built-in constant", + "scope": "constant.language", + "foreground": "var(blue4)", + }, + { + "name": "Variable", + "scope": "variable.language, variable.other", + "foreground": "var(red2)", + }, + { + "name": "String", + "scope": "string", + "foreground": "var(red)", + }, + { + "name": "String interpolation", + "scope": "constant.character.escape, string source", + "foreground": "var(purple3)", + }, + // { + // "name": "Function name", + // "scope": "entity.name.function, support.function.any-method", + // "foreground": "var(blue5)", + // }, + // { + // "name": "Type name", + // "scope": "entity.name.type", + // "font_style": "underline", + // }, + // { + // "name": "Inherited class name", + // "scope": "entity.other.inherited-class", + // "font_style": "italic", + // }, + // { + // "name": "Function parameter", + // "scope": "variable.parameter", + // "font_style": "italic", + // }, + // { + // "name": "Function argument and result types", + // "scope": "storage.type.method", + // "font_style": "", + // "foreground": "var(grey4)", + // }, + // { + // "name": "Section", + // "scope": "meta.section entity.name.section, declaration.section entity.name.section", + // "font_style": "italic", + // }, + { + "name": "Library function", + "scope": "support.function", + "foreground": "var(blue5)", + }, + // { + // "name": "Library object", + // "scope": "support.class, support.type", + // "font_style": "bold", + // "foreground": "var(blue6)", + // }, + // { + // "name": "Library constant", + // "scope": "support.constant", + // "font_style": "bold", + // "foreground": "var(green2)", + // }, + // { + // "name": "Library variable", + // "scope": "support.variable", + // "font_style": "bold", + // "foreground": "var(blue7)", + // }, + { + "name": "PowerShell: Assignment Operator", + "scope": "keyword.operator.assignment.powershell", + "foreground": "var(grey)", + }, + { + "name": "Invalid", + "scope": "invalid", + "foreground": "var(yellow)", + "background": "var(red3)", + }, + { + "name": "Invalid trailing whitespace", + "scope": "invalid.deprecated.trailing-whitespace", + "background": "var(red3)", + } + ] +} diff --git a/ISE Nostalgia.tmTheme b/ISE Nostalgia.tmTheme deleted file mode 100644 index 7eaf925..0000000 --- a/ISE Nostalgia.tmTheme +++ /dev/null @@ -1,280 +0,0 @@ - - - - - author - Guillermo López-Anglada - name - ISE Nostalgia - settings - - - settings - - gutterForeground - #5AB1CD - background - #FFFFFF - foreground - #8A2BE2 - caret - #7F7F7F - lineHighlight - #FEF8DA - selection - #ADD6FF - selectionBorder - #87BEFF - inactiveSelection - #E3F1FF - - - - name - Comment - scope - comment - settings - - fontStyle - normal - foreground - #006400 - - - - name - Keyword - scope - keyword, storage - settings - - foreground - #292929 - - - - name - Number - scope - constant.numeric - settings - - fontStyle - - foreground - #801E92 - - - - name - Built-in constant - scope - constant.language - settings - - foreground - #585CF6 - - - - name - Variable - scope - variable.language, variable.other - settings - - fontStyle - - foreground - #FF4500 - - - - name - String - scope - string - settings - - fontStyle - - foreground - #6B0000 - - - - name - String interpolation - scope - constant.character.escape, string source - settings - - fontStyle - - foreground - #AA69B6 - - - - - - - - name - Library function - scope - support.function - settings - - foreground - #0000FF - - - - - - - name - PowerShell: Assignment Operator - scope - keyword.operator.assignment.powershell - settings - - foreground - #A9A9A9 - - - - name - Invalid - scope - invalid - settings - - background - #B85B44 - foreground - #FFFF00 - - - - name - Invalid trailing whitespace - scope - invalid.deprecated.trailing-whitespace - settings - - background - #B85B44 - - - - uuid - 71D40D9D-AE48-11D9-920A-000D93589AF6 - - \ No newline at end of file From 562711fc668c908f4730232cddef8803cd6a919b Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 16 Apr 2021 19:52:11 -0400 Subject: [PATCH 18/23] Syntax test workflow --- .github/workflows/syntax.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/syntax.yml diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml new file mode 100644 index 0000000..7ec057b --- /dev/null +++ b/.github/workflows/syntax.yml @@ -0,0 +1,32 @@ +name: Syntax Tests + +on: + push: + paths: + - '**.sublime-syntax' + - '**/syntax_test*' + - '**.tmPreferences' + pull_request: + paths: + - '**.sublime-syntax' + - '**/syntax_test*' + - '**.tmPreferences' + +jobs: + main: + name: Syntax Tests (${{ matrix.build }}) + strategy: + matrix: + include: + - build: 3211 + packages: st3 + - build: 4102 + packages: master + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: SublimeText/syntax-test-action@v2 + with: + build: ${{ matrix.build }} + default_packages: ${{ matrix.packages }} + package_name: 'PowerShell' From 8b530af563645c5f2727b6f6d2b205bd79176bb9 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 16 Apr 2021 20:07:29 -0400 Subject: [PATCH 19/23] Syntax test references --- PowerShell.sublime-syntax | 1 + Support/Symbol List Classes.tmPreferences | 17 ------------ Tests/syntax_test_Class.ps1 | 3 ++- Tests/syntax_test_Function.ps1 | 7 +++-- Tests/syntax_test_PowerShell.ps1 | 32 +++++++++++++++++++---- 5 files changed, 35 insertions(+), 25 deletions(-) delete mode 100644 Support/Symbol List Classes.tmPreferences diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 97c92fe..241e06a 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -3,6 +3,7 @@ # http://www.sublimetext.com/docs/3/syntax.html name: PowerShell scope: source.powershell +version: 2 file_extensions: - ps1 diff --git a/Support/Symbol List Classes.tmPreferences b/Support/Symbol List Classes.tmPreferences deleted file mode 100644 index 5999bfd..0000000 --- a/Support/Symbol List Classes.tmPreferences +++ /dev/null @@ -1,17 +0,0 @@ - - - - - name - Symbol List: Functions - scope - source.powershell entity.name.class - settings - - showInSymbolList - 1 - - uuid - f935a7e0-c4fd-11e3-9c1a-0800200c9a66 - - diff --git a/Tests/syntax_test_Class.ps1 b/Tests/syntax_test_Class.ps1 index 7b015b2..89b52ac 100644 --- a/Tests/syntax_test_Class.ps1 +++ b/Tests/syntax_test_Class.ps1 @@ -7,7 +7,8 @@ using namespace system.management.automation # Define a class class TypeName # <- storage.type -# ^ entity.name.class +# ^^^^^^^^ entity.name.class +# @@@@@@@@ definition { # Property with validate set # <- punctuation.definition.comment diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 index bbb424e..3c16339 100644 --- a/Tests/syntax_test_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -53,8 +53,10 @@ using module Microsoft.Management #> # <- punctuation.definition.comment.block.end function Verb-Noun { -# <- meta.function storage.type -# ^ meta.function entity.name.function +#^^^^^^^^^^^^^^^^^ meta.function +#^^^^^^^ storage.type +# ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute @@ -381,6 +383,7 @@ function Verb-Noun { # ^ punctuation.definition.variable # ^^^^^^^^ variable.language # ^^^^^^^^^^^^^ variable.function + # @@@@@@@@@@@@@ reference # ^ punctuation.section.arguments.begin # ^^^^^^^^ string.quoted.double # ^ punctuation.separator diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index b706cc0..145a584 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -155,6 +155,7 @@ $variable.Name.Method( ) # ^^^^ variable.other.member # ^ punctuation.accessor.dot # ^^^^^^ meta.function-call variable.function +# @@@@@@ reference # ^^^ meta.function-call.arguments # ^^^^^^^^^^^^^^^ - variable.other.readwrite # ^ - meta.function-call @@ -606,6 +607,7 @@ There is no @platting here! # ^ punctuation.section.brackets.end # ^^ punctuation.accessor.double-colon # ^^^^^ meta.function-call variable.function +# @@@@@ reference # ^^^^^^^^^^^^^^ meta.function-call.arguments # ^ punctuation.section.arguments.begin # ^ punctuation.section.arguments.end @@ -828,46 +830,55 @@ switch ('this') { functioN MyFunction{} # <- storage.type # ^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function My-Function {} # <- storage.type # ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end Function My.Function{} # <- storage.type # ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function My-Function.Other{} # <- storage.type # ^^^^^^^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function Some.other.function{} # <- storage.type # ^^^^^^^^^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end FUNCTION MyFunction2 {} # <- storage.type # ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function New-File { } # <- storage.type # ^^^^^^^^ entity.name.function +# @@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function New-File ($Name) { } # <- storage.type # ^^^^^^^^ entity.name.function +# @@@@@@@@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end function NewFile($Name) { } # <- storage.type # ^^^^^^^ entity.name.function +# @@@@@@@ definition # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ variable.other.readwrite @@ -877,6 +888,7 @@ function NewFile($Name) { } filter myfilter($param) {} # <- storage.type # ^^^^^^^^ entity.name.function +# @@@@@@@@ definition # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ variable.other.readwrite @@ -886,6 +898,7 @@ filter myfilter($param) {} Filter my-Filter ($param){} # <- storage.type # ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition # ^ punctuation.section.group.begin # ^ punctuation.definition.variable # ^ variable.other.readwrite @@ -897,6 +910,7 @@ Filter my-Filter ($param){} function Test-Drive([string]$roman) { # <- storage.type # ^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ definition # ^ punctuation.section.group.begin # ^ punctuation.section.brackets.begin # ^^^^^^ storage.type @@ -915,8 +929,10 @@ function Test-Drive([string]$roman) { # <- punctuation.section.braces.end function Verb-Noun -# <- meta.function storage.type -# ^ meta.function entity.name.function +#^^^^^^^^^^^^^^^^^ meta.function +#^^^^^^^ storage.type +# ^^^^^^^^^ meta.function entity.name.function +# @@@@@@@@@ definition { # <- punctuation.section.braces.begin @@ -1042,6 +1058,7 @@ function Verb-Noun class Vehicle { # <- storage.type.class # ^^^^^^^ entity.name.class +# @@@@@@@ definition # ^ punctuation.section.braces.begin Vehicle() {} # ^ punctuation.section.group.begin @@ -1109,7 +1126,8 @@ catch { } # Reserved words Configuration Crazyness { # <- storage.type -# ^ entity.name.function +# ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition # ^ punctuation.section.braces.begin Node Whatever { # ^ punctuation.section.braces.begin @@ -1360,6 +1378,7 @@ $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1 # ^ variable.other.readwrite # ^ string.quoted.double punctuation.definition.variable # ^ storage.type +# @@@@@@@@@@@@@@@@@ reference $ScriptBlock | Out-File $file -Force # <- punctuation.definition.variable # ^ keyword.operator.logical.pipe @@ -1368,12 +1387,14 @@ $ScriptBlock | Out-File $file -Force # ^^^^^^ variable.parameter.option workflow w1 {} # <- storage.type -# ^ entity.name.function +# ^^ entity.name.function +# @@ definition # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end Workflow work { sequence {} } # <- storage.type -# ^ entity.name.function +# ^^^^ entity.name.function +# @@@@ definition # ^ punctuation.section.braces.begin # ^^^^^^^^ keyword.control # ^ punctuation.section.braces.begin @@ -1408,6 +1429,7 @@ get-thing | Out-WithYou > $null # destroy # ^^^^^^ storage.type # ^^ punctuation.accessor.double-colon # ^^^^^^ meta.function-call variable.function +# @@@@@@ reference # ^ meta.group.complex.subexpression punctuation.section.arguments.begin # ^ meta.group.complex.subexpression punctuation.section.arguments.end # ^ meta.group.complex.subexpression punctuation.section.group.end From 7f9cb43f1c365fe7cbe4e1d0468c5a5895ccfa20 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 13 May 2021 23:18:23 +0300 Subject: [PATCH 20/23] Add indentation rules and test --- Indentation.tmPreferences | 15 +++++++++++++++ Tests/syntax_test_reindent.ps1 | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 Indentation.tmPreferences create mode 100644 Tests/syntax_test_reindent.ps1 diff --git a/Indentation.tmPreferences b/Indentation.tmPreferences new file mode 100644 index 0000000..7406497 --- /dev/null +++ b/Indentation.tmPreferences @@ -0,0 +1,15 @@ + + + + + name + Indentation Rules + scope + source.powershell + settings + + unIndentedLinePattern + "@ + + + diff --git a/Tests/syntax_test_reindent.ps1 b/Tests/syntax_test_reindent.ps1 new file mode 100644 index 0000000..5c99463 --- /dev/null +++ b/Tests/syntax_test_reindent.ps1 @@ -0,0 +1,13 @@ +# SYNTAX TEST reindent "Packages/PowerShell/PowerShell.sublime-syntax" +Function Get-ForegroundWindow { + Add-Type @" + using System; using System.Runtime.InteropServices; public class ClassGetForegroundWindow { + [DllImport("user32.dll")] + public static extern IntPtr GetForegroundWindow(); + } +"@ + + return [ClassGetForegroundWindow]::GetForegroundWindow() +} + +Get-ForegroundWindow From bc47f5b719f42d39f9aaf22cb0a02ec8c1a30b49 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Mon, 2 May 2022 02:46:26 +0200 Subject: [PATCH 21/23] Clear string scope for subexpressions within strings Use meta.interpolation and punctuation.section.interpolation scopes for $(...) subexpressions within strings and clear the string scope, to enable ST's brackets matching. --- PowerShell.sublime-syntax | 40 ++++++++++---------- Tests/syntax_test_PowerShell.ps1 | 65 +++++++++++++++++--------------- 2 files changed, 55 insertions(+), 50 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 241e06a..4468ede 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -42,7 +42,7 @@ contexts: - include: redirection - include: commands - include: variable - - include: interpolated-string-content + - include: group - include: function - include: attribute - include: using-directive @@ -427,17 +427,16 @@ contexts: - match: \@"(?=$) scope: punctuation.definition.string.begin.powershell push: - - meta_scope: string.quoted.double.heredoc.powershell + - meta_scope: meta.string.powershell string.quoted.double.heredoc.powershell - match: ^"@ scope: punctuation.definition.string.end.powershell pop: true - - include: variable-no-property - include: escape-characters - include: interpolation - match: \@'(?=$) scope: punctuation.definition.string.begin.powershell push: - - meta_scope: string.quoted.single.heredoc.powershell + - meta_scope: meta.string.powershell string.quoted.single.heredoc.powershell - match: ^'@ scope: punctuation.definition.string.end.powershell pop: true @@ -448,7 +447,7 @@ contexts: - match: \' scope: punctuation.definition.string.begin.powershell push: - - meta_scope: string.quoted.single.powershell + - meta_scope: meta.string.powershell string.quoted.single.powershell - match: "''" scope: constant.character.escape.powershell - match: \' @@ -459,7 +458,7 @@ contexts: - match: '"' scope: punctuation.definition.string.begin.powershell push: - - meta_scope: string.quoted.double.powershell + - meta_scope: meta.string.powershell string.quoted.double.powershell - match: '""' scope: constant.character.escape.powershell - include: escape-characters @@ -467,8 +466,6 @@ contexts: scope: punctuation.definition.string.end.powershell pop: true - match: '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b' - - include: variable-no-property - - include: variable - include: interpolation - match: '`\s*$' scope: keyword.other.powershell @@ -511,31 +508,34 @@ contexts: - include: script-block - include: main - interpolated-string-content: + group: - match: \( scope: punctuation.section.group.begin.powershell push: - - meta_content_scope: interpolated.simple.source.powershell + - meta_scope: meta.group.powershell - match: \) scope: punctuation.section.group.end.powershell pop: true - include: main - - include: interpolation - - include: interpolated-string-content interpolation: - - match: (\$)(\() - captures: - 1: punctuation.definition.variable.powershell - 2: punctuation.section.group.begin.powershell + - match: \$\( + scope: punctuation.section.interpolation.begin.powershell push: - - meta_content_scope: interpolated.complex.source.powershell + - clear_scopes: 1 + - meta_scope: meta.interpolation.powershell - match: \) - scope: punctuation.section.group.end.powershell + scope: punctuation.section.interpolation.end.powershell pop: true - include: main - - include: interpolation - - include: interpolated-string-content + - match: (?=\$) + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.powershell + - include: variable-no-property + - include: variable + - match: '' + pop: true numeric-constant: - match: \b((0[xX])[\h_]*\h({{integer_suffix}})?)({{bytes_unit}})?\b diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index 145a584..c24264b 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -163,28 +163,31 @@ $variable.Name.Method( ) # In double-quoted strings, only the variable should be highlighted, not the property "This is my $variable.Name!" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^ meta.interpolation variable.other.readwrite - string # ^ punctuation.definition.variable -# ^^^^^^^^ variable.other.readwrite -# ^^^^^ - variable - punctuation +# ^^^^^^ meta.string string.quoted.double - meta.interpolation - variable - punctuation # ^ punctuation.definition.string.end # When used in a subexpression, both should be highlighted "This is my $($variable.Name)!" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string +# ^^ meta.string string.quoted.double - meta.interpolation +# ^^ punctuation.section.interpolation.begin +# ^^^^^^^^^ variable.other.readwrite # ^ punctuation.definition.variable -# ^ punctuation.section.group.begin -# ^ punctuation.section.group.end -# ^^^^^^^^ variable.other.readwrite # ^ punctuation.accessor.dot # ^^^^ variable.other.member +# ^ punctuation.section.interpolation.end # ^ punctuation.definition.string.end # $ENV:ComputerName should be highlighted "This is the name of my computer: $ENV:ComputerName" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string # ^ punctuation.definition.variable # ^^^^ support.variable.drive # ^^^^^^^^^^^^ variable.other.readwrite @@ -193,7 +196,8 @@ $variable.Name.Method( ) # Here as well "This is the name of my computer: ${ENV:ComputerName}" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string # ^ punctuation.definition.variable # ^ punctuation.section.braces.begin # ^^^^ support.variable.drive @@ -402,42 +406,43 @@ $a3[1..2] # Single quoted strings 'This is a single quoted string.' -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single '$This is a single ''quoted'' string.' -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single # ^^ constant.character.escape # ^^ constant.character.escape 'This is a single quoted string.' -# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +# ^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single 'This #also' -# ^^^^^^^^^^^^ string.quoted.single +# ^^^^^^^^^^^^ meta.string string.quoted.single '$(Invoke-Something)' -# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.single - meta - variable - support +# ^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single - meta.interpolation - variable - support 'This "string" is nice.' -# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single # Double quoted strings "This is a double quoted string." -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double "$This is a double ""quoted"" string." -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^^^^^ variable.language +# ^ meta.string string.quoted.double +# ^^^^^ meta.string meta.interpolation variable.language - string +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double - meta.interpolation # ^^ constant.character.escape # ^^ constant.character.escape "This is a double quoted string." -# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double "This #also" -# ^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^ meta.string string.quoted.double "$(Invoke-Something)" -# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^ punctuation.definition.variable -# ^ punctuation.section.group.begin -# ^ interpolated.complex.source support.function -# ^ punctuation.section.group.end +# ^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string +# ^^ punctuation.section.interpolation.begin +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.section.interpolation.end "This 'string' is nice." -# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double # Double quoted here-string @" @@ -1376,7 +1381,7 @@ $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1 # ^ support.function # ^ support.variable.drive # ^ variable.other.readwrite -# ^ string.quoted.double punctuation.definition.variable +# ^^ meta.string meta.interpolation punctuation.section.interpolation.begin # ^ storage.type # @@@@@@@@@@@@@@@@@ reference $ScriptBlock | Out-File $file -Force @@ -1423,7 +1428,7 @@ get-thing | Out-WithYou > $null # destroy # ^^ constant.character.escape # ^^^^^^^^^^^^^^^^^^^ - constant "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" -# ^ punctuation.definition.variable +# ^^ punctuation.section.interpolation.begin # ^ keyword.operator.logical.pipe # ^ meta.group.complex.subexpression punctuation.section.group.begin # ^^^^^^ storage.type @@ -1435,8 +1440,8 @@ get-thing | Out-WithYou > $null # destroy # ^ meta.group.complex.subexpression punctuation.section.group.end # ^ punctuation.definition.variable "This is the DebugPreference variable: $DebugPreference" -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^^^^^^^^^^^^^^^^ variable.language +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^ meta.string meta.interpolation variable.language - string $ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView #^ variable.language punctuation From abca63f98c99b19e28e7cffcda265ad93737f863 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Tue, 10 May 2022 21:28:31 +0200 Subject: [PATCH 22/23] Tweak syntax tests --- Tests/syntax_test_PowerShell.ps1 | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index c24264b..4858dd0 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -163,18 +163,20 @@ $variable.Name.Method( ) # In double-quoted strings, only the variable should be highlighted, not the property "This is my $variable.Name!" # <- punctuation.definition.string.begin -#^^^^^^^^^^^ meta.string string.quoted.double +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string +#^^^^^^^^^^^ string.quoted.double # ^^^^^^^^^ meta.interpolation variable.other.readwrite - string # ^ punctuation.definition.variable -# ^^^^^^ meta.string string.quoted.double - meta.interpolation - variable - punctuation +# ^^^^^^ string.quoted.double - meta.interpolation - variable - punctuation # ^ punctuation.definition.string.end # When used in a subexpression, both should be highlighted "This is my $($variable.Name)!" # <- punctuation.definition.string.begin -#^^^^^^^^^^^ meta.string string.quoted.double -# ^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string -# ^^ meta.string string.quoted.double - meta.interpolation +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string +#^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^ meta.interpolation - string +# ^^ string.quoted.double - meta.interpolation # ^^ punctuation.section.interpolation.begin # ^^^^^^^^^ variable.other.readwrite # ^ punctuation.definition.variable @@ -186,8 +188,9 @@ $variable.Name.Method( ) # $ENV:ComputerName should be highlighted "This is the name of my computer: $ENV:ComputerName" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double -# ^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^ meta.interpolation - string # ^ punctuation.definition.variable # ^^^^ support.variable.drive # ^^^^^^^^^^^^ variable.other.readwrite @@ -196,8 +199,9 @@ $variable.Name.Method( ) # Here as well "This is the name of my computer: ${ENV:ComputerName}" # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double -# ^^^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^^^ meta.interpolation - string # ^ punctuation.definition.variable # ^ punctuation.section.braces.begin # ^^^^ support.variable.drive @@ -206,7 +210,7 @@ $variable.Name.Method( ) # The @splat references only work in argument mode, should not highlight in strings "This is a @double quoted string." -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double # ^ - punctuation.definition.variable # ^^^^^^^ - variable @@ -219,7 +223,7 @@ $variable.Name.Method( ) # Single quotes string 'This is a string' # <- punctuation.definition.string.begin -#^^^^^^^^^^^^^^^^^ string.quoted.single +#^^^^^^^^^^^^^^^^^ meta.string string.quoted.single # ^ punctuation.definition.string.end # Hashtable From 3179654431d4b9ea3bf0fc792a277fdf348c66d3 Mon Sep 17 00:00:00 2001 From: Janos Wortmann Date: Tue, 10 May 2022 21:34:52 +0200 Subject: [PATCH 23/23] Add source.powershell.embedded for subexpressions --- PowerShell.sublime-syntax | 1 + Tests/syntax_test_PowerShell.ps1 | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 4468ede..db3f947 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -524,6 +524,7 @@ contexts: push: - clear_scopes: 1 - meta_scope: meta.interpolation.powershell + - meta_content_scope: source.powershell.embedded - match: \) scope: punctuation.section.interpolation.end.powershell pop: true diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index 4858dd0..119d609 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -1432,7 +1432,8 @@ get-thing | Out-WithYou > $null # destroy # ^^ constant.character.escape # ^^^^^^^^^^^^^^^^^^^ - constant "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" -# ^^ punctuation.section.interpolation.begin +# ^^ punctuation.section.interpolation.begin - source.powershell.embedded +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.powershell.embedded # ^ keyword.operator.logical.pipe # ^ meta.group.complex.subexpression punctuation.section.group.begin # ^^^^^^ storage.type @@ -1443,6 +1444,7 @@ get-thing | Out-WithYou > $null # destroy # ^ meta.group.complex.subexpression punctuation.section.arguments.end # ^ meta.group.complex.subexpression punctuation.section.group.end # ^ punctuation.definition.variable +# ^ punctuation.section.interpolation.end - source.powershell.embedded "This is the DebugPreference variable: $DebugPreference" #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double # ^^^^^^^^^^^^^^^^ meta.string meta.interpolation variable.language - string