|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466 |
- %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: (?<!')'
- captures:
- 0: punctuation.definition.string.begin.powershell
- push:
- - meta_scope: string.quoted.single.powershell
- - match: "'(?!')"
- captures:
- 0: punctuation.definition.string.end.powershell
- pop: true
- - match: "''"
- scope: constant.character.escape.powershell
- - match: \@"(?=$)
- push:
- - meta_scope: string.quoted.double.heredoc.powershell
- - match: ^"@
- pop: true
- - include: variableNoProperty
- - include: doubleQuotedStringEscapes
- - include: interpolation
- - match: \@'(?=$)
- push:
- - meta_scope: string.quoted.single.heredoc.powershell
- - match: ^'@
- pop: true
- - match: "''"
- scope: constant.character.escape.powershell
- - include: numericConstant
- - match: (@)(\()
- captures:
- 1: keyword.other.array.begin.powershell
- 2: punctuation.section.group.begin.powershell
- push:
- - meta_scope: meta.group.array-expression.powershell
- - match: \)
- captures:
- 0: punctuation.section.group.end.powershell
- pop: true
- - include: main
- - match: (\$)(\()
- comment: "TODO: move to repo; make recursive."
- captures:
- 1: punctuation.definition.variable.powershell
- 2: punctuation.section.group.begin.powershell
- push:
- - meta_scope: meta.group.complex.subexpression.powershell
- - match: \)
- captures:
- 0: 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: (?<!\w|-|\.)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|from|if|in|inlinescript|parallel|param|process|return|sequence|switch|throw|trap|try|until|var|while)|%|\?)(?!\w)
- scope: keyword.control.powershell
- - match: '(?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w)'
- scope: keyword.control.powershell
- - match: (?<!\w)(--%)(?!\w)
- comment: This should be moved to the repository at some point.
- captures:
- 1: keyword.control.powershell
- push:
- - match: $
- pop: true
- - match: .+
- scope: string.unquoted.powershell
- - match: (?<!\w)((?i:hidden|static))(?!\w)
- comment: 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: '(?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b'
- comment: capture should be entity.name.type, but it doesn't provide a good color in the default schema.
- captures:
- 1: storage.type.powershell
- 2: entity.name.function
- - match: (?<!\w)-(?i:is(?:not)?|as)\b
- scope: keyword.operator.comparison.powershell
- - match: '(?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L})'
- scope: keyword.operator.comparison.powershell
- - match: '(?<!\w)-(?i:join|split)(?!\p{L})|!'
- scope: keyword.operator.unary.powershell
- - match: '(?<!\w)-(?i:and|or|not|xor)(?!\p{L})|!'
- scope: keyword.operator.logical.powershell
- - match: '(?<!\w)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L})'
- scope: keyword.operator.bitwise.powershell
- - match: '(?<!\w)-(?i:f)(?!\p{L})'
- scope: keyword.operator.string-format.powershell
- - match: "[+%*/-]?=|[+/*%-]"
- scope: keyword.operator.assignment.powershell
- - match: '\|{2}|&{2}|;'
- scope: punctuation.terminator.statement.powershell
- - match: '&|(?<!\w)\.(?= )|`|,|\|'
- scope: keyword.operator.other.powershell
- - match: (?<!\s|^)\.\.(?=\-?\d|\(|\$)
- comment: This is very imprecise, is there a syntax for 'must come after...'
- scope: keyword.operator.range.powershell
- RequiresDirective:
- - match: (?<=#)(?i:(requires))\s
- captures:
- 0: keyword.control.requires.powershell
- push:
- - meta_scope: meta.requires.powershell
- - match: $
- pop: true
- - match: \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version)
- scope: keyword.other.powershell
- - match: '(?<!-)\b\p{L}+|\d+(?:\.\d+)*'
- scope: variable.parameter.powershell
- - include: hashtable
- UsingDirective:
- - match: (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
- captures:
- 1: keyword.control.using.powershell
- 2: keyword.other.powershell
- 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'
- captures:
- 1: punctuation.section.bracket.begin.powershell
- 2: support.function.attribute.powershell
- push:
- - meta_scope: meta.attribute.powershell
- - match: '(\])'
- captures:
- 1: punctuation.section.bracket.end.powershell
- pop: true
- - match: \(
- captures:
- 0: punctuation.section.group.begin.powershell
- push:
- - match: \)
- captures:
- 0: punctuation.section.group.end.powershell
- pop: true
- - include: variable
- - include: variableNoProperty
- - include: hashtable
- - include: scriptblock
- - include: doubleQuotedStringEscapes
- - include: doubleQuotedString
- - include: type
- - include: numericConstant
- - include: doubleQuotedString
- - include: main
- - match: (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=)?
- captures:
- 1: variable.parameter.attribute.powershell
- 2: keyword.operator.assignment.powershell
- - match: (?<!')'
- captures:
- 0: punctuation.definition.string.begin.powershell
- push:
- - meta_scope: string.quoted.single.powershell
- - match: "'(?!')"
- captures:
- 0: punctuation.definition.string.end.powershell
- pop: true
- - match: "''"
- scope: constant.character.escape.powershell
- 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'
- comment: "Verb-Noun pattern:"
- scope: support.function.powershell
- - match: (?<!\w)(?i:foreach-object)(?!\w)
- comment: Builtin cmdlets with reserved verbs
- scope: support.function.powershell
- - match: (?<!\w)(?i:where-object)(?!\w)
- comment: Builtin cmdlets with reserved verbs
- scope: support.function.powershell
- - match: (?<!\w)(?i:sort-object)(?!\w)
- comment: Builtin cmdlets with reserved verbs
- scope: support.function.powershell
- - match: (?<!\w)(?i:tee-object)(?!\w)
- comment: Builtin cmdlets with reserved verbs
- scope: support.function.powershell
- commentEmbeddedDocs:
- - 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-_]+))'
- scope: comment.documentation.embedded.powershell
- captures:
- 1: constant.string.documentation.powershell
- 2: keyword.operator.documentation.powershell
- 3: keyword.operator.documentation.powershell
- commentLine:
- - match: '(?<![`\\-])#'
- captures:
- 0: punctuation.definition.comment.powershell
- push:
- - meta_scope: comment.line.powershell
- - match: $\n?
- captures:
- 0: punctuation.definition.comment.powershell
- pop: true
- - include: commentEmbeddedDocs
- - include: RequiresDirective
- doubleQuotedString:
- - match: (?<!(?<!`)")"
- captures:
- 0: punctuation.definition.string.begin.powershell
- push:
- - meta_scope: string.quoted.double.powershell
- - match: '"(?!")'
- captures:
- 0: punctuation.definition.string.end.powershell
- pop: true
- - match: '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b'
- - include: variableNoProperty
- - include: variable
- - include: doubleQuotedStringEscapes
- - include: interpolation
- - match: '`\s*$'
- scope: keyword.other.powershell
- doubleQuotedStringEscapes:
- - match: '`[0abnfrvt"''$`]'
- 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|_|-|\.)+)'
- captures:
- 0: meta.function.powershell
- 1: storage.type.powershell
- 2: storage.modifier.scope.powershell
- 3: entity.name.function.powershell
- push:
- - match: '(?=\{|\()'
- pop: true
- - include: commentLine
- hashtable:
- - match: '(@)(\{)'
- captures:
- 1: keyword.other.hashtable.begin.powershell
- 2: punctuation.section.braces.begin.powershell
- push:
- - meta_scope: meta.hashtable.powershell
- - match: '(\})'
- captures:
- 1: punctuation.section.braces.end.powershell
- pop: true
- - match: \b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)?
- scope: meta.hashtable.assignment.powershell
- captures:
- 1: punctuation.definition.string.begin.powershell
- 2: variable.other.readwrite.powershell
- 3: punctuation.definition.string.end.powershell
- 4: keyword.operator.assignment.powershell
- - include: scriptblock
- - include: main
- interpolatedStringContent:
- - match: \(
- captures:
- 0: punctuation.section.group.begin.powershell
- push:
- - meta_content_scope: interpolated.simple.source.powershell
- - match: \)
- captures:
- 0: punctuation.section.group.end.powershell
- pop: true
- - include: main
- - include: interpolation
- - include: interpolatedStringContent
- interpolation:
- - match: (\$)(\()
- captures:
- 1: punctuation.definition.variable.powershell
- 2: punctuation.section.group.begin.powershell
- push:
- - meta_content_scope: interpolated.complex.source.powershell
- - match: \)
- captures:
- 0: punctuation.section.group.end.powershell
- pop: true
- - include: main
- - include: interpolation
- - include: interpolatedStringContent
- numericConstant:
- - 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: constant.numeric.hex.powershell
- 2: 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: constant.numeric.integer.powershell
- 2: 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: constant.numeric.octal.powershell
- 2: keyword.other.powershell
- - match: '(?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b'
- captures:
- 1: constant.numeric.integer.powershell
- 2: keyword.other.powershell
- - match: '(?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b'
- captures:
- 1: constant.numeric.integer.powershell
- 2: keyword.other.powershell
- - match: '(?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b'
- captures:
- 1: constant.numeric.integer.powershell
- 2: keyword.other.powershell
- - match: '(?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b'
- captures:
- 1: constant.numeric.integer.powershell
- 2: keyword.other.powershell
- scriptblock:
- - match: '\{'
- captures:
- 0: punctuation.section.braces.begin.powershell
- push:
- - meta_scope: meta.scriptblock.powershell
- - match: '\}'
- captures:
- 0: punctuation.section.braces.end.powershell
- pop: true
- - include: main
- type:
- - match: '\['
- captures:
- 0: punctuation.section.bracket.begin.powershell
- push:
- - match: '\]'
- captures:
- 0: punctuation.section.bracket.end.powershell
- pop: true
- - match: '(?!\d+|\.)(?:\p{L}|\p{N}|\.)+'
- scope: storage.type.powershell
- - include: main
- variable:
- - match: (\$)(?i:(False|Null|True))\b
- comment: These are special constants.
- captures:
- 0: constant.language.powershell
- 1: punctuation.definition.variable.powershell
- - match: '(\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b'
- comment: These are the other built-in constants.
- captures:
- 0: support.constant.variable.powershell
- 1: 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'
- 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.
- captures:
- 0: support.constant.automatic.powershell
- 1: 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'
- comment: Style preference variables as language variables so that they stand out.
- captures:
- 0: variable.language.powershell
- 1: punctuation.definition.variable.powershell
- 3: variable.other.member.powershell
- - match: '(?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: storage.modifier.scope.powershell
- 4: variable.other.member.powershell
- - match: '(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: punctuation.section.braces.begin.powershell
- 3: storage.modifier.scope.powershell
- 5: punctuation.section.braces.end.powershell
- 6: variable.other.member.powershell
- - match: '(?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: support.variable.drive.powershell
- 4: variable.other.member.powershell
- - match: '(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: punctuation.section.braces.begin.powershell
- 3: support.variable.drive.powershell
- 5: punctuation.section.braces.end.powershell
- 6: variable.other.member.powershell
- variableNoProperty:
- - match: (\$)(?i:(False|Null|True))\b
- comment: These are special constants.
- captures:
- 0: constant.language.powershell
- 1: punctuation.definition.variable.powershell
- - match: (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b
- comment: These are the other built-in constants.
- captures:
- 0: support.constant.variable.powershell
- 1: 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))\b
- comment: Automatic variables are not constants, but they are read-only...
- captures:
- 0: support.variable.automatic.powershell
- 1: 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))\b
- comment: Style preference variables as language variables so that they stand out.
- captures:
- 0: variable.language.powershell
- 1: punctuation.definition.variable.powershell
- 3: variable.other.member.powershell
- - match: '(?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: storage.modifier.scope.powershell
- 4: variable.other.member.powershell
- - match: '(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: storage.modifier.scope.powershell
- 4: keyword.other.powershell
- 5: variable.other.member.powershell
- - match: '(?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: support.variable.drive.powershell
- 4: variable.other.member.powershell
- - match: '(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))'
- captures:
- 0: variable.other.readwrite.powershell
- 1: punctuation.definition.variable.powershell
- 2: punctuation.section.braces.begin
- 3: support.variable.drive.powershell
- 5: punctuation.section.braces.end
|