diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 6372d331..cf6e7e8c 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -1,6 +1,7 @@ %YAML 1.2 --- -# http://www.sublimetext.com/docs/3/syntax.html +# http://www.sublimetext.com/docs/syntax.html +# https://learn.microsoft.com/en-us/powershell/ name: PowerShell scope: source.powershell version: 2 @@ -12,77 +13,137 @@ file_extensions: first_line_match: |- (?x: - ^\#!.*\b(?:pwsh|powershell)\b + ^\#!.*{{shebang_language}} | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*- ) -variables: - dec_exponent: (?:[eE][-+]?\d*) - dec_suffix: '[dD]' - float_suffix: '[dDlL]' - int_suffix: (?i:u[lsy]?|[lnsy]) - unit_suffix: (?i:[kmgtp]b\b) - kebab_break: (?![\w-]) - contexts: + prototype: + - include: comments + + main: + - meta_include_prototype: false + - match: '' + push: [statements, imports, shebang] - pop-before-newline: - - match: (?=\n|$) - pop: true + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.powershell + set: shebang-body + - include: else-pop - pop-at-newline: - - match: \n|$ - pop: true + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.powershell + - match: '{{shebang_language}}' + scope: constant.language.shebang.powershell + - include: pop-eol + + imports: + - include: using-directives + - include: else-pop + + statements: + - include: classes + - include: functions + - include: workflows + - include: desired-state-configurations + + - include: exceptions + - include: loops + - include: flow + - include: conditionals + + - match: \B\.(?= ) + scope: keyword.operator.source.powershell + push: + - include: commands-quoted + - include: else-pop + - match: \& + scope: keyword.operator.call.powershell + push: + - include: commands-quoted + - include: else-pop - main: - - include: regions - - include: comments - include: expressions expressions: - - include: redirection + # Meta + - include: labels + - include: regions + - include: requires-directives + + - include: escape-sequences + - include: literal-after + + # Normal code + - include: types + - include: strings + - include: numbers + - include: constants + - include: variables + + - include: hashtables + - include: arrays + + - include: data-blocks + - include: script-blocks + - include: groups + - include: subexpressions + + - include: future-reserved-words + + - include: operators - include: commands - - include: variable - - include: group - - include: function - - include: attribute - - include: using-directive - - include: type - - include: hashtable + + expressions-without-commands: + # Meta + - include: labels + - include: regions + - include: requires-directives + + - include: escape-sequences + - include: literal-after + + # Normal code + - include: types - include: strings - - include: script-block - - include: escape-characters - - include: numeric-constant - - include: class-method - - match: (@)(\() - captures: - 1: keyword.other.array.begin.powershell - 2: punctuation.section.group.begin.powershell - push: - - meta_scope: meta.group.array-expression.powershell - - match: \) - scope: punctuation.section.group.end.powershell - pop: true - - include: main - - match: (\$)(\() - # TODO: move to repo; make recursive. - captures: - 1: keyword.other.variable.definition.powershell - 2: punctuation.section.group.begin.powershell + - include: numbers + - include: constants + - include: variables + + - include: hashtables + - include: arrays + + - include: data-blocks + - include: script-blocks + - include: groups + - include: subexpressions + + - include: future-reserved-words + + - include: operators + + literal-after: + - match: \B--%\B + scope: keyword.control.powershell push: - - meta_scope: meta.group.complex.subexpression.powershell - - match: \) - scope: punctuation.section.group.end.powershell - pop: true - - include: main - - match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b - scope: variable.function.powershell - # Consume a string with a trailing dot - # to prevent members with particular names from being recognized as keywords. - - match: \b[\w-]+(?=\.) - scope: variable.other.object.powershell - push: members - # Exceptions + - meta_include_prototype: false + - meta_content_scope: string.unquoted.powershell + - include: pop-before-eol + + future-reserved-words: + # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_reserved_words + - match: \b(?i:define|from){{kebab_break}} + scope: keyword.control.powershell + - match: \b(?i:var){{kebab_break}} + scope: keyword.declaration.variable.powershell + +###[ EXCEPTIONS ]############################################################## + + exceptions: - match: \b(?i:throw){{kebab_break}} scope: keyword.control.exception.raise.powershell - match: \b(?i:try){{kebab_break}} @@ -91,29 +152,10 @@ contexts: 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:process){{kebab_break}} - scope: keyword.context.block.process.powershell - - match: \b(?i:end){{kebab_break}} - scope: keyword.context.block.end.powershell - - match: \b(?i:clean){{kebab_break}} - scope: keyword.context.block.clean.powershell - # Loops + +###[ LOOPS ]################################################################### + + loops: - match: \b(?i:for|foreach(?!-object)){{kebab_break}} scope: keyword.control.loop.for.powershell - match: \b(?i:do){{kebab_break}} @@ -122,7 +164,10 @@ contexts: scope: keyword.control.loop.while.powershell - match: \b(?i:until){{kebab_break}} scope: keyword.control.loop.repeat-until.powershell - # Flow + +###[ FLOW ]#################################################################### + + flow: - match: \b(?i:break){{kebab_break}} scope: keyword.control.flow.break.powershell - match: \b(?i:continue){{kebab_break}} @@ -131,28 +176,672 @@ contexts: 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|sequence){{kebab_break}} - scope: keyword.control.powershell - - match: \B--%\B - scope: keyword.control.powershell + +###[ CONDITIONALS ]############################################################ + + 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 + push: in-command + - match: \b(?i:default){{kebab_break}} + scope: keyword.control.conditional.default.powershell + - match: \b(?i:where(?!-object)){{kebab_break}} + scope: keyword.control.conditional.select.powershell + +###[ GROUPS ]################################################################## + + groups: + - match: \( + scope: punctuation.section.group.begin.powershell + push: inside-group + + inside-group: + - meta_scope: meta.group.powershell + - match: \) + scope: punctuation.section.group.end.powershell + set: members + # TODO: Move this to a foreach (X in Y) construct + - match: \b(?i:in){{kebab_break}} + scope: keyword.control.loop.in.powershell + - include: attributes + - include: expressions + + arrays: + - match: (@)(\() + captures: + 1: keyword.other.array.begin.powershell + 2: punctuation.section.group.begin.powershell + push: [members, inside-array] + + inside-array: + - meta_scope: meta.group.array-expression.powershell + - match: \) + scope: punctuation.section.group.end.powershell + pop: 1 + - include: expressions + + hashtables: + - match: (@)(\{) + captures: + 1: keyword.other.hashtable.begin.powershell + 2: punctuation.section.braces.begin.powershell + push: [members, inside-hashtable] + + inside-hashtable: + - meta_scope: meta.hashtable.powershell + - match: \} + scope: punctuation.section.braces.end.powershell + pop: 1 + - match: \b(({{single_quote}}){{identifier_simple}}({{single_quote}}))\s*(=)\s* + captures: + 1: meta.mapping.key.powershell string.quoted.single.powershell + 2: punctuation.definition.string.begin.powershell + 3: punctuation.definition.string.end.powershell + 4: punctuation.separator.key-value.powershell + - match: \b(({{double_quote}}){{identifier_simple}}({{double_quote}}))\s*(=)\s* + captures: + 1: meta.mapping.key.powershell string.quoted.double.powershell + 2: punctuation.definition.string.begin.powershell + 3: punctuation.definition.string.end.powershell + 4: punctuation.separator.key-value.powershell + - match: \b({{identifier_simple}})\s*(=)\s* + captures: + 1: meta.mapping.key.powershell string.unquoted.powershell + 2: punctuation.separator.key-value.powershell + - include: expressions + + subexpressions: + - match: (\$)(\() + captures: + 1: keyword.other.variable.definition.powershell + 2: punctuation.section.group.begin.powershell + push: inside-subexpression + + inside-subexpression: + - meta_scope: meta.group.complex.subexpression.powershell + - match: \) + scope: punctuation.section.group.end.powershell + pop: 1 + - include: expressions + + script-blocks: + - match: (%)?(\{) + captures: + 1: keyword.control.loop.for.powershell + 2: punctuation.section.braces.begin.powershell + push: [members, inside-script-block] + + inside-script-block: + - meta_scope: meta.block.powershell + - match: \} + scope: punctuation.section.braces.end.powershell + pop: 1 + - include: param-block + - include: statements + +###[ COMMANDS ]################################################################ + + commands: + - include: commands-verb-noun + - include: commands-reserved + - include: script-invocation + - include: command-freeform + + commands-verb-noun: + # The "Verb-Noun" pattern + - match: |- + (?x: + (?:[.\w\\/:-]*[\\/])? # Path stuff + {{command_verbs}} # Approved verbs + \-\w+? # Any "noun" + (?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff + ) + scope: meta.function-call.powershell support.function.powershell + push: in-command + + commands-reserved: + # Builtin cmdlets with reserved verbs + - match: \b(?i:(?:ForEach|Where|Sort|Tee)-Object)\b + scope: meta.function-call.powershell support.function.powershell + push: in-command + + script-invocation: + - match: \b(?i:[a-z]:)?[\w.\\/-]+\.(?i:exe|com|cmd|bat|ps1)\b + scope: meta.function-call.powershell variable.function.powershell + push: in-command + + commands-quoted: + - match: (?={{single_quote}}) + push: [in-command, single-quoted-command-string] + - match: (?={{double_quote}}) + push: [in-command, double-quoted-command-string] + + single-quoted-command-string: + - match: '{{single_quote}}' + scope: punctuation.definition.string.begin.powershell + push: inside-single-quoted-command-string + - include: immediately-pop + + inside-single-quoted-command-string: + - meta_include_prototype: false + - meta_scope: meta.string.powershell string.quoted.single.powershell meta.function-call.powershell variable.function.powershell + - match: '{{single_quote}}{2}' + scope: constant.character.escape.powershell + - match: '{{single_quote}}' + scope: punctuation.definition.string.end.powershell + pop: 1 + - include: path-punctuation + + double-quoted-command-string: + - match: '{{double_quote}}' + scope: punctuation.definition.string.begin.powershell + push: inside-double-quoted-command-string + - include: immediately-pop + + inside-double-quoted-command-string: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell meta.function-call.powershell variable.function.powershell + - match: '{{double_quote}}{2}' + scope: constant.character.escape.powershell + - include: escape-sequences + - match: '{{double_quote}}' + scope: punctuation.definition.string.end.powershell + pop: 1 + - include: string-interpolations + - include: path-punctuation + + command-freeform: + - match: '{{identifier_simple}}' + scope: meta.function-call.powershell variable.function.powershell + push: in-command + + in-command: + - meta_content_scope: meta.function-call.arguments.powershell + - include: command-ending-sequences + - include: redirection + - include: cli-parameters + - include: expressions-without-commands + - match: (?=\S) push: - - meta_content_scope: string.unquoted.powershell - - include: pop-before-newline + - meta_include_prototype: false + - meta_scope: string.unquoted.powershell + - match: (?=[\s#|>;,]|$) + pop: 1 + - include: path-punctuation + - include: escape-sequences + - include: string-wildcards + + command-ending-sequences: + - include: line-continuations + - include: pop-eol + - match: (?=[)}]) + pop: 1 + - match: ';' + scope: punctuation.terminator.statement.powershell + pop: 1 + - match: (\|)\s*\n + captures: + 1: keyword.operator.logical.pipe.powershell + push: + - match: ^ + pop: 2 + - match: \| + scope: keyword.operator.logical.pipe.powershell + pop: 1 + + cli-parameters: + # Flags/Options/Parameters + - match: \B(--?|[/+])\p{L}(?:[\w-]*\w)? + scope: variable.parameter.option.powershell + captures: + 1: punctuation.definition.parameter.powershell + +###[ DIRECTIVES ]############################################################## + + requires-directives: + - match: (#)((?i:requires))\s + captures: + 1: punctuation.definition.keyword.powershell + 2: keyword.control.import.require.powershell + push: + - meta_scope: meta.requires.powershell + - include: pop-eol + - include: hashtables + - match: (-)(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) + scope: variable.parameter.option.powershell + captures: + 1: punctuation.definition.variable.powershell + - match: ',' + scope: punctuation.separator.powershell + + using-directives: + - match: \b(?i)using(?=\s) + scope: keyword.control.import.powershell + push: inside-using + + inside-using: + - match: \bnamespace(?=\s) + scope: keyword.control.import.powershell + set: inside-using-namespace + - match: \bmodule(?=\s) + scope: keyword.control.import.powershell + set: inside-using-module + - include: else-pop + + inside-using-namespace: + - include: pop-eol + - match: '{{identifier_csharp}}(\.)' + scope: meta.path.powershell + captures: + 1: punctuation.accessor.dot.powershell + - match: '{{identifier_csharp}}' + scope: meta.path.powershell + + inside-using-module: + - include: pop-eol + - match: '{{identifier_csharp}}(\.)' + scope: meta.path.powershell + captures: + 1: punctuation.accessor.dot.powershell + - match: '{{identifier_csharp}}' + scope: meta.path.powershell support.type.powershell + +###[ CLASSES ]################################################################# + + classes: + - match: \b(?i)class(?=\s) + scope: keyword.declaration.class.powershell + push: [class-body, class-parents, class-name] + + class-name: + - match: '{{identifier_simple}}' + scope: entity.name.class.powershell + pop: 1 + - include: else-pop + + class-parents: + - match: ':' + scope: punctuation.separator.type.powershell + push: inside-class-parents + - include: else-pop + + inside-class-parents: + - include: comma-separators + - match: '{{identifier_simple}}' + scope: entity.other.inherited-class.powershell + - include: else-pop + + class-body: + - meta_scope: meta.class.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-class-body + - include: else-pop + + inside-class-body: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 1 - 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 + - include: attributes + - include: types-without-members + - include: variables-without-members + - match: (?={{identifier_simple}}) + push: [function-body, function-inline-params, function-name] + +###[ FUNCTIONS ]############################################################### + + functions: + - match: ^\s*(?i)(function|filter)(?=\s) + captures: + 1: keyword.declaration.function.powershell + push: [function-body, function-inline-params, function-name] + + function-name: + - match: (?:(global|local|script|private):)?({{identifier_function}}) captures: - 1: storage.type.class.powershell - 2: meta.class.powershell entity.name.class.powershell - # Operators... + 1: storage.modifier.scope.powershell + 2: entity.name.function.powershell + - match: (?=[{(]) + pop: 1 + + function-inline-params: + - match: \( + scope: punctuation.section.parameters.begin.powershell + push: inside-function-inline-params + - include: else-pop + + inside-function-inline-params: + - match: \) + scope: punctuation.section.parameters.end.powershell + pop: 1 + - include: comma-separators + - include: types + - match: (\$){{identifier_simple}} + scope: variable.parameter.powershell + captures: + 1: punctuation.definition.variable.begin.powershell + - include: assignment-normal + + function-body: + - meta_scope: meta.function.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-function-body + - include: else-pop + + inside-function-body: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + + - include: param-block + + - match: \b(?i:Begin|Process|End|Clean){{kebab_break}} + scope: keyword.context.block.powershell + push: expect-function-context + + - include: attributes + - include: workflow-execution-contexts + - include: statements + + param-block: + - match: \b(?i:(?:Dynamic)?Param){{kebab_break}} + scope: keyword.declaration.parameter.powershell # This scope is not standard + push: expect-param-context + + expect-function-context: + - meta_scope: meta.block.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-function-context + - include: else-pop + + inside-function-context: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + - include: workflow-execution-contexts + - include: statements + + expect-param-context: + - match: \( + scope: punctuation.section.block.begin.powershell + push: inside-param-context + - include: else-pop + + inside-param-context: + - match: \) + scope: punctuation.section.block.end.powershell + pop: 1 + - include: comma-separators + - include: attributes + - include: types-without-members + - include: variables-without-members + - include: literals + - include: assignment-normal + + attributes: + - match: (\[)\s*({{attributes}}) + captures: + 1: punctuation.section.brackets.begin.powershell + 2: support.function.attribute.powershell + push: inside-attribute + + inside-attribute: + - meta_scope: meta.attribute.powershell + - match: \] + scope: punctuation.section.brackets.end.powershell + pop: 1 + - match: \( + scope: punctuation.section.group.begin.powershell + push: inside-attribute-parameters + + inside-attribute-parameters: + - match: \) + scope: punctuation.section.group.end.powershell + pop: 1 + - match: ({{attribute_parameters}})\s*(=)? + captures: + 1: variable.parameter.attribute.powershell + 2: keyword.operator.assignment.powershell + - include: expressions + +###[ WORKFLOWS ]############################################################### + + workflows: + - match: ^\s*(?i)(workflow)(?=\s) + captures: + 1: keyword.declaration.function.powershell + push: [function-body, function-name] + + workflow-body: + - meta_scope: meta.function.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-workflow-body + with_prototype: + - include: workflow-execution-contexts + - include: else-pop + + inside-workflow-body: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + - include: statements + + workflow-execution-contexts: + - match: \b(?i:inlinescript){{kebab_break}} + scope: keyword.control.context.powershell + push: expect-function-context + - match: \b(?i:parallel|sequence){{kebab_break}} + scope: keyword.control.flow.powershell + push: expect-function-context + +###[ DESIRED STATE CONFIGURATIONS ]############################################ + + desired-state-configurations: + - match: ^\s*(?i)(configuration)(?=\s) + captures: + 1: keyword.declaration.function.powershell + push: + - desired-state-configuration-body + - desired-state-configuration-name + + desired-state-configuration-name: + - match: '{{identifier_function}}' + scope: entity.name.function.powershell + - match: (?=[{(]) + pop: 1 + + desired-state-configuration-body: + - meta_scope: meta.function.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-desired-state-configuration-body + - include: else-pop + + inside-desired-state-configuration-body: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + + - match: \b(?i:Param){{kebab_break}} + scope: keyword.declaration.parameter.powershell # This scope is not standard + push: expect-param-context + + - match: \b(?i:Node){{kebab_break}} + scope: keyword.context.block.powershell + push: expect-node-context + + - include: attributes + + expect-node-context: + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-node-context + - include: expressions + - include: else-pop + + inside-node-context: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + - match: \b((?i:WindowsFeature))\s+({{identifier_csharp}}) + captures: + 1: keyword.other.powershell + 2: entity.name.label.powershell + - include: expressions + +###[ VARIABLES ]############################################################### + + variables: + - match: '{{var_lookahead}}' + push: [members, expect-variable] + + variables-without-members: + - match: '{{var_lookahead}}' + push: [expect-variable] + + expect-variable: + - match: (\$|@){{var_constants}} + scope: support.constant.variable.powershell + captures: + 1: punctuation.definition.variable.powershell + - match: (\$|@){{var_language}} + scope: variable.language.powershell + captures: + 1: punctuation.definition.variable.powershell + - match: (\$)(\{) + captures: + 1: punctuation.definition.variable.powershell + 2: punctuation.section.interpolation.begin.powershell + push: inside-variable-special-char + - match: (\$|@) + captures: + 1: punctuation.definition.variable.powershell + 2: punctuation.section.interpolation.begin.powershell + push: inside-variable-simple + - include: immediately-pop + + inside-variable-simple: + - meta_include_prototype: false + - meta_scope: variable.other.readwrite.powershell + - match: ({{var_scope_mod}})(:) + captures: + 1: storage.modifier.scope.powershell + 2: punctuation.accessor.colon.powershell + - match: ({{identifier_simple}})(:) + captures: + 1: support.variable.drive.powershell + 2: punctuation.accessor.colon.powershell + - match: '{{identifier_simple}}' + - include: immediately-pop + + inside-variable-special-char: + - meta_include_prototype: false + - meta_scope: variable.other.readwrite.powershell + - match: '`.' + scope: constant.character.escape.powershell + - match: \} + scope: punctuation.section.interpolation.end.powershell + pop: 1 + - match: ({{var_scope_mod}})(:) + captures: + 1: storage.modifier.scope.powershell + 2: punctuation.accessor.colon.powershell + - match: ({{identifier_simple}})(:) + captures: + 1: support.variable.drive.powershell + 2: punctuation.accessor.colon.powershell + + members: + - match: (?=\.\.) + pop: 1 + - match: \?\.(?=\$?{{identifier_simple}}) + scope: punctuation.accessor.null-coalescing.powershell + - match: \??\.(?=\$?{{identifier_simple}}) + scope: punctuation.accessor.dot.powershell + - match: ::(?={{identifier_simple}}) + scope: punctuation.accessor.double-colon.powershell + - match: (new)(\() + captures: + 1: meta.function-call.powershell support.function.constructor.powershell + 2: meta.function-call.arguments.powershell punctuation.section.arguments.begin.powershell + push: inside-function-call-arguments + - match: ({{identifier_simple}})(\() + captures: + 1: meta.function-call.powershell variable.function.powershell + 2: meta.function-call.arguments.powershell punctuation.section.arguments.begin.powershell + push: inside-function-call-arguments + - match: '{{identifier_simple}}' + scope: variable.other.member.powershell + - match: (\?)(\[) + captures: + 1: punctuation.accessor.null-coalescing.powershell + 2: punctuation.section.brackets.begin.powershell + push: inside-indexer + - match: \[ + scope: punctuation.section.brackets.begin.powershell + push: inside-indexer + - include: immediately-pop + + inside-function-call-arguments: + - meta_content_scope: meta.function-call.arguments.powershell + - match: \) + scope: meta.function-call.arguments.powershell punctuation.section.arguments.end.powershell + pop: 1 + - include: expressions + + inside-indexer: + - meta_scope: meta.brackets.indexer.powershell + - match: \] + scope: punctuation.section.brackets.end.powershell + pop: 1 + - include: expressions + +###[ TYPES ]################################################################### + + types: + - match: \[ + scope: punctuation.section.brackets.begin.powershell + push: [members, inside-type] + + types-without-members: + - match: \[ + scope: punctuation.section.brackets.begin.powershell + push: inside-type + + inside-type: + - meta_include_prototype: false + - match: \] + scope: punctuation.section.brackets.end.powershell + pop: 1 + - match: \p{L}[\p{L}\p{N}]+(\.) + scope: meta.generic-name.powershell + captures: + 1: punctuation.accessor.dot.powershell + - match: '{{builtin_types}}' + scope: storage.type.powershell + - match: \p{L}[\p{L}\p{N}]+ + scope: support.type.powershell + - include: types-without-members + - match: \, + scope: punctuation.separator.sequence.powershell + - match: \+ + scope: punctuation.accessor.plus.powershell + +###[ OPERATORS ]############################################################### + + operators: + # Word operators - match: \B(-)(?i:as){{kebab_break}} scope: keyword.operator.cast.powershell captures: @@ -161,11 +850,21 @@ contexts: scope: keyword.operator.comparison.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in)){{kebab_break}} + - match: \B(-)(?i:[ic]?(?:not)?(?:match)){{kebab_break}} scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:join|split|replace){{kebab_break}} + push: expect-regex-string + - match: \B(-)(?i:[ic]?(?:not)?(?:like|contains|in)){{kebab_break}} + scope: keyword.operator.logical.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:replace){{kebab_break}} + scope: keyword.operator.string.powershell + captures: + 1: punctuation.definition.keyword.powershell + push: expect-regex-string + - match: \B(-)(?i:join|split){{kebab_break}} scope: keyword.operator.string.powershell captures: 1: punctuation.definition.keyword.powershell @@ -173,7 +872,7 @@ contexts: scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell - - match: \B(-)(?i:and|or|not|xor){{kebab_break}}|! # <-- note `!` + - match: \B(-)(?i:and|or|not|xor){{kebab_break}} scope: keyword.operator.logical.powershell captures: 1: punctuation.definition.keyword.powershell @@ -185,41 +884,55 @@ contexts: 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) + + # Symbol operators + - match: \! + scope: keyword.operator.logical.powershell + - include: assignment-normal + - match: (?:[+/*%-]|\?\?)= + scope: keyword.operator.assignment.augmented.powershell + push: in-assignment + - match: (?:\+\+|--)(?![ \t]*\d|[[:alpha:]]) scope: keyword.operator.assignment.powershell - match: '[+-](?=\.?\d)' # This is sort of heuristic scope: keyword.operator.unary.powershell - - match: '[+/*-]' + # Be careful about matching arithmetic with tightly following words + - match: '[/+](?![[:alpha:]])' + scope: keyword.operator.arithmetic.powershell + - match: -(?![[:alpha:]-]) scope: keyword.operator.arithmetic.powershell + - match: \*(?!\.?[[:alpha:]]) + scope: keyword.operator.arithmetic.powershell + # Exclude foreach shortcut - match: '%(?!\s*\{)' scope: keyword.operator.arithmetic.powershell - match: \|\||&& scope: keyword.operator.logical.powershell - match: \| scope: keyword.operator.logical.pipe.powershell + - match: \?\? + scope: keyword.operator.null-coalescing.powershell + - match: '[?:]' + scope: keyword.operator.ternary.powershell - match: ; scope: punctuation.terminator.statement.powershell - - match: \`(?=\n|$) - scope: punctuation.separator.continuation.line.powershell - - match: ',' - scope: punctuation.separator.sequence.powershell - - match: '&|\B\.(?= )' - scope: keyword.operator.other.powershell + - include: comma-separators + - match: '&' + scope: keyword.operator.background.powershell - match: \.\.(?=\-?\d|\(|\$) # This is very imprecise. Is there a syntax for 'must come after...'? scope: keyword.operator.range.powershell - comments: - - include: comment-block - - include: comment-line + assignment-normal: + - match: = + scope: keyword.operator.assignment.powershell + push: in-assignment + + in-assignment: + - include: command-ending-sequences + # INFO: Someday maybe we can nix the workflow stuff + - include: workflow-execution-contexts + - include: expressions redirection: # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection @@ -237,319 +950,204 @@ contexts: # - match: <+ # scope: invalid.illegal.powershell - requires-directive: - # TODO: add back `(?<=#)`-equivalent match - - match: (#)((?i:requires))\s - captures: - 1: punctuation.definition.keyword.powershell - 2: keyword.control.import.require.powershell - push: - - meta_scope: meta.requires.powershell - - include: pop-at-newline - - include: hashtable - - match: (-)(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) - scope: variable.parameter.option.powershell - captures: - 1: punctuation.definition.variable.powershell - - match: ',' - scope: punctuation.separator.powershell +###[ DATA BLOCK ]############################################################## - using-directive: - - match: \b(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+)) - captures: - 1: keyword.control.using.powershell - 2: keyword.other.powershell - 3: variable.parameter.powershell + data-blocks: + - match: \b(?i:data){{kebab_break}} + scope: keyword.control.context.powershell + push: [data-block-body, data-block-name] - attribute: - - 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.brackets.begin.powershell - 2: support.function.attribute.powershell - push: - - meta_scope: meta.attribute.powershell - - match: \] - scope: punctuation.section.brackets.end.powershell - pop: true - - match: \( - scope: punctuation.section.group.begin.powershell - push: - - match: \) - scope: punctuation.section.group.end.powershell - pop: true - - include: variable - - include: variable-no-property - - include: hashtable - - include: script-block - - include: escape-characters - - include: double-quoted-string - - include: type - - include: numeric-constant - - include: main - - match: |- - (?xi: - \b( - Mandatory | ValueFromPipeline(?:ByPropertyName)? - | ValueFromRemainingArguments | Position(?:alBinding)? - | (?:Default)?ParameterSetName | SupportsShouldProcess | SupportsPaging - | HelpUri | ConfirmImpact | HelpMessage - )\b - \s*(=)? - ) - captures: - 1: variable.parameter.attribute.powershell - 2: keyword.operator.assignment.powershell - - match: \' - scope: punctuation.definition.string.begin.powershell - push: - - meta_scope: string.quoted.single.powershell - - match: \'\' - scope: constant.character.escape.powershell - - match: \' - scope: punctuation.definition.string.end.powershell - pop: true + data-block-name: + - match: '{{identifier_simple}}' + scope: entity.name.section.powershell + pop: 1 + - include: else-pop - commands: - # "Verb-Noun pattern:" - - match: |- - (?x: - (?:[\w\\:-]*\\)? # Path stuff - \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 - ) - scope: meta.function-call.powershell support.function.powershell - # Builtin cmdlets with reserved verbs - - match: \b(?i:(?:foreach|where|sort|tee)-object)\b - scope: support.function.powershell + data-block-body: + - meta_scope: meta.block.data.powershell + - match: \{ + scope: punctuation.section.block.begin.powershell + push: inside-data-block + - include: else-pop - comment-block: - - match: <# - scope: punctuation.definition.comment.block.begin.powershell - push: - - meta_scope: comment.block.powershell - - match: '#>' - scope: punctuation.definition.comment.block.end.powershell - pop: true - - include: comment-embedded-docs + inside-data-block: + - match: \} + scope: punctuation.section.block.end.powershell + pop: 2 + # Data sections use a subset of Pwsh, but we don't distinguish yet. + - include: statements - comment-embedded-docs: - # TODO - # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help - - match: |- - (?xi: - ^\s*(\.) - ( - Component | Description | Example | ExternalHelp | ForwardHelpCategory | ForwardHelpTargetName - | Functionality | Inputs | Link | Notes | Outputs | Parameter | RemoteHelpRunSpace - | Role | Synopsis - ) - ) - scope: comment.documentation.embedded.powershell +###[ CONSTANTS ]############################################################### + + constants: + - match: (?i)(\$)True\b + scope: constant.language.boolean.true.powershell captures: - 1: punctuation.definition.keyword.documentation.powershell - 2: keyword.other.documentation.powershell - - match: ^\s*(\.)(?i:(Parameter)\s+([a-z0-9-_]+)) - scope: comment.documentation.embedded.powershell + 1: punctuation.definition.variable.powershell + - match: (?i)(\$)False\b + scope: constant.language.boolean.false.powershell captures: - 1: punctuation.definition.keyword.documentation.powershell - 2: keyword.other.documentation.param.powershell - 3: variable.parameter.powershell - - match: ^\s*(\.)(?i:(ForwardHelpTargetName|ForwardHelpCategory|ExternalHelp|Link)\s+([a-z0-9-_]+)) - scope: comment.documentation.embedded.powershell + 1: punctuation.definition.variable.powershell + - match: (?i)(\$)Null\b + scope: constant.language.null.powershell captures: - 1: punctuation.definition.keyword.documentation.powershell - 2: keyword.other.documentation.powershell - 3: markup.underline.link.powershell - - comment-line: - - include: requires-directive - - match: '#' - scope: punctuation.definition.comment.powershell - push: - - meta_scope: comment.line.powershell - - include: pop-at-newline - - include: comment-embedded-docs + 1: punctuation.definition.variable.powershell - static-members: - # - meta_content_scope: debug.in.static-members - - match: '::' - scope: punctuation.accessor.double-colon.powershell - set: members +###[ LITERALS ]################################################################ - 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 + literals: + - include: strings + - include: numbers strings: - - include: double-quoted-string - - include: single-quoted-string - - match: \@"(?=$) - scope: punctuation.definition.string.begin.powershell - push: - - meta_scope: meta.string.powershell string.quoted.double.heredoc.powershell - - match: ^"@ - scope: punctuation.definition.string.end.powershell - pop: true - - include: escape-characters - - include: interpolation - - match: \@'(?=$) + - include: double-quoted-strings + - include: single-quoted-strings + - include: double-quoted-heredoc-strings + - include: single-quoted-heredoc-strings + + expect-regex-string: + - match: '{{single_quote}}' + scope: meta.string.powershell string.quoted.single.powershell punctuation.definition.string.begin.powershell + embed: scope:source.regexp + embed_scope: meta.string.powershell source.regexp.embedded + escape: ({{single_quote}}) + escape_captures: + 1: meta.string.powershell string.quoted.single.powershell punctuation.definition.string.end.powershell + - include: comma-separators + - include: else-pop + - include: pop-eol + + single-quoted-strings: + - match: '{{single_quote}}' scope: punctuation.definition.string.begin.powershell - push: - - meta_scope: meta.string.powershell string.quoted.single.heredoc.powershell - - match: ^'@ - scope: punctuation.definition.string.end.powershell - pop: true - - match: "''" - scope: constant.character.escape.powershell + push: inside-single-quoted-string + + inside-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.powershell string.quoted.single.powershell + - match: '{{single_quote}}{2}' + scope: constant.character.escape.powershell + - match: '{{single_quote}}' + scope: punctuation.definition.string.end.powershell + pop: 1 + - include: string-placeholders - single-quoted-string: - - match: \' + double-quoted-strings: + - match: '{{double_quote}}' scope: punctuation.definition.string.begin.powershell - push: - - meta_scope: meta.string.powershell string.quoted.single.powershell - - match: "''" - scope: constant.character.escape.powershell - - match: \' - scope: punctuation.definition.string.end.powershell - pop: true + push: inside-double-quoted-string + + inside-double-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell + - match: '{{double_quote}}{2}' + scope: constant.character.escape.powershell + - include: escape-sequences + - match: '{{double_quote}}' + scope: punctuation.definition.string.end.powershell + pop: 1 + - include: string-interpolations + - include: string-placeholders - double-quoted-string: - - match: '"' + single-quoted-heredoc-strings: + - match: \@{{single_quote}}(?=$) scope: punctuation.definition.string.begin.powershell push: - - meta_scope: meta.string.powershell string.quoted.double.powershell - - match: '""' + - inside-single-quoted-heredoc-string + - inside-single-quoted-heredoc-string.syntax + + inside-single-quoted-heredoc-string.syntax: + - meta_include_prototype: false + - match: (?={{csharp_indicator}}) + set: scope:source.cs + with_prototype: + - match: (?=^{{single_quote}}@) + pop: 1 + - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell - - include: escape-characters - - match: '"' - scope: punctuation.definition.string.end.powershell - pop: true - - match: '(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b' - - include: interpolation - - match: '`\s*$' - scope: keyword.other.powershell - - escape-characters: - - match: '`[0abenfrvt"''$`]' - scope: constant.character.escape.powershell - - match: '`u\{\h+\}' + - include: else-pop + + inside-single-quoted-heredoc-string: + - meta_include_prototype: false + - meta_scope: meta.string.powershell string.quoted.single.heredoc.powershell + - match: ^{{single_quote}}@ + scope: punctuation.definition.string.end.powershell + pop: 1 + - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell + - include: string-placeholders - function: - - match: ^(?:\s*)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) - scope: meta.function.powershell - captures: - 1: storage.type.powershell - 2: storage.modifier.scope.powershell - 3: entity.name.function.powershell + double-quoted-heredoc-strings: + - match: \@{{double_quote}}(?=$) + scope: punctuation.definition.string.begin.powershell push: - - match: (?=\{|\() - pop: true - - include: comment-line + - inside-double-quoted-heredoc-string + - inside-double-quoted-heredoc-string.syntax - hashtable: - - match: (@)(\{) - captures: - 1: keyword.other.hashtable.begin.powershell - 2: punctuation.section.braces.begin.powershell - push: - - meta_scope: meta.hashtable.powershell - - match: \} - scope: 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: script-block - - include: main - - group: - - match: \( - scope: punctuation.section.group.begin.powershell - push: - - meta_scope: meta.group.powershell - - match: \) - scope: punctuation.section.group.end.powershell - pop: true - - include: main + inside-double-quoted-heredoc-string: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.powershell string.quoted.double.heredoc.powershell + - match: ^{{double_quote}}@ + scope: punctuation.definition.string.end.powershell + pop: 1 + - include: escape-sequences + - include: string-placeholders + - include: string-interpolations + + inside-double-quoted-heredoc-string.syntax: + - meta_include_prototype: false + - match: (?={{csharp_indicator}}) + set: scope:source.cs + with_prototype: + - match: (?=^{{double_quote}}@) + pop: 1 + - include: escape-sequences + - include: else-pop - interpolation: + string-interpolations: - match: \$\( scope: punctuation.section.interpolation.begin.powershell push: - clear_scopes: 1 + - meta_include_prototype: false - meta_scope: meta.interpolation.powershell - meta_content_scope: source.powershell.embedded - match: \) scope: punctuation.section.interpolation.end.powershell - pop: true - - include: main + pop: 1 + - include: expressions - match: (?=\$) push: - clear_scopes: 1 + - meta_include_prototype: false - meta_scope: meta.interpolation.powershell - - include: variable-no-property - - include: variable - - match: '' - pop: true + - include: variables-without-members + - include: immediately-pop + + string-placeholders: + - match: \{ + scope: punctuation.definition.placeholder.begin.powershell + push: inside-string-placeholder + + inside-string-placeholder: + - meta_include_prototype: false + - meta_scope: constant.other.placeholder.powershell + - match: \} + scope: punctuation.definition.placeholder.end.powershell + pop: 1 + - match: (?={{single_quote}}|{{double_quote}}) + pop: 1 + - match: '[:,;]' + scope: punctuation.separator.powershell + + string-wildcards: + - match: \* + scope: constant.other.wildcard.asterisk.powershell + - match: \? + scope: constant.other.wildcard.questionmark.powershell - numeric-constant: + numbers: + # Binary numbers - match: \b(0[bB])([01]*)({{int_suffix}}?{{unit_suffix}}?) scope: meta.number.integer.binary.powershell captures: @@ -557,6 +1155,7 @@ contexts: 2: constant.numeric.value.powershell 3: constant.numeric.suffix.powershell push: members + # Hexadecimal numbers - match: \b(0[xX])(\h*)({{int_suffix}}?{{unit_suffix}}?) scope: meta.number.integer.hexadecimal.powershell captures: @@ -564,6 +1163,7 @@ contexts: 2: constant.numeric.value.powershell 3: constant.numeric.suffix.powershell push: members + # Floats - match: |- (?x) ( @@ -588,12 +1188,14 @@ contexts: 7: punctuation.separator.decimal.powershell 8: constant.numeric.suffix.powershell push: members + # "Decimal" numbers - match: \b(\d+)({{dec_suffix}}{{unit_suffix}}?) scope: meta.number.float.decimal.powershell captures: 1: constant.numeric.value.powershell 2: constant.numeric.suffix.powershell push: members + # Integers - match: \b(\d+)({{int_suffix}}?{{unit_suffix}}?) scope: meta.number.integer.decimal.powershell captures: @@ -601,214 +1203,13 @@ contexts: 2: constant.numeric.suffix.powershell push: members - script-block: - - match: (%)?(\{) - captures: - 1: keyword.control.loop.for.powershell - 2: punctuation.section.braces.begin.powershell - push: - - 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.brackets.begin.powershell - push: - - match: \](?=::) - scope: punctuation.section.brackets.end.powershell - set: static-members - - match: \] - scope: punctuation.section.brackets.end.powershell - pop: true - - match: (?!\d+|\.)[\p{L}\p{N}.]+ - scope: storage.type.powershell - - include: main - - variable: - - match: (\$)(?i:True|False|Null)\b - scope: constant.language.powershell - captures: - 1: punctuation.definition.variable.powershell - - match: |- - (?xi: - (\$) - (?: - 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 - push: members - - match: |- - (?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: punctuation.definition.variable.powershell - push: members - - match: |- - (?xi: - (\$) - (?: - (?: - 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 - 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 - 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 - 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 - 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 - push: members - - variable-no-property: - - match: (\$)(?i:True|False|Null)\b - scope: constant.language.powershell - captures: - 1: punctuation.definition.variable.powershell - - match: |- - (?xi: - (\$) - (?: - 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: |- - (?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: punctuation.definition.variable.powershell - - match: |- - (?xi: - (\$) - (?: - (?: - 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 - - match: (?i:(\$|@)(global|local|private|script|using|workflow):(\w+)) - captures: - 1: punctuation.definition.variable.powershell - 2: storage.modifier.scope.powershell - 3: variable.other.readwrite.powershell - - match: (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) - captures: - 1: punctuation.definition.variable.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: - 1: punctuation.definition.variable.powershell - 2: support.variable.drive.powershell - - match: (?i:(\$)(\{)(\w+:)?([^}]*[^}`])(\})) - captures: - 1: punctuation.definition.variable.powershell - 2: punctuation.section.braces.begin - 3: support.variable.drive.powershell - 4: variable.other.readwrite.powershell - 5: punctuation.section.braces.end +###[ LABELS ]################################################################## - class-method: - - match: ^(?:\s*)(?i)(hidden|static)?\s*(\[)((?!\d+|\.)[\p{L}\p{N}.]+)(\])\s*((?:\p{L}|\d|_|-|\.)+)\s*(?=\() - scope: meta.function.powershell + labels: + - match: ^\s*((:){{identifier_simple}}) captures: - 1: storage.modifier.powershell - 2: punctuation.section.brackets.begin.powershell - 3: storage.type.powershell - 4: punctuation.section.brackets.end.powershell - 5: entity.name.function.powershell - push: - - match: (?=\() - pop: true - - include: comment-line + 1: entity.name.label.powershell + 2: punctuation.definition.label.powershell regions: - match: ^\s*((#)\s*(region\b)(?:\s*(\S.*))?(\n?)) @@ -824,3 +1225,228 @@ contexts: 2: punctuation.definition.comment.powershell 3: keyword.other.region.end.powershell 4: meta.fold.end.powershell + +###[ COMMENTS ]################################################################ + + comments: + - include: comment-block + - include: comment-line + + comment-block: + - match: <# + scope: punctuation.definition.comment.block.begin.powershell + push: + - meta_scope: comment.block.powershell + - match: '#>' + scope: punctuation.definition.comment.block.end.powershell + pop: 1 + - include: comment-embedded-docs + + comment-embedded-docs: + # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help + - 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|ExternalHelp|Link)\s+([a-z0-9-_:/.&]+)) + scope: comment.documentation.embedded.powershell + captures: + 1: punctuation.definition.keyword.documentation.powershell + 2: keyword.other.documentation.powershell + 3: markup.underline.link.powershell + - match: ^\s*(\.)(?i:(ForwardHelpCategory)\s+({{doc_fwdhelp_cat}})) + scope: comment.documentation.embedded.powershell + captures: + 1: punctuation.definition.keyword.documentation.powershell + 2: keyword.other.documentation.powershell + 3: support.type.powershell + - match: ^\s*(\.)({{doc}}) + scope: comment.documentation.embedded.powershell + captures: + 1: punctuation.definition.keyword.documentation.powershell + 2: keyword.other.documentation.powershell + + comment-line: + - match: '#(?!(?i:requires|(?:end)?region)\b)' + scope: punctuation.definition.comment.powershell + push: + - meta_scope: comment.line.powershell + - include: pop-eol + - include: comment-embedded-docs + +###[ COMPONENTS ]############################################################## + + path-punctuation: + - match: '[:/\\.]+' + scope: punctuation.separator.powershell + + line-continuations: + - match: (`)\n + captures: + 1: punctuation.separator.continuation.line.powershell + push: line-continuation-body + - match: '`(\s+)\n' + captures: + 1: invalid.illegal.unexpected-whitespace.powershell + + line-continuation-body: + - match: ^(?!\s*#) + pop: 1 + + comma-separators: + - match: ',' + scope: punctuation.separator.sequence.powershell + + escape-sequences: + - match: '`(?:[0abenfrvt$`]|{{single_quote}}|{{double_quote}})' + scope: constant.character.escape.powershell + - match: '`u\{\h+\}' + scope: constant.character.escape.powershell + + pop-eol: + - match: $\n? + pop: 1 + + pop-before-eol: + - match: (?=$) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + else-pop: + - match: (?=\S) + pop: 1 + +############################################################################### + +variables: + kebab_break: (?![\w-]) + builtin_types: |- + \b(?x: + void | null | object | bool | char | string + | int (?:32|64)? | long | byte | float | double | decimal + | array | hashtable + )\b + shebang_language: \b(?:pwsh|powershell)\b + + # Attributes + attributes: |- + \b(?xi: + CmdletBinding | Alias | OutputType | Parameter + | Validate + (?: Count | NotNull (?:OrEmpty)? | Range | Pattern | Length | Set | Script) + | Allow (?: Null | Empty (?: Collection | String )) + )\b + attribute_parameters: |- + \b(?xi: + Mandatory | ValueFromPipeline (?:ByPropertyName)? + | ValueFromRemainingArguments | Position(?:alBinding)? + | (?:Default)? ParameterSetName | SupportsShouldProcess | SupportsPaging + | HelpUri | ConfirmImpact | HelpMessage + )\b + + # Numbers + dec_exponent: (?:[eE][-+]?\d*) + dec_suffix: '[dD]' + float_suffix: '[dDlL]' + int_suffix: (?i:u[lsy]?|[lnsy]) + unit_suffix: (?i:[kmgtp]b\b) + + # Variables + # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_variables + identifier_simple: '[\p{L}\p{Nd}_?]+' + identifier_special: '[^}]*[^}`]' + identifier_function: '[\p{L}\p{Nd}_.-]+' + identifier_csharp: '[\p{L}_][\p{L}\p{Nd}_]*' + var_lookahead: |- + (?x: (?= + \$[$^{] + | [$@]{{identifier_simple}} + )) + # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables + var_constants: |- + \b(?xi: + (?: + ExecutionContext | Host | Home | IsCoreCLR | IsLinux | IsWindows + | IsMacOS | PID | Profile | PsCommandPath | PsHome | PsScriptRoot + | PsUiCulture | PsVersionTable | ShellID + ) + )\b + var_language: |- + (?xi: + [$^?_] + | \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 + | (?: + Confirm | Debug | ErrorAction | Information | Progress # *Preference + | Verbose | 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 + )\b + ) + var_scope_mod: (?i:global|local|private|script|using|workflow) + + # The "Approved Verbs" list + # https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands + command_verbs: |- + \b(?xi: + # Common verbs + Add | Clear | Close | Copy | Enter | Exit | Find | Format | Get | Hide + | Join | Lock | Move | New | Open | Optimize | Pop | Push | Redo | Remove + | Rename | Reset | Resize | Search | Select | Set | Show | Skip | Split + | Step | Switch | Undo | Unlock | Watch + # Communications verbs + | Connect | Disconnect | Read | Receive | Send | Write + # Data verbs + | Backup | Checkpoint | Compare | Compress | Convert | ConvertFrom + | ConvertTo | Dismount | Edit | Expand | Export | Group | Import + | Initialize | Limit | Merge | Mount | Out | Publish | Restore | Save + | Sync | Unpublish | Update + # Diagnostic verbs + | Debug | Measure | Ping | Repair | Resolve | Test | Trace + # Lifecycle verbs + | Approve | Assert | Build | Complete | Confirm | Deny | Deploy | Disable + | Enable | Install | Invoke | Register | Request | Restart | Resume | Start + | Stop | Submit | Suspend | Uninstall | Unregister | Wait + # Security verbs + | Block | Grant | Protect | Revoke | Unblock | Unprotect + # Other verbs + | Use + )\b + + # Documentation + doc: |- + (?xi: + Component | Description | Example | ExternalHelp | ForwardHelpCategory + | ForwardHelpTargetName | Functionality | Inputs | Link | Notes | Outputs + | Parameter | RemoteHelpRunSpace | Role | Synopsis + ) + doc_fwdhelp_cat: |- + (?x: + Alias | Cmdlet | HelpFile | Function | Provider | General | FAQ + | Glossary | ScriptCommand | ExternalScript | Filter | All + ) + + # Strings + single_quote: "['‘’‚]" + double_quote: '["“”„]' + csharp_indicator: |- + (?x: \s* (?: + using\s+System[.;] + | public\s+class\s+ + | \[DllImport\b + )) diff --git a/Tests/syntax_test_Class.ps1 b/Tests/syntax_test_Class.ps1 index fe41a23c..90775389 100644 --- a/Tests/syntax_test_Class.ps1 +++ b/Tests/syntax_test_Class.ps1 @@ -1,133 +1,167 @@ # SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" using namespace system.management.automation -# <- keyword.control.using -# ^^^^^^^^^ keyword.other -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter +#^^^^ keyword.control.import.powershell +# ^^^^^^^^^ keyword.control.import.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell + +class Foo : Bar, Baz { } +#^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +#^^^^ keyword.declaration.class.powershell +# ^^^ entity.name.class.powershell +# @@@ definition +# ^ punctuation.separator.type.powershell +# ^^^ entity.other.inherited-class.powershell +# @@@ reference +# ^ punctuation.separator.sequence.powershell +# ^^^ entity.other.inherited-class.powershell +# @@@ reference +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell # Define a class class TypeName -# <- storage.type -# ^^^^^^^^ entity.name.class +#^^^^^^^^^^^^^ meta.class.powershell +#^^^^ keyword.declaration.class.powershell +# ^^^^^^^^ entity.name.class.powershell # @@@@@@@@ definition { # Property with validate set # <- punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line [ValidateSet("val1", "Val2")] - # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute - # <- 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.brackets.end +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^^ support.function.attribute.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.section.brackets.end.powershell [string] $P1 - # <- punctuation.section.brackets.begin - # ^^^^^ storage.type - # ^ punctuation.section.brackets.end - # ^ punctuation.definition.variable - # ^^ variable.other.readwrite +#^^^^^^^^^^^^^^^ meta.class.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell # Static property # <- punctuation.definition.comment # ^^^^^^^^^^^^^^^ comment.line static [hashtable] $P2 - #^^^^^ storage.modifier - # ^ punctuation.section.brackets.begin - # ^^^^^^^^^ storage.type - # ^ punctuation.section.brackets.end - # ^ punctuation.definition.variable - # ^^ variable.other.readwrite +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^ storage.modifier.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell # Hidden property does not show as result of Get-Member # <- punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line hidden [int] $P3 - #^^^^^ storage.modifier - # ^ punctuation.section.brackets.begin - # ^ storage.type - # ^ punctuation.section.brackets.end - # ^ punctuation.definition.variable - # ^^ variable.other.readwrite +#^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^ storage.modifier.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell # Constructor # <- punctuation.definition.comment # ^^^^^^^^^^^ comment.line TypeName ([string] $s) { - # ^ punctuation.section.group.begin - # ^ punctuation.section.brackets.begin - # ^^^^^^ storage.type - # ^ punctuation.section.brackets.end - # ^ punctuation.definition.variable - # ^ variable.other.readwrite - # ^ punctuation.section.group.end +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ entity.name.function.powershell +# @@@@@@@@ definition +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell $this.P1 = $s - # <- punctuation.definition.variable - # ^ variable.language - # ^^ variable.other.member - # ^ keyword.operator.assignment - # ^ punctuation.definition.variable - # ^ variable.other.readwrite +#^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell +# ^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^ variable.other.member.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell } - +# ^ - meta.function # Static method # <- punctuation.definition.comment # ^^^^^^^^^^^^^ comment.line static [void] MemberMethod1([hashtable] $h) { - # <- storage.modifier - # ^ punctuation.section.brackets.begin - # ^^^^ storage.type - # ^ punctuation.section.brackets.end - # ^^^^^^^^^^^^^ entity.name.function - # @@@@@@@@@@@@@ definition - # ^ punctuation.section.group.begin - # ^ punctuation.section.brackets.begin - # ^^^^^^^^^ storage.type - # ^ punctuation.section.brackets.end - # ^ punctuation.definition.variable - # ^ variable.other.readwrite - # ^ punctuation.section.group.end +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^ storage.modifier.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^ entity.name.function.powershell +# @@@@@@@@@@@@@ definition +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell [TypeName]::P2 = $h - # <- punctuation.section.brackets.begin - # ^ storage.type - # ^ punctuation.section.brackets.end - # ^^ punctuation.accessor.double-colon - # ^^ variable.other.member - # ^ keyword.operator.assignment - # ^ punctuation.definition.variable - # ^ variable.other.readwrite +#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^ variable.other.member.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell } # Instance method # <- punctuation.definition.comment # ^^^^^^^^^^^^^^^ comment.line [int] MemberMethod2([int] $i) { - # <- punctuation.section.brackets.begin - # ^ storage.type - # ^ punctuation.section.brackets.end - # ^^^^^^^^^^^^^ entity.name.function - # @@@@@@@@@@@@@ definition - # ^ punctuation.section.group.begin - # ^ punctuation.section.brackets.begin - # ^^^ storage.type - # ^ punctuation.section.brackets.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 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^ entity.name.function.powershell +# @@@@@@@@@@@@@ definition +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell return $this.P3 - # <- keyword.control - # ^ punctuation.definition.variable - # ^^^^ variable.language - # ^^ variable.other.member +#^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell +# ^^^^^^ keyword.control.flow.return.powershell +# ^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^ variable.other.member.powershell } } @@ -136,3 +170,309 @@ class TypeName $object.MemberMethod2() # @@@@@@@@@@@@@ reference + + +# PowerShell documentation examples +# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes + +# Example 1 - Minimal definition +class Device { +# @@@@@@ definition + [string]$Brand +} + +$dev = [Device]::new() +# @@@ reference +$dev.Brand = "Fabrikam, Inc." +$dev + + +# Example 2 - Class with instance members +class Book { +# @@@@ definition + # Class properties + [string] $Title + [string] $Author + [string] $Synopsis + [string] $Publisher + [datetime] $PublishDate + [int] $PageCount + [string[]] $Tags + # Default constructor + Book() { $this.Init(@{}) } +# @@@@ definition +# @@@@ reference + # Convenience constructor from hashtable + Book([hashtable]$Properties) { $this.Init($Properties) } +# @@@@ definition +# @@@@ reference + # Common constructor for title and author + Book([string]$Title, [string]$Author) { +# @@@@ definition + $this.Init(@{Title = $Title; Author = $Author }) +# @@@@ reference + } + # Shared initializer method + [void] Init([hashtable]$Properties) { +# @@@@ definition + foreach ($Property in $Properties.Keys) { + $this.$Property = $Properties.$Property + } + } + # Method to calculate reading time as 2 minutes per page + [timespan] GetReadingTime() { +# @@@@@@@@@@@@@@ definition + if ($this.PageCount -le 0) { + throw 'Unable to determine reading time from page count.' + } + $Minutes = $this.PageCount * 2 + return [timespan]::new(0, $Minutes, 0) +# @@@ reference + } + # Method to calculate how long ago a book was published + [timespan] GetPublishedAge() { +# @@@@@@@@@@@@@@@ definition + if ( + $null -eq $this.PublishDate -or + $this.PublishDate -eq [datetime]::MinValue + ) { throw 'PublishDate not defined' } + + return (Get-Date) - $this.PublishDate +# @@@@@@@@ reference + } + # Method to return a string representation of the book + [string] ToString() { +# @@@@@@@@ definition + return "$($this.Title) by $($this.Author) ($($this.PublishDate.Year))" + } +} + +[BookList]::Add([Book]::new(@{ +# @@@ reference +# @@@ reference + Title = 'The Fellowship of the Ring' + Author = 'J.R.R. Tolkien' + Publisher = 'George Allen & Unwin' + PublishDate = '1954-07-29' + PageCount = 423 + Tags = @('Fantasy', 'Adventure') +})) + +[BookList]::Find({ +# @@@@ reference + param ($b) + + $b.PublishDate -gt '1950-01-01' +}).Title + +[BookList]::FindAll({ +# @@@@@@@ reference + param($b) + + $b.Author -match 'Tolkien' +}).Title + +[BookList]::Remove($Book) +# @@@@@@ reference +[BookList]::Books.Title + +[BookList]::RemoveBy('Author', 'J.R.R. Tolkien') +# @@@@@@@@ reference +"Titles: $([BookList]::Books.Title)" + +[BookList]::Add($Book) +# @@@ reference +[BookList]::Add($Book) +# @@@ reference + + +# Example 3 - Class with static members +class BookList { +# @@@@@@@@ definition + # Static property to hold the list of books + static [System.Collections.Generic.List[Book]] $Books + # Static method to initialize the list of books. Called in the other + # static methods to avoid needing to explicit initialize the value. + static [void] Initialize() { [BookList]::Initialize($false) } +# @@@@@@@@@@ definition +# @@@@@@@@@@ reference + static [bool] Initialize([bool]$Force) { +# @@@@@@@@@@ definition + if ([BookList]::Books.Count -gt 0 -and -not $Force) { + return $false + } + + [BookList]::Books = [System.Collections.Generic.List[Book]]::new() +# @@@ reference + + return $true + } + # Ensure a book is valid for the list. + static [void] Validate([book]$Book) { +# @@@@@@@@ definition + $Prefix = @( + 'Book validation failed: Book must be defined with the Title,' + 'Author, and PublishDate properties, but' + ) -join ' ' + if ($null -eq $Book) { throw "$Prefix was null" } + if ([string]::IsNullOrEmpty($Book.Title)) { +# @@@@@@@@@@@@@ reference + throw "$Prefix Title wasn't defined" + } + if ([string]::IsNullOrEmpty($Book.Author)) { +# @@@@@@@@@@@@@ reference + throw "$Prefix Author wasn't defined" + } + if ([datetime]::MinValue -eq $Book.PublishDate) { + throw "$Prefix PublishDate wasn't defined" + } + } + # Static methods to manage the list of books. + # Add a book if it's not already in the list. + static [void] Add([Book]$Book) { +# @@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + [BookList]::Validate($Book) +# @@@@@@@@ reference + if ([BookList]::Books.Contains($Book)) { +# @@@@@@@@ reference + throw "Book '$Book' already in list" + } + + $FindPredicate = { + param([Book]$b) + + $b.Title -eq $Book.Title -and + $b.Author -eq $Book.Author -and + $b.PublishDate -eq $Book.PublishDate + }.GetNewClosure() +#^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell +#^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@ reference +# ^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^ punctuation.section.arguments.end.powershell + if ([BookList]::Books.Find($FindPredicate)) { +# @@@@ reference + throw "Book '$Book' already in list" + } + + [BookList]::Books.Add($Book) +# @@@ reference + } + # Clear the list of books. + static [void] Clear() { +# @@@@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + [BookList]::Books.Clear() +# @@@@@ reference + } + # Find a specific book using a filtering scriptblock. + static [Book] Find([scriptblock]$Predicate) { +# @@@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + return [BookList]::Books.Find($Predicate) +# @@@@ reference + } + # Find every book matching the filtering scriptblock. + static [Book[]] FindAll([scriptblock]$Predicate) { +# @@@@@@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + return [BookList]::Books.FindAll($Predicate) +# @@@@@@@ reference + } + # Remove a specific book. + static [void] Remove([Book]$Book) { +# @@@@@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + [BookList]::Books.Remove($Book) +# @@@@@@ reference + } + # Remove a book by property value. + static [void] RemoveBy([string]$Property, [string]$Value) { +# @@@@@@@@ definition + [BookList]::Initialize() +# @@@@@@@@@@ reference + $Index = [BookList]::Books.FindIndex({ +# @@@@@@@@@ reference + param($b) + $b.$Property -eq $Value + }.GetNewClosure()) +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell meta.function-call.arguments.powershell +#^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@ reference +# ^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^ punctuation.section.arguments.end.powershell +# ^ punctuation.section.arguments.end.powershell + if ($Index -ge 0) { + [BookList]::Books.RemoveAt($Index) +# @@@@@@@@ reference + } + } +} + + +# Example 4 - Class definition with and without Runspace affinity + +# Class definition with Runspace affinity (default behavior) +class UnsafeClass { +# @@@@@@@@@@@ definition + static [Object] ShowRunspaceId($Val) { +# @@@@@@@@@@@@@@ definition + return [pscustomobject]@{ + ThreadId = [Threading.Thread]::CurrentThread.ManagedThreadId + RunspaceId = [runspace]::DefaultRunspace.Id + } + } +} + +$unsafe = [UnsafeClass]::new() +# @@@ reference + +while ($true) { + 1..10 | ForEach-Object -Parallel { +# @@@@@@@@@@@@@@ reference + Start-Sleep -ms 100 +# @@@@@@@@@@@ reference + ($Using:unsafe)::ShowRunspaceId($_) +# @@@@@@@@@@@@@@ reference + } +} + +# Class definition with NoRunspaceAffinity attribute +[NoRunspaceAffinity()] +class SafeClass { +# @@@@@@@@@ definition + static [Object] ShowRunspaceId($Val) { +# @@@@@@@@@@@@@@ definition + return [pscustomobject]@{ + ThreadId = [Threading.Thread]::CurrentThread.ManagedThreadId + RunspaceId = [runspace]::DefaultRunspace.Id + } + } +} + +$safe = [SafeClass]::new() +# @@@ reference + +while ($true) { + 1..10 | ForEach-Object -Parallel { +# @@@@@@@@@@@@@@ reference + Start-Sleep -ms 100 +# @@@@@@@@@@@ reference + ($Using:safe)::ShowRunspaceId($_) +# @@@@@@@@@@@@@@ reference + } +} diff --git a/Tests/syntax_test_DSC.ps1 b/Tests/syntax_test_DSC.ps1 new file mode 100644 index 00000000..ff66f2e4 --- /dev/null +++ b/Tests/syntax_test_DSC.ps1 @@ -0,0 +1,116 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + +"<- Exit the imports context block" + + Configuration MyDscConfiguration { +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^^^^^^ entity.name.function.powershell +# ^ punctuation.section.block.begin.powershell + Node "TEST-PC1" { +#^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^ keyword.context.block.powershell +# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.block.begin.powershell + WindowsFeature MyFeatureInstance { +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^ keyword.other.powershell +# ^^^^^^^^^^^^^^^^^ entity.name.label.powershell +# ^ meta.block.powershell punctuation.section.braces.begin.powershell + Ensure = 'Present' +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.block.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + Name = 'RSAT' + } + WindowsFeature My2ndFeatureInstance { +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^ keyword.other.powershell +# ^^^^^^^^^^^^^^^^^^^^ entity.name.label.powershell +# ^ meta.block.powershell punctuation.section.braces.begin.powershell + Ensure = 'Present' + Name = 'Bitlocker' + } +#^^^^^^^^^^^^ meta.function.powershell meta.block.powershell +# ^ punctuation.section.braces.end.powershell + } + } + MyDscConfiguration + + + Configuration MyDscConfiguration + { + param +#^^^^^^^^^^^^ meta.function.powershell +# ^^^^^ keyword.declaration.parameter.powershell + ( + [string[]]$ComputerName='localhost' +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + ) + + Node $ComputerName + { + WindowsFeature MyFeatureInstance + { + Ensure = 'Present' + Name = 'RSAT' + } + + WindowsFeature My2ndFeatureInstance + { + Ensure = 'Present' + Name = 'Bitlocker' + } + } + } + MyDscConfiguration + + + Configuration MyDscConfiguration + { + Node @('localhost', 'Server01') +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^ keyword.context.block.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell +# ^ keyword.other.array.begin.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell + { + WindowsFeature MyFeatureInstance +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^ keyword.other.powershell +# ^^^^^^^^^^^^^^^^^ entity.name.label.powershell + { + Ensure = 'Present' + Name = 'RSAT' + } + + WindowsFeature My2ndFeatureInstance + { + Ensure = 'Present' + Name = 'Bitlocker' + } + } + } + MyDscConfiguration diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 index f79bfdc7..a01002db 100644 --- a/Tests/syntax_test_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -1,9 +1,11 @@ # SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" using module Microsoft.Management -# <- keyword.control.using -# ^ keyword.other -# ^ variable.parameter +#^^^^ keyword.control.import.powershell +# ^^^^^^ keyword.control.import.powershell +# ^^^^^^^^^^^^^^^^^^^^ meta.path.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^ support.type.powershell function Test-Path {} # @@@@@@@@@ definition @@ -49,16 +51,34 @@ function Test-Path {} # <- punctuation.definition.keyword # ^ keyword.other.documentation The functionality that best describes this cmdlet + .ForwardHelpCategory Alias +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.powershell comment.documentation.embedded.powershell +# ^ punctuation.definition.keyword.documentation.powershell +# ^^^^^^^^^^^^^^^^^^^ keyword.other.documentation.powershell +# ^^^^^ support.type.powershell + + .parameter foo +#^^^^^^^^^^^^^^^^^ comment.block.powershell comment.documentation.embedded.powershell +# ^ punctuation.definition.keyword.documentation.powershell +# ^^^^^^^^^ keyword.other.documentation.param.powershell +# ^^^ variable.parameter.powershell + + .LINK https://example.com +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.block.powershell comment.documentation.embedded.powershell +# ^ punctuation.definition.keyword.documentation.powershell +# ^^^^ keyword.other.documentation.powershell +# ^^^^^^^^^^^^^^^^^^^ markup.underline.link.powershell This should not be considered documentaton -> .role # ^ - keyword.operator.documentation #> # <- punctuation.definition.comment.block.end function Verb-Noun { -#^^^^^^^^^^^^^^^^^ meta.function -#^^^^^^^ storage.type -# ^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@ definition +# ^ punctuation.section.block.begin.powershell [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', # <- meta.attribute punctuation.section.brackets.begin # ^ meta.attribute support.function.attribute @@ -93,18 +113,22 @@ function Verb-Noun { # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.brackets.end [OutputType([String])] - # <- meta.attribute punctuation.section.brackets.begin - # ^ meta.attribute support.function.attribute - # ^ meta.attribute punctuation.section.group.begin - # ^ meta.attribute punctuation.section.brackets.begin - # ^^^^^^ meta.attribute storage.type - # ^ meta.attribute punctuation.section.brackets.end - # ^ meta.attribute punctuation.section.group.end - # ^ meta.attribute punctuation.section.brackets.end +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^ support.function.attribute.powershell +# ^ punctuation.section.group.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.section.brackets.end.powershell Param - #^^^^^ keyword.declaration.parameter +#^^^^^^^^ meta.function.powershell +# ^^^^^ keyword.declaration.parameter.powershell ( - # <- punctuation.section.group.begin +#^^^^ meta.function.powershell +# ^ punctuation.section.block.begin.powershell # Param1 help description # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line @@ -264,13 +288,15 @@ function Verb-Noun { # ^ punctuation.section.group.end # ^ punctuation.section.brackets.end [int32] - # <- punctuation.section.brackets.begin - #^^^^^ storage.type - # ^ punctuation.section.brackets.end +#^^^^^^^^^^^^^^ meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell $Param2, - # <- punctuation.definition.variable - # ^ variable.other.readwrite - # ^ punctuation.separator +#^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.separator.sequence.powershell # Param3 help description # <- comment.line punctuation.definition.comment @@ -302,9 +328,10 @@ function Verb-Noun { # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.brackets.end [String] - # <- punctuation.section.brackets.begin - #^^^^^^ storage.type - # ^ punctuation.section.brackets.end +#^^^^^^^^^^^^^^^ meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell $Param3, # <- punctuation.definition.variable #^^^^^^ variable.other.readwrite @@ -335,9 +362,10 @@ function Verb-Noun { # ^ meta.attribute punctuation.section.group.end # ^ meta.attribute punctuation.section.brackets.end [string] - # <- punctuation.section.brackets.begin - # ^ storage.type - # ^ punctuation.section.brackets.end +#^^^^^^^^^^^^^^^ meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell $Param4, # <- punctuation.definition.variable # ^ variable.other.readwrite @@ -365,38 +393,61 @@ function Verb-Noun { # ^ comment.line punctuation.definition.comment # ^ comment.line [string] - # <- punctuation.section.brackets.begin - # ^ storage.type - # ^ punctuation.section.brackets.end +#^^^^^^^^^^^^^^^ meta.function.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell $Param5 # <- punctuation.definition.variable # ^ variable.other.readwrite - ) - # <- punctuation.section.group.end + ) +#^^^^ meta.function.powershell +# ^ punctuation.section.block.end.powershell Begin - #^^^^^ keyword.context.block.begin +#^^^^^^^^ meta.function.powershell +# ^^^^^ keyword.context.block.powershell { +#^^^^ meta.function.powershell +# ^ punctuation.section.block.begin.powershell } Process { - # <- keyword.context.block.process +#^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^ keyword.context.block.powershell +# ^ punctuation.section.block.begin.powershell if ($pscmdlet.ShouldProcess("Target", "Operation")) { - # <- keyword.control - # ^ punctuation.section.group.begin - # ^ punctuation.definition.variable - # ^^^^^^^^ variable.language - # ^^^^^^^^^^^^^ variable.function - # @@@@@@@@@@@@@ reference - # ^ punctuation.section.arguments.begin - # ^^^^^^^^ string.quoted.double - # ^ punctuation.separator - # ^^^^^^^^^^^ string.quoted.double - # ^ punctuation.section.arguments.end - # ^ punctuation.section.group.end +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^ keyword.control.conditional.if.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.arguments.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ meta.block.powershell punctuation.section.braces.begin.powershell } } End { - #^^^ keyword.context.block.end +#^^^^^^^^ meta.function.powershell +# ^^^ keyword.context.block.powershell +# ^ punctuation.section.block.begin.powershell } + clean { } +#^^^^^^^^^^^^ meta.function.powershell +# ^^^^^ keyword.context.block.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell } diff --git a/Tests/syntax_test_Pester.ps1 b/Tests/syntax_test_Pester.ps1 new file mode 100644 index 00000000..6dfbb125 --- /dev/null +++ b/Tests/syntax_test_Pester.ps1 @@ -0,0 +1,61 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + +BeforeAll { + # your function + function Get-Planet ([string]$Name='*') +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^ entity.name.function.powershell +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ keyword.operator.assignment.powershell +# ^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.parameters.end.powershell + { + $planets = @( + @{ Name = 'Mercury' } + @{ Name = 'Venus' } + @{ Name = 'Earth' } + @{ Name = 'Mars' } + @{ Name = 'Jupiter' } + @{ Name = 'Saturn' } + @{ Name = 'Uranus' } + @{ Name = 'Neptune' } + ) | foreach { [PSCustomObject]$_ } + + $planets | where { $_.Name -like $Name } + } +} + +# Pester tests +Describe 'Get-Planet' { + It "Given no parameters, it lists all 8 planets" { + $allPlanets = Get-Planet + $allPlanets.Count | Should -Be 8 + } + + Context "Filtering by Name" { + It "Given valid -Name '', it returns ''" -TestCases @( + @{ Filter = 'Earth'; Expected = 'Earth' } + @{ Filter = 'ne*' ; Expected = 'Neptune' } + @{ Filter = 'ur*' ; Expected = 'Uranus' } + @{ Filter = 'm*' ; Expected = 'Mercury', 'Mars' } + ) { + param ($Filter, $Expected) + + $planets = Get-Planet -Name $Filter + $planets.Name | Should -Be $Expected + } + + It "Given invalid parameter -Name 'Alpha Centauri', it returns `$null" { + $planets = Get-Planet -Name 'Alpha Centauri' + $planets | Should -Be $null + } + } +} diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index bb9d932a..87b38ae3 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -1,11 +1,14 @@ # SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" using namespace System.Management.Automation -# <- keyword.control.using -# ^ keyword.other -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter +#^^^^ keyword.control.import.powershell +# ^^^^^^^^^ keyword.control.import.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.path.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell + #Requires -PSSnapin DiskSnapin -Version 1.2 # <- punctuation.definition.keyword -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires #^^^^^^^^ keyword.control.import.require # ^^^^^^^^^ variable.parameter # ^^^^^^^^ variable.parameter @@ -65,177 +68,208 @@ using namespace System.Management.Automation # ^^^^^^^^ variable.parameter #Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"} # <- punctuation.definition.keyword -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 -# ^ 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 -# ^^^^^^^^ variable.function -# ^ punctuation.definition.parameter -# ^^^^^ variable.parameter.option -# ^ punctuation.definition.parameter -# ^^^^^ variable.parameter.option -# ^^^ keyword.control -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted - constant - variable - comment - -& gnutool.exe -s 'short option' --long-option --very_long_option value +plus-option -#<- keyword.operator.other -# ^^^^^^^^^^^ variable.function -# ^ variable.parameter.option punctuation.definition.parameter -# ^ variable.parameter.option -# ^^ variable.parameter.option punctuation.definition.parameter -# ^^ variable.parameter.option punctuation.definition.parameter -# ^^^^^^^^^^^^^^^^ variable.parameter.option -# ^ variable.parameter.option punctuation.definition.parameter -# ^^^^^^^^^^^ variable.parameter.option - -# 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 -#^^^^ variable.language -$error -# <- punctuation.definition.variable -# ^^^^ variable.language -$home -# <- punctuation.definition.variable -# ^^^ support.constant.variable -$foreach -# <- punctuation.definition.variable -#^^^^^^^ variable.language - -# Normal variables -$variable -# <- punctuation.definition.variable -# ^ variable.other.readwrite -$script:variable -# <- variable.other.readwrite punctuation.definition.variable -# ^ storage.modifier.scope -# ^ variable.other.readwrite -$ENV:ComputerName -# <- variable.other.readwrite punctuation.definition.variable -# ^ support.variable.drive -# ^ variable.other.readwrite -${variable} -# <- variable.other.readwrite punctuation.definition.variable - # <- punctuation.section.braces.begin -# ^^^^^^^^ variable.other.readwrite -# ^ punctuation.section.braces.end -${script:variable} -# <- variable.other.readwrite punctuation.definition.variable - # <- 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 -# ^ 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 -# @@@@@@ reference -# ^^^ 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 -#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string -#^^^^^^^^^^^ string.quoted.double -# ^^^^^^^^^ meta.interpolation variable.other.readwrite - string -# ^ punctuation.definition.variable -# ^^^^^^ 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.interpolation - string -# ^^ string.quoted.double - meta.interpolation -# ^^ punctuation.section.interpolation.begin -# ^^^^^^^^^ variable.other.readwrite -# ^ punctuation.definition.variable -# ^ 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 -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^^^^^^^^^^^^^^^^^ meta.interpolation - string -# ^ 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 -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string -#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^^^^^^^^^^^^^^^^^^^ meta.interpolation - string -# ^ punctuation.definition.variable -# ^ punctuation.section.braces.begin -# ^^^^ support.variable.drive -# ^^^^^^^^^^^^ variable.other.readwrite -# ^ punctuation.definition.string.end - -# The @splat references only work in argument mode, should not highlight in strings -"This is a @double quoted string." -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double -# ^ - punctuation.definition.variable -# ^^^^^^^ - variable - -# 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 -#^^^^^^^^^^^^^^^^^ meta.string string.quoted.single -# ^ punctuation.definition.string.end +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^^^^^^^ meta.mapping.key string.unquoted +# ^ punctuation.separator.key-value.powershell +# ^^^^^^^^^^^^^^^^ string.quoted.double +# ^ punctuation.terminator.statement +# ^^^^^^^^^^^^^ meta.mapping.key string.unquoted +# ^ punctuation.separator.key-value.powershell +# ^^^^^^^^^ string.quoted.double + + :label1 +# ^^^^^^^ entity.name.label.powershell +# ^ punctuation.definition.label.powershell + + throw "Do not run this file!" +# ^^^^^ keyword.control.exception.raise.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + # Stop parsing + & tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment +# ^ keyword.operator.call.powershell +# ^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.control.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.powershell + + & gnutool.exe -s 'short option' --long-option --very_long_option value +plus-option +# ^ keyword.operator.call.powershell +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^^^^^^^^ variable.parameter.option.powershell +# ^^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^^^^^^^^ variable.parameter.option.powershell +# ^^ punctuation.definition.parameter.powershell +# ^^^^^ string.unquoted.powershell +# ^^^^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + + $job = Get-Process -Name pwsh & +# ^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@ reference +# ^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^ string.unquoted.powershell +# ^ keyword.operator.background.powershell + Receive-Job $job -Wait +# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@ reference +# ^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + + # Constants + $true +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + $True +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + $TRUE +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + + $false +# ^^^^^^ constant.language.boolean.false.powershell +# ^ punctuation.definition.variable.powershell + $False +# ^^^^^^ constant.language.boolean.false.powershell +# ^ punctuation.definition.variable.powershell + $FALSE +# ^^^^^^ constant.language.boolean.false.powershell +# ^ punctuation.definition.variable.powershell + + $null +# ^^^^^ constant.language.null.powershell +# ^ punctuation.definition.variable.powershell + $Null +# ^^^^^ constant.language.null.powershell +# ^ punctuation.definition.variable.powershell + $NULL +# ^^^^^ constant.language.null.powershell +# ^ punctuation.definition.variable.powershell + + # Automatic variables + $_, $$, $^, $? +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.separator.sequence.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.separator.sequence.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.separator.sequence.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell + $args +# ^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell + $error +# ^^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell + $home +# ^^^^^ support.constant.variable.powershell +# ^ punctuation.definition.variable.powershell + $foreach +# ^^^^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell + + + # Normal variables + $variable +# ^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $script:variable +# ^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ storage.modifier.scope.powershell +# ^ punctuation.accessor.colon.powershell + $ENV:ComputerName +# ^^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ support.variable.drive.powershell +# ^ punctuation.accessor.colon.powershell +# ^^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell + ${variable} +# ^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^ punctuation.section.interpolation.end.powershell + ${vari-able} +# ^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^ punctuation.section.interpolation.end.powershell + ${var`iable} +# ^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.section.interpolation.end.powershell + ${variable`}} +# ^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.section.interpolation.end.powershell + ${script:variable} +# ^^^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^^^^^^ storage.modifier.scope.powershell +# ^ punctuation.accessor.colon.powershell +# ^ punctuation.section.interpolation.end.powershell + + + # Variable properties should be highlighted + $variable.Name +# ^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^ variable.other.member.powershell + + # Variable properties should be highlighted + $variable.Name.Method( ) +# ^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^ variable.other.member.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@ reference +# ^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^ punctuation.section.arguments.end.powershell # Hashtable $properties = @{ @@ -245,29 +279,44 @@ $properties = @{ # ^ 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 +#^^^^^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell Something = $else - # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite - # Atom-grammar-test is not tokenizing this correctly... Need to test in Atom - TODO +#^^^^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^^^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell Number = 16 - # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite - # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment - # ^^ meta.hashtable meta.number.integer.decimal constant.numeric.value +#^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell from = 'hello world' - # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite - # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment - # ^^^^^^^^^^^^^ meta.hashtable string.quoted.single +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell 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 +#^^^^^^^^^^^^^^^^^ meta.hashtable.powershell +# ^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^ meta.hashtable.powershell +# ^ keyword.other.hashtable.begin.powershell +# ^ punctuation.section.braces.begin.powershell hello = 'world' - # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite - # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment - # ^^^^^^^ meta.hashtable string.quoted.single +#^^^^^^^^^^^^^^^^^^^^^^ meta.hashtable.powershell meta.hashtable.powershell +# ^^^^^ meta.mapping.key.powershell string.unquoted.powershell +# ^ punctuation.separator.key-value.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell } # <- punctuation.section.braces.end } @@ -426,66 +475,6 @@ $a3[1..2] # ^ punctuation.section.brackets.end # ^^^^^^^^^^^^^^^ meta.brackets.indexer -# Single quoted strings - 'This is a single quoted string.' -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single - '$This is a single ''quoted'' string.' -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single -# ^^ constant.character.escape -# ^^ constant.character.escape - 'This is a - single quoted string.' -# ^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single - 'This #also' -# ^^^^^^^^^^^^ meta.string string.quoted.single - '$(Invoke-Something)' -# ^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single - meta.interpolation - variable - support - 'This "string" is nice.' -# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.single - -# Double quoted strings - "This is a double quoted string." -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double - "$This is a double ""quoted"" string." -# ^ 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." -# ^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double - "This #also" -# ^^^^^^^^^^^^ meta.string string.quoted.double - "$(Invoke-Something)" -# ^ meta.string string.quoted.double -# ^^^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string -# ^^ punctuation.section.interpolation.begin -# ^^^^^^^^^^^^^^^^ support.function -# ^ punctuation.section.interpolation.end -# @@@@@@@@@@@@@@@@ reference - "This 'string' is nice." -# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string 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! -# ^^^^^^^^^ - variable - punctuation -"@ -# <- string.quoted.double.heredoc - # <- string.quoted.double.heredoc -@' -#<- meta.string string.quoted.single.heredoc punctuation.definition.string.begin -A 'single quoted' "heredoc" -'@ -#<- meta.string string.quoted.single.heredoc punctuation.definition.string.end - # Numeric constants -3 +3 3 3l 3lm 3lmb @@ -536,6 +525,7 @@ A 'single quoted' "heredoc" # ^^ meta.number.float.decimal constant.numeric.value - constant constant # ^ punctuation.separator.decimal + # BUG: Don't mark the dot as a function 1. # ^ meta.number.integer.decimal constant.numeric.value # ^ - meta.number - constant.numeric @@ -749,162 +739,290 @@ A 'single quoted' "heredoc" # ^^ constant.numeric.value # ^^ constant.numeric.suffix -# Types -[string] -# <- punctuation.section.brackets.begin -# ^ storage.type -# ^ punctuation.section.brackets.end -[string[]] -# <- punctuation.section.brackets.begin -# ^ storage.type -# ^ punctuation.section.brackets.begin -# ^^ punctuation.section.brackets.end -[int32] -# <- punctuation.section.brackets.begin -# ^^^^ storage.type -# ^ punctuation.section.brackets.end -[System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] -# <- punctuation.section.brackets.begin -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.type -# ^^ punctuation.section.brackets.begin -# ^^^^^^^^^^^^^ storage.type -# ^^^^^^^^ storage.type -# ^ punctuation.section.brackets.end -# ^ punctuation.section.brackets.begin -# ^^^^^^^^^^^^^^^^ storage.type -# ^^^ punctuation.section.brackets.end -[System.Array+SZArrayEnumerator] -# <- punctuation.section.brackets.begin -# ^^^^^^^^^^^ storage.type -# ^^^^^^^^^^^^^^^^^ storage.type -# ^ keyword.operator -# ^ punctuation.section.brackets.end -[int]::MinValue -# <- punctuation.section.brackets.begin -# ^ storage.type -# ^ punctuation.section.brackets.end -# ^^ punctuation.accessor.double-colon -# ^^^^^^^^ variable.other.member -[System.DateTime]::Parse('2016/09/21') -# <- punctuation.section.brackets.begin -# ^^^^^^^^^^^^^^ storage.type -# ^ 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 - -# Commands (functions) - Invoke-Something -foobar -#^ support.function -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option -#@@@@@@@@@@@@@@@@ reference - Invoke-Something -foobar value -#^ support.function -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option -#@@@@@@@@@@@@@@@@ reference - Invoke-Something -foobar:$true -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option -# ^ punctuation.definition.variable -# ^^^^ constant.language - Invoke-Something -foobar: $true -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option - Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^^ meta.number.integer.decimal constant.numeric.value -# ^^^^^^ - keyword -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option - Invoke-Something (1..20 | Invoke-Something) -p2 'value' -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# @@@@@@@@@@@@@@@@ reference -# ^^ keyword.operator.range - Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch -#^ support.function -# @@@@@@@@@@@@@@@@ reference -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^^ meta.number.integer.decimal constant.numeric.value -# ^ keyword.operator.logical.pipe -# ^ support.function -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option - keyword - Invoke-Something -p1 { -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option + +###[ Types ]################################################################### + + [string] +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell + + [string[]] +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^ punctuation.section.brackets.end.powershell + + [int32] +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell + + [System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^ support.type.powershell +# ^^ punctuation.section.brackets.begin.powershell +# ^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^ support.type.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^^^^^^^^ support.type.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^^^^^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^ support.type.powershell +# ^^^ punctuation.section.brackets.end.powershell + + [System.Array+SZArrayEnumerator] +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^ support.type.powershell +# ^ punctuation.accessor.plus.powershell +# ^^^^^^^^^^^^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell + + [int]::MinValue +# ^ punctuation.section.brackets.begin.powershell +# ^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^^^^^^^ variable.other.member.powershell + + [System.DateTime]::Parse('2016/09/21') +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@ reference +# ^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.arguments.end.powershell + + +###[ Commands ]################################################################ + + Invoke-Something -foobar +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + Invoke-Something -foobar value +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^ string.unquoted.powershell Invoke-Something -foobar:$true -# ^ support.function +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell # @@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^^^^^ variable.parameter.option -# ^ punctuation.definition.variable -# ^^^^ constant.language -} | Invoke-Something -# <- punctuation.section.braces.end -# ^ keyword.operator.logical.pipe -# ^ support.function +# ^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^ keyword.operator.ternary.powershell +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + Invoke-Something -foobar: $true +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^ keyword.operator.ternary.powershell +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^ string.unquoted.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + Invoke-Something (1..20 | Invoke-Something) -p2 'value' +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^ keyword.operator.range.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ keyword.operator.logical.pipe.powershell +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^ punctuation.section.group.end.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^ string.unquoted.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ keyword.operator.logical.pipe.powershell +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + Invoke-Something -p1 { +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell # @@@@@@@@@@@@@@@@ reference - Invoke-Something -p1 value ` -#^ support.function -#@@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^ punctuation.separator.continuation +# ^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^ meta.block.powershell punctuation.section.braces.begin.powershell + Invoke-Something -foobar:$true +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell meta.block.powershell +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^ keyword.operator.ternary.powershell +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + } | Invoke-Something +#^^^^^^^^^ meta.function-call.arguments.powershell +#^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.end.powershell +# ^ keyword.operator.logical.pipe.powershell +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference + + Invoke-Something -p1 value ` +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^ string.unquoted.powershell +# ^ punctuation.separator.continuation.line.powershell -p2 14.4 ` -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option -# ^^^^ meta.number.float.decimal constant.numeric.value -# ^ punctuation.separator.continuation +#^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.separator.continuation.line.powershell + # An indented comment doesn't interrupt line continuation -p3 $value | Invoke-Something -verbose -# ^ punctuation.definition.parameter -# ^^^ variable.parameter.option +#^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.logical.pipe.powershell +# ^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell # @@@@@@@@@@@@@@@@ reference -# ^ punctuation.definition.parameter -# ^^^^^^^^ variable.parameter.option -# ^ punctuation.definition.variable -# ^ keyword.operator.logical.pipe -# ^^^^^^^^^^^^^^^^ support.function - -# Commands (Built-in variables) -ls *.ps1 -recurse -# ^ keyword.operator -# ^ punctuation.definition.parameter -# ^^^^^^^^ variable.parameter.option - -# Commands (executable files) -. .\scripts\myscript.ps1 -parameter 'value' -# <- keyword.operator.other -# ^ punctuation.definition.parameter -# ^^^^^^^^^^ variable.parameter.option -# ^^^^^^^ string.quoted.single -& tool.exe -# <- keyword.operator.other -# ^^^^^^^^ variable.function -something.cmd -#^^^^^^^^^^^^ variable.function - øyvind.com -#^^^^^^^^^^ variable.function +# ^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + + Get-ChildItem | +# ^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@ reference +# ^^ meta.function-call.arguments.powershell +# ^ keyword.operator.logical.pipe.powershell + Select Name,Length +# ^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@ reference +# ^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^^^^ string.unquoted.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^ string.unquoted.powershell + + # Commands (Built-in variables) + ls *.ps1 -recurse +# ^^ meta.function-call.powershell variable.function.powershell +# @@ reference +# ^^^^^ string.unquoted.powershell +# ^ constant.other.wildcard.asterisk.powershell +# ^ punctuation.separator.powershell +# ^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell + + # Commands (executable files) + . .\scripts\Test-Foo.ps1 -parameter 'value' +# ^ keyword.operator.source.powershell +# ^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@@@@@@@@@@@@ reference +# ^^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + & tool.exe +# ^ keyword.operator.call.powershell +# ^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@ reference + + something.cmd +# ^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@ reference + + øyvind.com +# ^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@ reference + + & '.\script name with spaces.ps1' +# ^ keyword.operator.call.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ reference +# ^ punctuation.definition.string.begin.powershell +# ^^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.string.end.powershell + + & ".\script name with spaces.ps1" +# ^ keyword.operator.call.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ reference +# ^ punctuation.definition.string.begin.powershell +# ^^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.string.end.powershell # switch switch ("fourteen") {} @@ -1024,123 +1142,157 @@ switch ('this') { } # <- meta.block punctuation.section.braces.end + data { + "Thank you for using my PowerShell Organize.pst script." +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.data.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "It is provided free of charge to the community." + "I appreciate your comments and feedback." + } +# ^ - meta + # Functions and filters functioN MyFunction{} -# <- storage.type -# ^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell +# ^ - meta function My-Function {} -# <- storage.type -# ^^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell Function My.Function{} -# <- storage.type -# ^^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell function My-Function.Other{} -# <- storage.type -# ^^^^^^^^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell function Some.other.function{} -# <- storage.type -# ^^^^^^^^^^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell FUNCTION MyFunction2 {} -# <- storage.type -# ^^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell function New-File { } -# <- storage.type -# ^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^ entity.name.function.powershell # @@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell function New-File ($Name) { } -# <- storage.type -# ^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^ entity.name.function.powershell # @@@@@@@@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end New-File -#^^^^^^^^ meta.function-call support.function +#^^^^^^^^ meta.function-call.powershell support.function.powershell #@@@@@@@@ reference function NewFile($Name) { } -# <- storage.type -# ^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^ entity.name.function.powershell # @@@@@@@ definition -# ^ punctuation.section.group.begin -# ^ punctuation.definition.variable -# ^ variable.other.readwrite -# ^ punctuation.section.group.end -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.parameters.begin.powershell +# ^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell filter myfilter($param) {} -# <- storage.type -# ^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^ entity.name.function.powershell # @@@@@@@@ definition -# ^ punctuation.section.group.begin -# ^ punctuation.definition.variable -# ^ variable.other.readwrite -# ^ punctuation.section.group.end -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.parameters.begin.powershell +# ^^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell Filter my-Filter ($param){} -# <- storage.type -# ^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@ definition -# ^ punctuation.section.group.begin -# ^ punctuation.definition.variable -# ^ variable.other.readwrite -# ^ punctuation.section.group.end -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +# ^ punctuation.section.parameters.begin.powershell +# ^^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell # Note that the # in the path should highlight as a comment! function Test-Drive([string]$roman) { -# <- storage.type -# ^^^^^^^^^^ entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@ definition -# ^ punctuation.section.group.begin -# ^ punctuation.section.brackets.begin -# ^^^^^^ storage.type -# ^ punctuation.section.brackets.end -# ^ punctuation.definition.variable -# ^ variable.other.readwrite -# ^ punctuation.section.group.end -# ^ punctuation.section.braces.begin +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell $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 +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ meta.function-call.powershell variable.function.powershell +# @ reference +# ^ keyword.operator.ternary.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^^^^^^^^^^^^^^^^^ comment.line.powershell +# ^ punctuation.definition.comment.powershell + } +#^^^^ meta.function.powershell +# ^ punctuation.section.block.end.powershell function Verb-Noun -#^^^^^^^^^^^^^^^^^ meta.function -#^^^^^^^ storage.type -# ^^^^^^^^^ meta.function entity.name.function +#^^^^^^^^^^^^^^^^^ meta.function.powershell +#^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@ definition -{ -# <- punctuation.section.braces.begin + { +#^^^^ meta.function.powershell +# ^ punctuation.section.block.begin.powershell Param #^^^^^ keyword.declaration.parameter ( - # <- punctuation.section.group.begin +#^^^^ meta.function.powershell +# ^ punctuation.section.block.begin.powershell # Param1 help description # <- comment.line punctuation.definition.comment # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line @@ -1248,29 +1400,44 @@ function Verb-Noun # <- punctuation.definition.variable # ^ variable.other.readwrite ) - # <- punctuation.section.group.end +#^^^^ meta.function.powershell +# ^ punctuation.section.block.end.powershell # Do Something.... -} -# <- punctuation.section.braces.end + } +#^^^^ meta.function.powershell +# ^ punctuation.section.block.end.powershell # Class class Vehicle { -# <- storage.type.class -# ^^^^^^^ entity.name.class +#^^^^^^^^^^^^^^ meta.class.powershell +#^^^^ keyword.declaration.class.powershell +# ^^^^^^^ entity.name.class.powershell # @@@@@@@ definition -# ^ punctuation.section.braces.begin +# ^ punctuation.section.block.begin.powershell Vehicle() {} -# ^ punctuation.section.group.begin -# ^ punctuation.section.group.end -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end +#^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^ entity.name.function.powershell +# @@@@@@@ definition +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell Vehicle([string]$Owner) { -# ^ storage.type -# ^ punctuation.definition.variable -# ^ variable.other.readwrite -# ^ punctuation.section.braces.begin +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^ entity.name.function.powershell +# @@@@@@@ definition +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell $this.Owner = $Owner } @@ -1288,29 +1455,53 @@ class Vehicle { # ^ variable.other.readwrite [void]Drive([int]$NumberOfMiles) { -# ^^^^ storage.type -# ^^^^^ meta.function entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^ entity.name.function.powershell # @@@@@ definition -# ^^^ storage.type -# ^ punctuation.definition.variable -# ^ variable.other.readwrite +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^ storage.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^^ variable.parameter.powershell +# ^ punctuation.definition.variable.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell $this.Mileage += $NumberOfMiles -# ^^^^^ variable.language -# ^ punctuation.definition.variable -# ^^^^^^^ variable.other.member -# ^^ keyword.operator.assignment +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell meta.function.powershell +# ^^^^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^ variable.other.member.powershell +# ^^ keyword.operator.assignment.augmented.powershell +# ^^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell } - # <- punctuation.section.braces.end +#^^^^ meta.class.powershell meta.function.powershell +# ^ punctuation.section.block.end.powershell + static [System.Array] GetAvailableColors() { -# ^^^^^^^^^^^^^^^^^^ meta.function entity.name.function +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.class.powershell +# ^^^^^^ storage.modifier.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^^^^^ entity.name.function.powershell # @@@@@@@@@@@@@@@@@@ definition -# ^^^^^^ meta.function storage.modifier -# ^^^^^^^^^^^ meta.function storage.type +# ^ punctuation.section.parameters.begin.powershell +# ^ punctuation.section.parameters.end.powershell +# ^ punctuation.section.block.begin.powershell return 'yellow', 'red' } } -# <- punctuation.section.braces.end +# <- punctuation.section.block.end $fiat.Drive(42) # ^^^^^ meta.function-call @@ -1339,286 +1530,586 @@ catch { } # <- keyword.control # ^ punctuation.section.braces.begin # ^ punctuation.section.braces.end -clean { } -# <- keyword.context.block.clean -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end -# Reserved words -Configuration Crazyness { -# <- storage.type -# ^^^^^^^^^ entity.name.function -# @@@@@@@@@ definition -# ^ punctuation.section.braces.begin - Node Whatever { -# ^ punctuation.section.braces.begin - } - # <- punctuation.section.braces.end -} -# <- punctuation.section.braces.end + # Redirection + notepad.exe > log.txt +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ keyword.operator.redirection.powershell +# ^^^^^^^ string.unquoted.powershell +# ^ punctuation.separator.powershell + notepad.exe 1> log.txt +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^ keyword.operator.redirection.powershell +# ^^^^^^^ string.unquoted.powershell +# ^ punctuation.separator.powershell + notepad.exe *> log.txt +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^ keyword.operator.redirection.powershell +# ^^^^^^^ string.unquoted.powershell +# ^ punctuation.separator.powershell + notepad.exe 2>&1 +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell + notepad.exe 3>&1 +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell + notepad.exe 4>&1 +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell + notepad.exe 5>&1 +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell + notepad.exe 6>&1 +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell + notepad.exe 2>&1> log.txt +# ^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@ reference +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^^ keyword.operator.redirection.powershell +# ^ constant.numeric.decimal.file-descriptor.powershell +# ^ keyword.operator.redirection.powershell +# ^^^^^^^ string.unquoted.powershell +# ^ punctuation.separator.powershell + + # Operators + if (10 -cgt 100) { } +# ^^ keyword.control.conditional.if.powershell +# ^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.section.group.end.powershell +# ^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^ punctuation.section.braces.end.powershell + $a -is $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $b -contains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $x -notcontains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $c -in $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $c -notin $x +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -match $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -notmatch $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $x -like $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + 100 -and 0 +# ^^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + $a -ceq 4 -and $a -ine $d -or +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell + $c -is [Type] +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell + $c -isnot [Type] +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell + $c -as [Type] +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ keyword.operator.cast.powershell +# ^ punctuation.definition.keyword.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell + $k = $y -bor $k +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $x = $y -band $x +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $z = -bnot $x +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $l = 1 -shl 10 +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + $r = 10 -shr 1 +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + $k = $y -xor $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $k = $y -bxor $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ keyword.operator.bitwise.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -icontains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -ccontains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -iNotContains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -cNotContains $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -cmatch $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $x -iMatch $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $x -iNotMatch $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $a -iLike $b +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + $b -cLike $c +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + "hey" -cgt "Hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "Hey" -igt "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "hey" -cge "Hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "Hey" -ige "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "HEY" -clt "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "HEY" -ilt "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "HEY" -cle "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + "HEY" -ile "hey" +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + function Test-Function {} +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^ entity.name.function.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell +# @@@@@@@@@@@@@ definition + function New-Object {} +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^ entity.name.function.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell +# @@@@@@@@@@ definition + Test-Function -Class ClassName +# ^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# ^^^^^^ variable.parameter.option.powershell - storage - keyword +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^ string.unquoted.powershell +# @@@@@@@@@@@@@ reference + New-Object -TypeName System.Diagnostics.Process +# ^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@ reference +# ^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted.powershell - keyword +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell + New-Object -TypeName System.Data +# ^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@ reference +# ^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^ string.unquoted.powershell - keyword + New-Object -TypeName Sy-stem.if +# ^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@ reference +# ^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^ string.unquoted.powershell - keyword +# ^ punctuation.separator.powershell + New-Object -TypeName S_ystem.Clean +# ^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@ reference +# ^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^^^ string.unquoted.powershell - keyword +# ^ punctuation.separator.powershell + New-Object -TypeName Sy_stem-.Throw +# ^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@ reference +# ^^^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^^^^^^^^^^^^^ string.unquoted.powershell - keyword + + echo `"test`" +# ^^^^ meta.function-call.powershell variable.function.powershell +# @@@@ reference +# ^^ constant.character.escape.powershell +# ^^^^^^ string.unquoted.powershell - string.quoted +# ^^ constant.character.escape.powershell + + @("any","array","has").foreach({ $_ }) +# ^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell +# ^ keyword.other.array.begin.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@ reference +# ^^^^^^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.braces.end.powershell +# ^ punctuation.section.arguments.end.powershell + @('any','array','has').foreach{ $_ } +# ^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell +# ^ keyword.other.array.begin.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.braces.end.powershell + @("any","array","has").where({ $_.Length -gt 3 }) +# ^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell +# ^ keyword.other.array.begin.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@ reference +# ^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^^^^^^^^^^^^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^ variable.other.member.powershell +# ^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.section.braces.end.powershell +# ^ punctuation.section.arguments.end.powershell + @("any","array","has").where{ $_.Length -gt 3 } +# ^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell +# ^ keyword.other.array.begin.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^^^^^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^^ variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^ variable.other.member.powershell +# ^^^ keyword.operator.comparison.powershell +# ^ punctuation.definition.keyword.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.section.braces.end.powershell + + function join-path {} +# @@@@@@@@@ definition -# Redirection -notepad.exe > log.txt -#^^^^^^^^^^ variable.function -# ^ keyword.operator.redirection -notepad.exe 1> log.txt -#^^^^^^^^^^ variable.function -# ^ keyword.operator.redirection -notepad.exe *> log.txt -#^^^^^^^^^^ variable.function -# ^ keyword.operator.redirection -notepad.exe 2>&1 -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -notepad.exe 3>&1 -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -notepad.exe 4>&1 -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -notepad.exe 5>&1 -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -notepad.exe 6>&1 -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -notepad.exe 2>&1> log.txt -#^^^^^^^^^^ variable.function -# ^^ keyword.operator.redirection -# ^ keyword.operator.redirection - -# Operators -if (10 -cgt 100) { } -# <- keyword.control -# ^ punctuation.section.group.begin -# ^^ meta.number.integer.decimal constant.numeric.value -# ^^^^ keyword.operator.comparison -# ^^^ meta.number.integer.decimal constant.numeric.value -# ^ 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 -# ^ meta.number.integer.decimal constant.numeric.value -$a -ceq 4 -and $a -ine $d -or -# ^^^^ keyword.operator.comparison -# ^ meta.number.integer.decimal constant.numeric.value -# ^^^^ 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.cast -# ^ 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 -# ^ meta.number.integer.decimal constant.numeric.value -# ^^ meta.number.integer.decimal constant.numeric.value -# ^^^^ keyword.operator.bitwise -$r = 10 -shr 1 -# ^ keyword.operator.assignment -# ^^ meta.number.integer.decimal constant.numeric.value -# ^ meta.number.integer.decimal constant.numeric.value -# ^^^^ 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 -# ^^^^ meta.number.float.decimal constant.numeric.value -# ^ punctuation.section.group.begin -# ^ string.quoted.double - "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 -# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double -# ^^ keyword.operator.string-format -# ^^^ meta.number.integer.decimal constant.numeric.value - ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) -# ^^ keyword.operator.string-format -# ^^^^ meta.number.float.decimal constant.numeric.value -# ^^^^^^^^^^^^^ string.quoted.double -# ^^ keyword.operator.string-format - "{0:R}" -f (1mb/2.0) -# ^ keyword.operator.string-format -# ^ meta.number.integer.decimal constant.numeric.value -# ^^ meta.number.integer.decimal constant.numeric.suffix - "{0:00.0}" -f 4.12341234 -# ^ keyword.operator.string-format - "{0:##.#}" -f 4.12341234 -# ^ string.quoted.double -# ^ keyword.operator.string-format -# ^^^^^^^^^^ meta.number.float.decimal constant.numeric.value - "{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 - -function Test-Function {} -# @@@@@@@@@@@@@ definition -function New-Object {} -# @@@@@@@@@@ definition -# Misc test cases - Test-Function -Class ClassName -# ^^^^^ - storage.type -#@@@@@@@@@@@@@ reference - New-Object -TypeName System.Diagnostics.Process -# ^^^^^^^ - keyword.control -#@@@@@@@@@@ reference - New-Object -TypeName System.Data -# ^^^^ - keyword.control -#@@@@@@@@@@ reference - New-Object -TypeName Sy-stem.if -# ^^ - keyword.control -#@@@@@@@@@@ reference - New-Object -TypeName S_ystem.Clean -# ^^^^^ - keyword.control -#@@@@@@@@@@ reference - New-Object -TypeName Sy_stem-.Throw -# ^^^^^ - keyword.control -#@@@@@@@@@@ reference -echo `"test`" -# ^^^^^^^^^ - string.quoted -# ^^ constant.character.escape -# ^^ constant.character.escape -@("any","array","has").foreach({ $_ }) -# <- keyword.other.array.begin -# ^ meta.group.array-expression -# ^ keyword.control -# ^ meta.block -@('any','array','has').foreach{ $_ } -# <- keyword.other.array.begin -# ^ meta.group.array-expression -# ^ keyword.control -# ^ meta.block -@("any","array","has").where({ $_.Length -gt 3 }) -# <- keyword.other.array.begin -# ^ meta.group.array-expression -# ^ keyword.control -# ^ meta.block -@("any","array","has").where{ $_.Length -gt 3 } -# <- keyword.other.array.begin -# ^ meta.group.array-expression -# ^ keyword.control -# ^ meta.block -function join-path {} -# @@@@@@@@@ definition $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" -# <- punctuation.definition.variable +#^^^^ variable.other.readwrite.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^^ meta.function-call.powershell support.function.powershell # @@@@@@@@@ reference -# ^ support.function -# ^ support.variable.drive -# ^ variable.other.readwrite -# ^^ meta.string meta.interpolation punctuation.section.interpolation.begin -# ^ storage.type +# ^^^^^^^^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ support.variable.drive.powershell +# ^ punctuation.accessor.colon.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interpolation.powershell +# ^^ punctuation.section.interpolation.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.powershell.embedded +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^ meta.generic-name.powershell +# ^ punctuation.accessor.dot.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^^^^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell # @@@@@@@@@@@@@@@@@ reference +# ^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^ punctuation.section.arguments.end.powershell +# ^ punctuation.section.interpolation.end.powershell +# ^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.end.powershell + function out-file {} # @@@@@@@@ definition $ScriptBlock | Out-File $file -Force @@ -1628,21 +2119,6 @@ $ScriptBlock | Out-File $file -Force # ^ punctuation.definition.variable # ^ punctuation.definition.parameter # ^^^^^^ variable.parameter.option -workflow w1 {} -# <- storage.type -# ^^ entity.name.function -# @@ definition -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end -Workflow work { sequence {} } -# <- storage.type -# ^^^^ entity.name.function -# @@@@ definition -# ^ punctuation.section.braces.begin -# ^^^^^^^^ keyword.control -# ^ punctuation.section.braces.begin -# ^ punctuation.section.braces.end -# ^ punctuation.section.braces.end function get-something {} # @@@@@@@@@@@@@ definition function Out-WithYou {} @@ -1658,19 +2134,7 @@ function Out-WithYou {} # ^ constant.language # ^ punctuation.definition.comment # ^^^^^^^^^ comment.line -"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 + function get-number {} # @@@@@@@@@@ definition "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" @@ -1689,6 +2153,40 @@ function get-number {} # ^ meta.group.complex.subexpression punctuation.section.group.end # ^ punctuation.definition.variable # ^ punctuation.section.interpolation.end - source.powershell.embedded + + ([MyType])::Name[2] +# ^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^ punctuation.section.group.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^^^ variable.other.member.powershell +# ^^^ meta.brackets.indexer.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.section.brackets.end.powershell + ([MyType])::Name.ToString()[2] +# ^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^ support.type.powershell +# ^ punctuation.section.brackets.end.powershell +# ^ punctuation.section.group.end.powershell +# ^^ punctuation.accessor.double-colon.powershell +# ^^^^ variable.other.member.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@ reference +# ^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^ punctuation.section.arguments.end.powershell +# ^^^ meta.brackets.indexer.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.section.brackets.end.powershell + "This is the DebugPreference variable: $DebugPreference" #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double # ^^^^^^^^^^^^^^^^ meta.string meta.interpolation variable.language - string diff --git a/Tests/syntax_test_Workflow.ps1 b/Tests/syntax_test_Workflow.ps1 new file mode 100644 index 00000000..be0bbb72 --- /dev/null +++ b/Tests/syntax_test_Workflow.ps1 @@ -0,0 +1,187 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + +"<- Exit the imports context block" + + workflow w1 {} +#^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^ entity.name.function.powershell +# @@ definition +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell + Workflow work { sequence {} } +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^ entity.name.function.powershell +# @@@@ definition +# ^ punctuation.section.block.begin.powershell +# ^^^^^^^^^^^ meta.block.powershell +# ^^^^^^^^ keyword.control.flow.powershell +# ^ punctuation.section.block.begin.powershell +# ^ punctuation.section.block.end.powershell +# ^ punctuation.section.block.end.powershell + + workflow Test-Workflow { +#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.declaration.function.powershell +# ^^^^^^^^^^^^^ entity.name.function.powershell +# @@@@@@@@@@@@@ definition +# ^ punctuation.section.block.begin.powershell + parallel { +#^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^ keyword.control.flow.powershell +# ^ punctuation.section.block.begin.powershell + Get-Process +# @@@@@@@@@@@ reference + Get-Service +#^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@ reference + } + } + + + workflow Test-Workflow { +# @@@@@@@@@@@@@ definition + $a = 3 +#^^^^^^^^^^^^^ meta.function.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + + ## Without $Using, the $a workflow variable isn't visible + ## in inline script. + inlinescript {"Inline A0 = $a"} +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^ keyword.control.context.powershell +# ^ punctuation.section.block.begin.powershell +# ^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^ meta.interpolation.powershell variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell +# ^ punctuation.section.block.end.powershell + + ## $Using imports the variable and its current value. + inlinescript {"Inline A1 = $Using:a"} +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell +# ^^^^^^^^^^^^ keyword.control.context.powershell +# ^ punctuation.section.block.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^ meta.interpolation.powershell variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ storage.modifier.scope.powershell +# ^ punctuation.accessor.colon.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell +# ^ punctuation.section.block.end.powershell + } + Test-Workflow +# @@@@@@@@@@@@@ reference + + + workflow Test-Workflow { +# @@@@@@@@@@@@@ definition + $a = 3 + + ## Changes to the inlinescript variable value don't + ## change the workflow variable. + inlinescript { + $a = $Using:a+1; + "Inline A = $a" + } + "Workflow A = $a" + + ## To change the variable in workflow scope, return the + ## new value. + $a = inlinescript {$b = $Using:a+1; $b} +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell +# ^^^^^^^^^^^^ keyword.control.context.powershell +# ^ punctuation.section.block.begin.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^ storage.modifier.scope.powershell +# ^ punctuation.accessor.colon.powershell +# ^ keyword.operator.unary.powershell +# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.terminator.statement.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.block.end.powershell + "Workflow New A = $a" + } + Test-Workflow +# @@@@@@@@@@@@@ reference + + + workflow Test-Workflow { +# @@@@@@@@@@@@@ definition + $ie = inlinescript { + $ie = New-Object -ComObject InternetExplorer.Application -Property @{navigate2="www.microsoft.com"} +# @@@@@@@@@@ reference + + $ie.Visible = $true +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^ variable.other.member.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^ constant.language.boolean.true.powershell +# ^ punctuation.definition.variable.powershell + } + + $ie + } + Test-Workflow +# @@@@@@@@@@@@@ reference + + + workflow Test-Workflow { +# @@@@@@@@@@@@@ definition + parallel { + Get-Process +# @@@@@@@@@@@ reference + Get-Service +#^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell +# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell +# @@@@@@@@@@@ reference + + sequence { +# ^ meta.function.powershell meta.block.powershell meta.block.powershell punctuation.section.block.begin.powershell + $Hotfix = Get-Content 'D:\HotFixes\Required.txt' +# @@@@@@@@@@@ reference + foreach ($h in $Hotfix) {D:\Scripts\Verify-Hotfix.ps1 -Hotfix $h} +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.block.powershell meta.block.powershell +# ^^^^^^^ keyword.control.loop.for.powershell +# ^^^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^ keyword.control.loop.in.powershell +# ^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.group.end.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell +# ^ punctuation.section.braces.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@@@@@@@@@@@@@@@@@@@@@ reference +# ^^^^^^^ variable.parameter.option.powershell +# ^ punctuation.definition.parameter.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.braces.end.powershell + } + } + } diff --git a/Tests/syntax_test_partial-symbols.ps1 b/Tests/syntax_test_partial-symbols.ps1 new file mode 100644 index 00000000..0371a95b --- /dev/null +++ b/Tests/syntax_test_partial-symbols.ps1 @@ -0,0 +1,16 @@ +# SYNTAX TEST partial-symbols "Packages/PowerShell/PowerShell.sublime-syntax" + + + data TextMsgs { +# ^^^^^^^^^^^^^^^ meta.block.data.powershell +# ^^^^ keyword.control.context.powershell +# ^^^^^^^^ entity.name.section.powershell +# ^ punctuation.section.block.begin.powershell + ConvertFrom-StringData -StringData @' +# @@@@@@@@@@@@@@@@@@@@@@ reference + Text001 = Windows 7 + Text002 = Windows Server 2008 R2 +'@ + } + + $TextMsgs diff --git a/Tests/syntax_test_strings.ps1 b/Tests/syntax_test_strings.ps1 new file mode 100644 index 00000000..05962bb2 --- /dev/null +++ b/Tests/syntax_test_strings.ps1 @@ -0,0 +1,751 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + +###[ Single Quoted Strings ]################################################### + + 'This is a single quoted string.' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - meta.string.interpolated +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + 'This is a +# ^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - meta.string.interpolated +# ^ punctuation.definition.string.begin.powershell + single quoted string.' +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - meta.string.interpolated +# ^ punctuation.definition.string.end.powershell + + 'This #also' +# ^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - comment +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + 'This "string" is nice.' +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - constant +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + '$This is a single ''quoted'' string.' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - meta.string.interpolated +# ^ punctuation.definition.string.begin.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.definition.string.end.powershell + + '$(Invoke-Something)' +# ^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - meta.interpolation - variable - support +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + 'Not escape chars: `", `n, `$, `b, `"' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell - constant +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + ‘curly ‘‘quotes'’ are equivalent to straight ones' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.definition.string.end.powershell + + @' +# ^^ meta.string.powershell string.quoted.single.heredoc.powershell punctuation.definition.string.begin.powershell - meta.string.interpolated + A 'single quoted' "heredoc" +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.heredoc.powershell - punctuation + '@ +#^^^^^ meta.string.powershell string.quoted.single.heredoc.powershell - punctuation +'@ +#^ meta.string.powershell string.quoted.single.heredoc.powershell punctuation.definition.string.end.powershell + + @' + using System; +#^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.heredoc.powershell source.cs +# ^^^^^ keyword.control.import.cs +# ^^^^^^ meta.path.cs +# ^ punctuation.terminator +'@ + +###[ Double Quoted Strings ]################################################### + + "This is a double quoted string." +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + "This is a +# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell + double quoted string." +#^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.end.powershell + + "This #also" +# ^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - comment +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + "This 'string' is nice." +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - constant +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + "$This is a double ""quoted"" string." +# ^ 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 + + # In double-quoted strings, only the variable should be highlighted, not the property + "This is my $variable.Name!" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^ meta.interpolation.powershell variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^ string.quoted.double.powershell - meta.interpolation - variable - punctuation.accessor +# ^ punctuation.definition.string.end.powershell + + # When used in a subexpression, both should be highlighted + "This is my $($variable.Name)!" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^ meta.interpolation.powershell - string +# ^^ punctuation.section.interpolation.begin.powershell +# ^^^^^^^^^^^^^^ source.powershell.embedded +# ^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^ variable.other.member.powershell +# ^ punctuation.section.interpolation.end.powershell +# ^^ string.quoted.double.powershell - meta.interpolation +# ^ punctuation.definition.string.end.powershell + + # When used in a subexpression, still don't extend past its closing + "This is my $($variable.Name).Name!" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^ meta.interpolation.powershell +# ^^ punctuation.section.interpolation.begin.powershell +# ^^^^^^^^^^^^^^ source.powershell.embedded +# ^^^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^ variable.other.member.powershell +# ^ punctuation.section.interpolation.end.powershell +# ^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.end.powershell + + # $ENV:ComputerName should be highlighted + "This is the name of my computer: $ENV:ComputerName" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^ meta.interpolation.powershell variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^ support.variable.drive.powershell +# ^ punctuation.accessor.colon.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell + + # Here as well + "This is the name of my computer: ${ENV:ComputerName}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^ meta.interpolation.powershell variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.interpolation.begin.powershell +# ^^^ support.variable.drive.powershell +# ^ punctuation.accessor.colon.powershell +# ^ punctuation.section.interpolation.end.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell + + # The @splat references only work in argument mode, should not highlight in strings + "This is a @double quoted string." +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - variable - punctuation.definition.variable +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell + + # Double check scopes for automatic variables in strings + "$_ $$ $Pwd" +# ^^^^^^^^^^^^ meta.string.interpolated.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.begin.powershell +# ^^ meta.interpolation.powershell variable.language.powershell - string +# ^ punctuation.definition.variable.powershell +# ^ string.quoted.double.powershell +# ^^ meta.interpolation.powershell variable.language.powershell - string +# ^ punctuation.definition.variable.powershell +# ^ string.quoted.double.powershell +# ^^^^ meta.interpolation.powershell variable.language.powershell - string +# ^ punctuation.definition.variable.powershell +# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell + + "$(Invoke-Something)" +# ^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^^^^ meta.string meta.interpolation - string +# ^^ punctuation.section.interpolation.begin +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.section.interpolation.end +# @@@@@@@@@@@@@@@@ reference + + “curly ““quotes"” are equivalent to straight ones" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.definition.string.end.powershell + + # Double quoted here-string + @" +# ^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell punctuation.definition.string.begin.powershell + $This is a 'double quoted' +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell +#^^^ string.quoted.double.heredoc.powershell +# ^^^^^ meta.interpolation.powershell variable.language.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.heredoc.powershell + Isn't it "nice"?? +#^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell - punctuation + There is no @splatting here! +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell + "@ +#^^^^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell - punctuation +"@ +#^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell punctuation.definition.string.end.powershell + + + "Escaped chars: `", `n, `$, `b, `t, `e, `u{10ffff}, `"" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^^^^^^^^^^ constant.character.escape.powershell +# ^^ constant.character.escape.powershell +# ^ punctuation.definition.string.end.powershell + + @" + using System; +#^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.heredoc.powershell source.cs +# ^^^^^ keyword.control.import.cs +# ^^^^^^ meta.path.cs +# ^ punctuation.terminator +"@ + + +###[ Regular Expressions ]##################################################### + + 'book' -match 'oo' +# ^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'big' -match 'b[iou]g' +# ^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 42 -match '[0-9][0-9]' +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'a1\ ' -match '....' +# ^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^ source.regexp.embedded keyword.other.any.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'ACCOUNT NAME: Administrator' -match 'ACCOUNT NAME:\s*\w*' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^ source.regexp.embedded +# ^^ keyword.control.character-class.regexp +# ^ keyword.operator.quantifier.regexp +# ^^ keyword.control.character-class.regexp +# ^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'SERVER01' -match '[A-Z]+-?\d\d' +# ^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^ source.regexp.embedded +# ^^^^^ meta.set.regexp +# ^ keyword.operator.quantifier.regexp +# ^ keyword.operator.quantifier.regexp +# ^^^^ keyword.control.character-class.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + '111-222-3333' -match '\d{3}-\d{3}-\d{4}' +# ^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^ source.regexp.embedded +# ^^ keyword.control.character-class.regexp +# ^^^ keyword.operator.quantifier.regexp +# ^^ keyword.control.character-class.regexp +# ^^^ keyword.operator.quantifier.regexp +# ^^ keyword.control.character-class.regexp +# ^^^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'fishing' -match '^fish$' +# ^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^ source.regexp.embedded +# ^ keyword.control +# ^ keyword.control +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + '3.141' -match '3\.\d{2,}' +# ^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^ source.regexp.embedded +# ^^ constant.character.escape.regexp +# ^^ keyword.control.character-class.regexp +# ^^^^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'The last logged on user was CONTOSO\jsmith' -match '(.+was )(.+)' +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^ source.regexp.embedded +# ^ keyword.other.any.regexp +# ^ keyword.operator.quantifier.regexp +# ^ keyword.other.any.regexp +# ^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + $string -match 'was (?.+)\\(?.+)' +# ^^^^^^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell +# ^^^^^^ keyword.operator.logical.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + 'Hello World' -replace '(\w+) \w+', '$1 Universe' +# ^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^^^ keyword.operator.string.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^ source.regexp.embedded +# ^^ keyword.control.character-class.regexp +# ^ keyword.operator.quantifier.regexp +# ^^ keyword.control.character-class.regexp +# ^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + "Hello World" -replace "(\w+) \w+", "`$1 Universe" + '5.72' -replace '(.+)', '$$$1' +# ^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^^^^^^^^ keyword.operator.string.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^ source.regexp.embedded +# ^ keyword.other.any.regexp +# ^ keyword.operator.quantifier.regexp +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^ meta.string.powershell +# ^ string.quoted.single.powershell punctuation.definition.string.begin.powershell +# ^^^^ source.regexp.embedded +# ^ string.quoted.single.powershell punctuation.definition.string.end.powershell + "5.72" -replace "(.+)", "`$`$`$1" + +###[ String Formatting ]####################################################### + + "{0:N2}" -f $a +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + + "{0:D8}" -f $a +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + + "{0:C2}" -f $a +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + + "{0:P0}" -f $a +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + + "{0:X0}" -f $a +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ variable.other.readwrite.powershell +# ^ punctuation.definition.variable.powershell + + (1.11).ToString("#.#") +# ^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.accessor.dot.powershell +# ^^^^^^^^ meta.function-call.powershell variable.function.powershell +# @@@@@@@@ reference +# ^^^^^^^ meta.function-call.arguments.powershell +# ^ punctuation.section.arguments.begin.powershell +# ^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.section.arguments.end.powershell + + "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 +# ^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^ punctuation.definition.string.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + + ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) +# ^^^^^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.section.group.end.powershell + + "{0:R}" -f (1mb/2.0) +# ^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^ meta.group.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^ meta.number.integer.decimal.powershell +# ^ constant.numeric.value.powershell +# ^^ constant.numeric.suffix.powershell +# ^ keyword.operator.arithmetic.powershell +# ^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.section.group.end.powershell + + "{0:00.0}" -f 4.12341234 +# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + "{0:##.#}" -f 4.12341234 +# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + "{0:#,#.#}" -f 1234.121234 +# ^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + "{0:##,,.000}" -f 1048576 +# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + + "{this is not a #comment}" +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - comment +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell + + "{0:##.#E000}" -f 2.71828 +# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + # TODO: Let placeholders contain quotes + "{0:#.00'##'}" -f 2.71828 +# ^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + "{0:POS;NEG;ZERO}" -f -14 +# ^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^ keyword.operator.unary.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + + "{0:$## Please}" -f 14 +# ^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell - comment +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^ meta.number.integer.decimal.powershell constant.numeric.value.powershell + + "{0,-8:P1}" -f 1.75 +# ^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell +# ^ punctuation.separator.sequence.powershell +# ^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell + + # Single-quoted format string + '{0:00000.000}' -f 7.125 +# ^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell +# ^ punctuation.definition.string.begin.powershell +# ^^^^^^^^^^^^^ constant.other.placeholder.powershell +# ^ punctuation.definition.placeholder.begin.powershell +# ^ punctuation.separator.powershell +# ^ punctuation.definition.placeholder.end.powershell +# ^ punctuation.definition.string.end.powershell +# ^^ keyword.operator.string-format.powershell +# ^ punctuation.definition.keyword.powershell +# ^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell +# ^ punctuation.separator.decimal.powershell