diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml new file mode 100644 index 0000000..7ec057b --- /dev/null +++ b/.github/workflows/syntax.yml @@ -0,0 +1,32 @@ +name: Syntax Tests + +on: + push: + paths: + - '**.sublime-syntax' + - '**/syntax_test*' + - '**.tmPreferences' + pull_request: + paths: + - '**.sublime-syntax' + - '**/syntax_test*' + - '**.tmPreferences' + +jobs: + main: + name: Syntax Tests (${{ matrix.build }}) + strategy: + matrix: + include: + - build: 3211 + packages: st3 + - build: 4102 + packages: master + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: SublimeText/syntax-test-action@v2 + with: + build: ${{ matrix.build }} + default_packages: ${{ matrix.packages }} + package_name: 'PowerShell' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e742607..1660549 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ ## Contributing -Thanks for taking an insterest in contributing to the PowerShell package for +Thanks for taking an interest in contributing to the PowerShell package for Sublime Text 3! @@ -17,15 +17,17 @@ To build development versions, first you need a configuration file in This file must contain the following information: - { - "pathToSublimeText": "...\sublime_text.exe", - "pathToSublimeTextData": "...\ - } +``` json +{ + "pathToSublimeText": "...\\sublime_text.exe", + "pathToSublimeTextData": "...\\" +} +``` #### Using Sublime Text -1. Press Ctrl+Shift+B to open the build systems menu. +1. Press Ctrl+Shift+B to open the build systems menu. 2. Select 'PowerShell: Build Dev Version' @@ -33,8 +35,9 @@ This file must contain the following information: From the project's root: - .\bin\BuildFolder.ps1 -verbose - +``` pwsh +.\bin\BuildFolder.ps1 -verbose +``` #### Running Tests diff --git a/ISE Nostalgia.sublime-color-scheme b/ISE Nostalgia.sublime-color-scheme new file mode 100644 index 0000000..c94b433 --- /dev/null +++ b/ISE Nostalgia.sublime-color-scheme @@ -0,0 +1,151 @@ +{ + "name": "ISE Nostalgia", + "author": "Guillermo L\u00f3pez-Anglada", + "variables": + { + "blue": "#87beff", + "blue2": "#add6ff", + "blue3": "#5ab1cd", + "blue4": "#585cf6", + "blue5": "#0000ff", + "blue6": "#6d79de", + "blue7":"#21439C", + "green": "#006400", + "green2": "#06960e", + "grey": "#a9a9a9", + "grey2": "#7f7f7f", + "grey3": "#292929", + "grey4": "#70727E", + "purple": "#8a2be2", + "purple2": "#801e92", + "purple3": "#aa69b6", + "red": "#6b0000", + "red2": "#ff4500", + "red3": "#b85b44", + "white": "#ffffff", + "white2": "#fef8da", + "white3": "#e3f1ff", + "yellow": "#ffff00", + }, + "globals": + { + "foreground": "var(purple)", + "background": "var(white)", + "caret": "var(grey2)", + // "invisibles": "var(grey2)", + "line_highlight": "var(white2)", + "selection": "var(blue2)", + "selection_border": "var(blue)", + "inactive_selection": "var(white3)", + "gutter_foreground": "var(blue3)", + }, + "rules": + [ + { + "name": "Comment", + "scope": "comment", + "foreground": "var(green)", + "font_style": "normal", + }, + { + "name": "Keyword", + "scope": "keyword, storage", + "foreground": "var(grey3)", + }, + { + "name": "Number", + "scope": "constant.numeric", + "foreground": "var(purple2)", + }, + { + "name": "Built-in constant", + "scope": "constant.language", + "foreground": "var(blue4)", + }, + { + "name": "Variable", + "scope": "variable.language, variable.other", + "foreground": "var(red2)", + }, + { + "name": "String", + "scope": "string", + "foreground": "var(red)", + }, + { + "name": "String interpolation", + "scope": "constant.character.escape, string source", + "foreground": "var(purple3)", + }, + // { + // "name": "Function name", + // "scope": "entity.name.function, support.function.any-method", + // "foreground": "var(blue5)", + // }, + // { + // "name": "Type name", + // "scope": "entity.name.type", + // "font_style": "underline", + // }, + // { + // "name": "Inherited class name", + // "scope": "entity.other.inherited-class", + // "font_style": "italic", + // }, + // { + // "name": "Function parameter", + // "scope": "variable.parameter", + // "font_style": "italic", + // }, + // { + // "name": "Function argument and result types", + // "scope": "storage.type.method", + // "font_style": "", + // "foreground": "var(grey4)", + // }, + // { + // "name": "Section", + // "scope": "meta.section entity.name.section, declaration.section entity.name.section", + // "font_style": "italic", + // }, + { + "name": "Library function", + "scope": "support.function", + "foreground": "var(blue5)", + }, + // { + // "name": "Library object", + // "scope": "support.class, support.type", + // "font_style": "bold", + // "foreground": "var(blue6)", + // }, + // { + // "name": "Library constant", + // "scope": "support.constant", + // "font_style": "bold", + // "foreground": "var(green2)", + // }, + // { + // "name": "Library variable", + // "scope": "support.variable", + // "font_style": "bold", + // "foreground": "var(blue7)", + // }, + { + "name": "PowerShell: Assignment Operator", + "scope": "keyword.operator.assignment.powershell", + "foreground": "var(grey)", + }, + { + "name": "Invalid", + "scope": "invalid", + "foreground": "var(yellow)", + "background": "var(red3)", + }, + { + "name": "Invalid trailing whitespace", + "scope": "invalid.deprecated.trailing-whitespace", + "background": "var(red3)", + } + ] +} diff --git a/ISE Nostalgia.tmTheme b/ISE Nostalgia.tmTheme deleted file mode 100644 index 7eaf925..0000000 --- a/ISE Nostalgia.tmTheme +++ /dev/null @@ -1,280 +0,0 @@ - - - - - author - Guillermo López-Anglada - name - ISE Nostalgia - settings - - - settings - - gutterForeground - #5AB1CD - background - #FFFFFF - foreground - #8A2BE2 - caret - #7F7F7F - lineHighlight - #FEF8DA - selection - #ADD6FF - selectionBorder - #87BEFF - inactiveSelection - #E3F1FF - - - - name - Comment - scope - comment - settings - - fontStyle - normal - foreground - #006400 - - - - name - Keyword - scope - keyword, storage - settings - - foreground - #292929 - - - - name - Number - scope - constant.numeric - settings - - fontStyle - - foreground - #801E92 - - - - name - Built-in constant - scope - constant.language - settings - - foreground - #585CF6 - - - - name - Variable - scope - variable.language, variable.other - settings - - fontStyle - - foreground - #FF4500 - - - - name - String - scope - string - settings - - fontStyle - - foreground - #6B0000 - - - - name - String interpolation - scope - constant.character.escape, string source - settings - - fontStyle - - foreground - #AA69B6 - - - - - - - - name - Library function - scope - support.function - settings - - foreground - #0000FF - - - - - - - name - PowerShell: Assignment Operator - scope - keyword.operator.assignment.powershell - settings - - foreground - #A9A9A9 - - - - name - Invalid - scope - invalid - settings - - background - #B85B44 - foreground - #FFFF00 - - - - name - Invalid trailing whitespace - scope - invalid.deprecated.trailing-whitespace - settings - - background - #B85B44 - - - - uuid - 71D40D9D-AE48-11D9-920A-000D93589AF6 - - \ No newline at end of file diff --git a/Indentation.tmPreferences b/Indentation.tmPreferences new file mode 100644 index 0000000..7406497 --- /dev/null +++ b/Indentation.tmPreferences @@ -0,0 +1,15 @@ + + + + + name + Indentation Rules + scope + source.powershell + settings + + unIndentedLinePattern + "@ + + + diff --git a/LICENSE.txt b/LICENSE.txt index 51a8c4c..0a8767a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,5 @@ -Copyright (c) 2011 Guillermo López-Anglada +Copyright (c) 2011-2015 Guillermo López-Anglada + 2020-2021 Michael Lyons Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/PowerShell.sublime-project b/PowerShell.sublime-project index a56dd4b..9d0052b 100644 --- a/PowerShell.sublime-project +++ b/PowerShell.sublime-project @@ -3,14 +3,7 @@ [ { "follow_symlinks": true, - "path": "." - } + "path": ".", + }, ], - - "build_systems": [ - { - "name": "PowerShell: Build Dev Version", - "shell_cmd": "powershell.exe -noninteractive -file $project_path/bin/BuildFolder.ps1" - } - ] } diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax new file mode 100644 index 0000000..db3f947 --- /dev/null +++ b/PowerShell.sublime-syntax @@ -0,0 +1,778 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: PowerShell +scope: source.powershell +version: 2 + +file_extensions: + - ps1 + - psm1 + - psd1 + +first_line_match: |- + (?x: + ^\#!.*\b(?:pwsh|powershell)\b + | ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*- + ) + +variables: + dec_digits: (?:[\d_]*\d) + dec_exponent: (?:[eE][-+]?{{dec_digits}}) + float_suffix: (?i:[fdm](?!b)) + integer_suffix: (?i:ul?|lu?) + bytes_unit: (?i:[kmgtp]b) + kebab_break: (?![\w-]) + +contexts: + + pop-before-newline: + - match: (?=\n|$) + pop: true + + pop-at-newline: + - match: \n|$ + pop: true + + main: + - include: comments + - include: expressions + + expressions: + - include: redirection + - include: commands + - include: variable + - include: group + - include: function + - include: attribute + - include: using-directive + - include: type + - include: hashtable + - include: strings + - include: script-block + - include: escape-characters + - include: numeric-constant + - 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 + 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 + # Exceptions + - match: \b(?i:throw){{kebab_break}} + scope: keyword.control.exception.raise.powershell + - match: \b(?i:try){{kebab_break}} + scope: keyword.control.exception.try.powershell + - match: \b(?i:catch|trap){{kebab_break}} + scope: keyword.control.exception.catch.powershell + - match: \b(?i:finally){{kebab_break}} + scope: keyword.control.exception.finally.powershell + # Conditionals + - match: \b(?i:if){{kebab_break}} + scope: keyword.control.conditional.if.powershell + - match: \b(?i:elseif){{kebab_break}} + scope: keyword.control.conditional.elseif.powershell + - match: \b(?i:else){{kebab_break}} + scope: keyword.control.conditional.else.powershell + - match: \b(?i:switch){{kebab_break}} + scope: keyword.control.conditional.switch.powershell + - match: \? + scope: keyword.control.conditional.select.powershell + - match: \b(?i:where(?!-object)){{kebab_break}} + scope: keyword.control.conditional.select.powershell + # Begin/End + - match: \b(?i:begin){{kebab_break}} + scope: keyword.context.block.begin.powershell + - match: \b(?i:end){{kebab_break}} + scope: keyword.context.block.end.powershell + # Loops + - match: \b(?i:for|foreach(?!-object)){{kebab_break}} + scope: keyword.control.loop.for.powershell + - match: \b(?i:do){{kebab_break}} + scope: keyword.control.loop.do-while.powershell + - match: \b(?i:while){{kebab_break}} + scope: keyword.control.loop.while.powershell + - match: \b(?i:until){{kebab_break}} + scope: keyword.control.loop.repeat-until.powershell + # Flow + - match: \b(?i:break){{kebab_break}} + scope: keyword.control.flow.break.powershell + - match: \b(?i:continue){{kebab_break}} + scope: keyword.control.flow.continue.powershell + - match: \b(?i:exit){{kebab_break}} + scope: keyword.control.flow.exit.powershell + - match: \b(?i:return){{kebab_break}} + scope: keyword.control.flow.return.powershell + # Declaration + - match: \b(?i:var){{kebab_break}} + # scope: storage.type.variable.powershell + scope: keyword.declaration.variable.powershell + - match: \b(?i:(?:dynamic)?param){{kebab_break}} + scope: keyword.declaration.parameter.powershell # This scope is not standard + # Uncategorized keywords + - match: \b(?i:data|default|define|from|in|inlinescript|parallel|process){{kebab_break}} + scope: keyword.control.powershell + - match: \B--%\B + scope: keyword.control.powershell + push: + - meta_content_scope: string.unquoted.powershell + - include: pop-before-newline + - match: \b(?i:hidden|static)\b + # This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. + scope: storage.modifier.powershell + - match: \b((?i:class))\s+([\w-]+)\b + captures: + 1: storage.type.class.powershell + 2: meta.class.powershell entity.name.class.powershell + # Operators... + - match: \B(-)(?i:as){{kebab_break}} + scope: keyword.operator.cast.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te])){{kebab_break}} + scope: keyword.operator.comparison.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:[ic]?(?:not)?(?:like|match|contains|in)){{kebab_break}} + scope: keyword.operator.logical.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:join|split|replace){{kebab_break}} + scope: keyword.operator.string.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:is(?:not)?){{kebab_break}} + scope: keyword.operator.logical.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:and|or|not|xor){{kebab_break}}|! # <-- note `!` + scope: keyword.operator.logical.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:band|bor|bnot|bxor|sh[lr]){{kebab_break}} + scope: keyword.operator.bitwise.powershell + captures: + 1: punctuation.definition.keyword.powershell + - match: \B(-)(?i:f){{kebab_break}} + 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) + scope: keyword.operator.assignment.powershell + - match: '[+-](?=\.?\d)' # This is sort of heuristic + scope: keyword.operator.unary.powershell + - match: '[+/*-]' + scope: keyword.operator.arithmetic.powershell + - match: '%(?!\s*\{)' + scope: keyword.operator.arithmetic.powershell + - match: \|\||&& + scope: keyword.operator.logical.powershell + - match: \| + scope: keyword.operator.logical.pipe.powershell + - match: ; + scope: punctuation.terminator.statement.powershell + - match: \`(?=\n|$) + scope: punctuation.separator.continuation.line.powershell + - match: ',' + scope: punctuation.separator.sequence.powershell + - match: '&|\B\.(?= )' + scope: keyword.operator.other.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 + + redirection: + # https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection + - match: ([2-6*])(>&)(1) + captures: + 1: constant.numeric.decimal.file-descriptor.powershell + 2: keyword.operator.redirection.powershell + 3: constant.numeric.decimal.file-descriptor.powershell + - match: ([1-6*])(>>?) + captures: + 1: constant.numeric.decimal.file-descriptor.powershell + 2: keyword.operator.redirection.powershell + - match: '>>?' + scope: keyword.operator.redirection.powershell + # - match: <+ + # scope: invalid.illegal.powershell + + requires-directive: + # 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 + + 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 + + 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 + | (?:Default)?ParameterSetName | SupportsShouldProcess + | PositionalBinding | HelpUri | ConfirmImpact | HelpMessage + ) + \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 + + 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: support.function.powershell + # Builtin cmdlets with reserved verbs + - match: \b(?i:(?:foreach|where|sort|tee)-object)\b + scope: support.function.powershell + + 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 + + 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 | ForwardHelpTargetName + | Functionality | Inputs | Notes | Outputs | RemoteHelpRunSpace + | Role | Synopsis + ) + ) + scope: comment.documentation.embedded.powershell + captures: + 1: punctuation.definition.keyword.documentation.powershell + 2: keyword.other.documentation.powershell + - match: ^\s*(\.)(?i:(Parameter)\s+([a-z0-9-_]+)) + scope: comment.documentation.embedded.powershell + captures: + 1: punctuation.definition.keyword.documentation.powershell + 2: keyword.other.documentation.param.powershell + 3: variable.parameter.powershell + - match: ^\s*(\.)(?i:(ForwardHelpTargetName|ForwardHelpCategory|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 + + 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 + + static-members: + # - meta_content_scope: debug.in.static-members + - match: '::' + scope: punctuation.accessor.double-colon.powershell + set: members + + members: + # - meta_content_scope: debug.in.members + - match: (?=\.\.) + pop: true + - match: \.(?=\w) + scope: punctuation.accessor.dot.powershell + - match: (\w+)(\() + captures: + 1: meta.function-call.powershell variable.function.powershell + 2: meta.function-call.arguments.powershell punctuation.section.arguments.begin.powershell + push: + - meta_content_scope: meta.function-call.arguments.powershell + - match: \) + scope: meta.function-call.arguments.powershell punctuation.section.arguments.end.powershell + pop: true + - include: expressions + - match: \w+ + scope: variable.other.member.powershell + - match: \[ + scope: punctuation.section.brackets.begin.powershell + push: + - meta_scope: meta.brackets.indexer.powershell + - match: \] + scope: punctuation.section.brackets.end.powershell + pop: true + - include: expressions + - match: '' + pop: true + + strings: + - include: double-quoted-string + - include: single-quoted-string + - 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: \@'(?=$) + 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 + + single-quoted-string: + - match: \' + 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 + + double-quoted-string: + - match: '"' + scope: punctuation.definition.string.begin.powershell + push: + - meta_scope: meta.string.powershell string.quoted.double.powershell + - match: '""' + 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+\}' + scope: constant.character.escape.powershell + + 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 + push: + - match: (?=\{|\() + pop: true + - include: comment-line + + 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 + + interpolation: + - match: \$\( + scope: punctuation.section.interpolation.begin.powershell + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.powershell + - meta_content_scope: source.powershell.embedded + - match: \) + scope: punctuation.section.interpolation.end.powershell + pop: true + - include: main + - match: (?=\$) + push: + - clear_scopes: 1 + - meta_scope: meta.interpolation.powershell + - include: variable-no-property + - include: variable + - match: '' + pop: true + + numeric-constant: + - match: \b((0[xX])[\h_]*\h({{integer_suffix}})?)({{bytes_unit}})?\b + captures: + 1: constant.numeric.integer.hexadecimal.powershell + 2: punctuation.definition.numeric.base.powershell + 3: storage.type.numeric.powershell + 4: keyword.other.unit.powershell + - match: \b((0[bB])[01_]*[01]({{integer_suffix}})?)({{bytes_unit}})?\b + captures: + 1: constant.numeric.integer.binary.powershell + 2: punctuation.definition.numeric.base.powershell + 3: storage.type.numeric.powershell + 4: keyword.other.unit.powershell + - match: |- + (?x: + ( + \b{{dec_digits}} + (?: + (?: + (?:(\.(?!\.))\d*) # No `_` after the `.` + {{dec_exponent}}? + | {{dec_exponent}} + ) + ({{float_suffix}})? + | ({{float_suffix}}) + ) + | \b{{dec_digits}}\.(?!\.) + | (\.)\d+ + ) + ({{bytes_unit}}\b)? + ) + captures: + 1: constant.numeric.float.decimal.powershell + 2: punctuation.separator.decimal.powershell + 3: storage.type.numeric.powershell + 4: storage.type.numeric.powershell + 5: punctuation.separator.decimal.powershell + 6: keyword.other.unit.powershell + - match: \b((?:0|[1-9]{{dec_digits}}?)({{integer_suffix}})?)({{bytes_unit}})?\b + captures: + 1: constant.numeric.integer.decimal.powershell + 2: storage.type.numeric.powershell + 3: keyword.other.unit.powershell + + 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 diff --git a/README.md b/README.md index fbc18b5..c35ed0a 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Adds support for the MS PowerShell programming language. 1. Install [package control][package_control] for Sublime Text. 1. Install the **PowerShell** package: - 1. Press Ctrl + Shift + P (Cmd + Shift + P on Mac) + 1. Press Ctrl+Shift+P (Cmd+Shift+P on Mac) 1. Select 'Install Package' 1. Select 'PowerShell' @@ -20,8 +20,7 @@ You want to contribute? Awesome! Take a look at [CONTRIBUTING.md](CONTRIBUTING.m ### EditorSyntax -Syntax highlighting is provided by the project [EditorSyntax][]. -Issues about the grammar should be opened in **EditorSyntax** instead of this repo. +Syntax highlighting is adapted from the [EditorSyntax][] project. [package_control]: https://sublime.wbond.net/installation [EditorSyntax]: https://github.com/PowerShell/EditorSyntax diff --git a/Snippets/Powershell.sublime-completions b/Snippets/Powershell.sublime-completions index 2776a2f..b3d9dd8 100644 --- a/Snippets/Powershell.sublime-completions +++ b/Snippets/Powershell.sublime-completions @@ -2,16 +2,16 @@ "scope": "source.powershell", "completions": [ - { "trigger": "dict", "contents": "@{$1$0}" }, - { "trigger": "arr", "contents": "@($0)" }, - { "trigger": "req", "contents": "#requires -$0" }, - { "trigger": "reqp", "contents": "#requires -pssnapin $0" }, - { "trigger": "reqv", "contents": "#requires -version ${0:2}" }, + { "trigger": "dict\thashtable", "contents": "@{$1$0}" }, + { "trigger": "arr\tarray", "contents": "@($0)" }, + { "trigger": "req\trequires", "contents": "#requires -$0" }, + { "trigger": "reqp\trequires", "contents": "#requires -pssnapin $0" }, + { "trigger": "reqv\trequires", "contents": "#requires -version ${0:2}" }, { "trigger": "void", "contents": "[void] ($1)$0" }, { "trigger": "sb", "contents": "\\${$1}$0" }, - { "trigger": "wd", "contents": "write-debug -message \"$1\"$0" }, - { "trigger": "wh", "contents": "write-host \"$1\"" }, - { "trigger": "ww", "contents": "write-warning $0" }, + { "trigger": "wd\twrite-debug", "contents": "write-debug -message \"$1\"$0" }, + { "trigger": "wh\twrite-host", "contents": "write-host \"$1\"" }, + { "trigger": "ww\twrite-warning", "contents": "write-warning $0" }, { "trigger": "param", "contents": "param(\\$${1:paramName})" } ] } diff --git a/Support/PowerShell.sublime-settings b/Support/PowerShell.sublime-settings new file mode 100644 index 0000000..77a3a3b --- /dev/null +++ b/Support/PowerShell.sublime-settings @@ -0,0 +1,6 @@ +{ + "word_wrap": false, + "translate_tabs_to_spaces": true, + // Skip `-` in word separators + "word_separators": "./\\()\"':,.;<>~!@#$%^&*|+=[]{}`~?", +} diff --git a/Support/PowershellSyntax.tmLanguage b/Support/PowershellSyntax.tmLanguage deleted file mode 100644 index 26a9108..0000000 --- a/Support/PowershellSyntax.tmLanguage +++ /dev/null @@ -1,1548 +0,0 @@ - - - - - fileTypes - - ps1 - psm1 - psd1 - - name - PowerShell - patterns - - - begin - <# - beginCaptures - - 0 - - name - punctuation.definition.comment.block.begin.powershell - - - end - #> - endCaptures - - 0 - - name - punctuation.definition.comment.block.end.powershell - - - name - comment.block.powershell - patterns - - - include - #commentEmbeddedDocs - - - - - match - [2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>> - name - keyword.operator.redirection.powershell - - - include - #commands - - - include - #commentLine - - - include - #variable - - - include - #interpolatedStringContent - - - include - #function - - - include - #attribute - - - include - #UsingDirective - - - include - #type - - - include - #hashtable - - - include - #doubleQuotedString - - - include - #scriptblock - - - comment - Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) - include - #doubleQuotedStringEscapes - - - begin - (?<!')' - end - '(?!') - name - string.quoted.single.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - begin - \@"(?=$) - end - ^"@ - name - string.quoted.double.heredoc.powershell - patterns - - - include - #variableNoProperty - - - include - #doubleQuotedStringEscapes - - - include - #interpolation - - - - - begin - \@'(?=$) - end - ^'@ - name - string.quoted.single.heredoc.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - include - #numericConstant - - - begin - (@)(\() - beginCaptures - - 1 - - name - keyword.other.array.begin.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - name - meta.group.array-expression.powershell - patterns - - - include - $self - - - - - begin - (\$)(\() - beginCaptures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - comment - TODO: move to repo; make recursive. - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - name - meta.group.complex.subexpression.powershell - patterns - - - include - $self - - - - - match - (\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b) - name - support.function.powershell - - - match - (?<!\w|-)((?i:begin|break|catch|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|foreach(?!-object)|from|if|in|inlinescript|parallel|param|process|return|switch|throw|trap|try|until|var|where(?!-object)|while)|%|\?)(?!\w) - name - keyword.control.powershell - - - match - (?<!\w)(--%)(?!\w) - name - keyword.control.powershell - - - comment - This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. - match - (?<!\w)((?i:hidden|static))(?!\w) - name - storage.modifier.powershell - - - captures - - 1 - - name - storage.type.powershell - - 2 - - name - entity.name.function - - - comment - capture should be entity.name.type, but it doesn't provide a good color in the default schema. - match - (?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b - - - match - (?<!\w)-(?i:is(?:not)?|as)\b - name - keyword.operator.comparison.powershell - - - match - (?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) - name - keyword.operator.comparison.powershell - - - match - (?<!\w)-(?i:join|split)(?!\p{L})|! - name - keyword.operator.unary.powershell - - - match - (?<!\w)-(?i:and|or|not|xor)(?!\p{L})|! - name - keyword.operator.logical.powershell - - - match - (?<!\w)-(?i:band|bor|bnot|bxor)(?!\p{L}) - name - keyword.operator.bitwise.powershell - - - match - (?<!\w)-(?i:f)(?!\p{L}) - name - keyword.operator.string-format.powershell - - - match - [+%*/-]?=|[+/*%-] - name - keyword.operator.assignment.powershell - - - match - \|{2}|&{2}|; - name - keyword.other.statement-separator.powershell - - - match - &|(?<!\w)\.(?= )|`|,|\| - name - keyword.operator.other.powershell - - - comment - This is very imprecise, is there a syntax for 'must come after...' - match - (?<!\s|^)\.\.(?=\-?\d|\(|\$) - name - keyword.operator.range.powershell - - - repository - - commentLine - - begin - (?<![`\\-])# - captures - - 0 - - name - punctuation.definition.comment.powershell - - - end - $ - name - comment.line.powershell - patterns - - - include - #commentEmbeddedDocs - - - include - #RequiresDirective - - - - attribute - - begin - (\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength)\b - beginCaptures - - 1 - - name - punctuation.section.bracket.begin.powershell - - 2 - - name - support.function.attribute.powershell - - - end - (\]) - endCaptures - - 1 - - name - punctuation.section.bracket.end.powershell - - - name - meta.attribute.powershell - patterns - - - begin - \( - beginCaptures - - 0 - - name - punctuation.section.group.begin.powershell - - - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - patterns - - - include - #variable - - - include - #variableNoProperty - - - include - #hashtable - - - include - #scriptblock - - - include - #doubleQuotedStringEscapes - - - include - #doubleQuotedString - - - include - #type - - - include - #numericConstant - - - include - #doubleQuotedString - - - include - $self - - - match - (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=) - captures - - 1 - - name - variable.parameter.attribute.powershell - - 2 - - name - keyword.operator.assignment.powershell - - - - - begin - (?<!')' - end - '(?!') - name - string.quoted.single.powershell - patterns - - - match - '' - name - constant.character.escape.powershell - - - - - - - - commands - - patterns - - - comment - Verb-Noun pattern: - match - (?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Deploy|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?i:exe|cmd|bat|ps1))?\b - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:foreach-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:where-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:sort-object)(?!\w) - name - support.function.powershell - - - comment - Builtin cmdlets with reserved verbs - match - (?<!\w)(?i:tee-object)(?!\w) - name - support.function.powershell - - - - commentEmbeddedDocs - - patterns - - - captures - - 1 - - name - constant.string.documentation.powershell - - 2 - - name - keyword.operator.documentation.powershell - - - match - (?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|EXTERNALHELP|FORWARDHELPCATEGORY|FORWARDHELPTARGETNAME|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|REMOTEHELPRUNSPACE|ROLE|SYNOPSIS)) - name - comment.documentation.embedded.powershell - - - captures - - 1 - - name - constant.string.documentation.powershell - - 2 - - name - keyword.operator.documentation.powershell - - 3 - - name - keyword.operator.documentation.powershell - - - match - (?i:\s*(\.)(PARAMETER|FORWARDHELPTARGETNAME|FORWARDHELPCATEGORY|REMOTEHELPRUNSPACE|EXTERNALHELP)\s+([a-z0-9-_]+)) - name - comment.documentation.embedded.powershell - - - - doubleQuotedStringEscapes - - patterns - - - match - `[0abnfrvt"'$`] - name - constant.character.escape.powershell - - - match - "" - name - constant.character.escape.powershell - - - - function - - begin - ^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) - beginCaptures - - 0 - - name - meta.function.powershell - - 1 - - name - storage.type.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - entity.name.function.powershell - - - end - (?=\{|\() - patterns - - - include - #commentLine - - - - interpolatedStringContent - - begin - \( - beginCaptures - - 0 - - name - punctuation.section.group.begin.powershell - - - contentName - interpolated.simple.source.powershell - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - patterns - - - include - $self - - - include - #interpolation - - - include - #interpolatedStringContent - - - - interpolation - - begin - (\$)(\() - beginCaptures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.group.begin.powershell - - - contentName - interpolated.complex.source.powershell - end - \) - endCaptures - - 0 - - name - punctuation.section.group.end.powershell - - - patterns - - - include - $self - - - include - #interpolation - - - include - #interpolatedStringContent - - - - numericConstant - - patterns - - - captures - - 1 - - name - constant.numeric.hex.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?0(?:x|X)[0-9a-fA-F_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?(?:[0-9_]+)?\.[0-9_]+(?:(?:e|E)[0-9]+)?(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.octal.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?0(?:b|B)[01_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b - - - captures - - 1 - - name - constant.numeric.integer.powershell - - 2 - - name - keyword.other.powershell - - - match - (?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b - - - - scriptblock - - begin - \{ - beginCaptures - - 0 - - name - punctuation.section.braces.begin.powershell - - - end - \} - endCaptures - - 0 - - name - punctuation.section.braces.end.powershell - - - name - meta.scriptblock.powershell - patterns - - - include - $self - - - - type - - begin - \[ - beginCaptures - - 0 - - name - punctuation.section.bracket.begin.powershell - - - end - \] - endCaptures - - 0 - - name - punctuation.section.bracket.end.powershell - - - patterns - - - match - (?!\d+|\.)(?:\p{L}|\p{N}|\.)+ - name - storage.type.powershell - - - include - $self - - - - variable - - patterns - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - constant.language.powershell - - - comment - These are special constants. - match - (\$)(?i:(False|Null|True))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.variable.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - These are the other built-in constants. - match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.automatic.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - Automatic variables are not constants, but they are read-only. In monokai (default) color schema support.variable doesn't have color, so we use constant. - match - (\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))((?:\.(?:\p{L}|\d|_)+)*\b)?\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - variable.language.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - Style preference variables as language variables so that they stand out. - match - (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))((?:\.(?:\p{L}|\d|_)+)*\b)?\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - 3 - - name - storage.modifier.scope.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end.powershell - - 6 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.drive.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - 3 - - name - support.variable.drive.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end.powershell - - 6 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? - - - - UsingDirective - - match - (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+)) - captures - - 1 - - name - keyword.control.using.powershell - - 2 - - name - keyword.other.powershell - - 3 - - name - variable.parameter.powershell - - - - RequiresDirective - - begin - (?<=#)(?i:(requires))\s - beginCaptures - - 0 - - name - keyword.control.requires.powershell - - - end - $ - name - meta.requires.powershell - patterns - - - match - \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version) - name - keyword.other.powershell - - - match - (?<!-)\b\p{L}+|\d+(?:\.\d+)* - name - variable.parameter.powershell - - - include - #hashtable - - - - variableNoProperty - - patterns - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - constant.language.powershell - - - comment - These are special constants. - match - (\$)(?i:(False|Null|True))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.constant.variable.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - These are the other built-in constants. - match - (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.automatic.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - Automatic variables are not constants, but they are read-only... - match - (\$)(?i:(\$|\^|\?|_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - variable.language.powershell - - 3 - - name - entity.name.function.invocation.powershell - - - comment - Style preference variables as language variables so that they stand out. - match - (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|ProgressPreference|PsCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|VerbosePreference|WarningPreference|WhatIfPreference))\b - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+)) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - storage.modifier.scope.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - keyword.other.powershell - - 5 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - support.variable.drive.powershell - - 3 - - name - variable.other.readwrite.powershell - - 4 - - name - entity.name.function.invocation.powershell - - - match - (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+)) - - - captures - - 1 - - name - keyword.other.variable.definition.powershell - - 2 - - name - punctuation.section.braces.begin - - 3 - - name - support.variable.drive.powershell - - 4 - - name - variable.other.readwrite.powershell - - 5 - - name - punctuation.section.braces.end - - - match - (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) - - - - hashtable - - begin - (@)(\{) - beginCaptures - - 1 - - name - keyword.other.hashtable.begin.powershell - - 2 - - name - punctuation.section.braces.begin.powershell - - - end - (\}) - endCaptures - - 1 - - name - punctuation.section.braces.end.powershell - - - name - meta.hashtable.powershell - patterns - - - captures - - 1 - - name - punctuation.definition.string.begin.powershell - - 2 - - name - variable.other.readwrite.powershell - - 3 - - name - punctuation.definition.string.end.powershell - - 4 - - name - keyword.operator.assignment.powershell - - - match - \b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)? - name - meta.hashtable.assignment.powershell - - - include - #scriptblock - - - include - $self - - - - doubleQuotedString - - begin - (?<!(?<!`)")" - end - "(?!") - name - string.quoted.double.powershell - patterns - - - match - (?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b - - - include - #variableNoProperty - - - include - #variable - - - include - #doubleQuotedStringEscapes - - - include - #interpolation - - - match - `\s*$ - name - keyword.other.powershell - - - - - scopeName - source.powershell - uuid - f8f5ffb0-503e-11df-9879-0800200c9a66 - - diff --git a/Symbol List Functions.tmPreferences b/Symbol List Functions.tmPreferences deleted file mode 100644 index b13ff01..0000000 --- a/Symbol List Functions.tmPreferences +++ /dev/null @@ -1,17 +0,0 @@ - - - - - name - Symbol List: Functions - scope - source.powershell meta.function - settings - - showInSymbolList - 1 - - uuid - f935a7e0-c4fd-11e3-9c1a-0800200c9a66 - - diff --git a/Tests/syntax_test_Class.ps1 b/Tests/syntax_test_Class.ps1 new file mode 100644 index 0000000..89b52ac --- /dev/null +++ b/Tests/syntax_test_Class.ps1 @@ -0,0 +1,128 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" +using namespace system.management.automation +# <- keyword.control.using +# ^^^^^^^^^ keyword.other +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter + +# Define a class +class TypeName +# <- storage.type +# ^^^^^^^^ entity.name.class +# @@@@@@@@ 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 + [string] $P1 + # <- punctuation.section.brackets.begin + # ^^^^^ storage.type + # ^ punctuation.section.brackets.end + # ^ punctuation.definition.variable + # ^^ variable.other.readwrite + + # 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 + + # 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 + + # 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 + $this.P1 = $s + # <- punctuation.definition.variable + # ^ variable.language + # ^^ variable.other.member + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + } + + # Static method + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^ comment.line + static [void] MemberMethod1([hashtable] $h) { + # <- storage.modifier + # ^ punctuation.section.brackets.begin + # ^^^^ storage.type + # ^ punctuation.section.brackets.end + # ^ punctuation.section.group.begin + # ^ punctuation.section.brackets.begin + # ^^^^^^^^^ storage.type + # ^ punctuation.section.brackets.end + # ^ punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.section.group.end + [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 + } + + # Instance method + # <- punctuation.definition.comment + # ^^^^^^^^^^^^^^^ comment.line + [int] MemberMethod2([int] $i) { + # <- punctuation.section.brackets.begin + # ^ storage.type + # ^ punctuation.section.brackets.end + # ^ 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 + return $this.P3 + # <- keyword.control + # ^ punctuation.definition.variable + # ^^^^ variable.language + # ^^ variable.other.member + } +} diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 new file mode 100644 index 0000000..3c16339 --- /dev/null +++ b/Tests/syntax_test_Function.ps1 @@ -0,0 +1,399 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + +using module Microsoft.Management +# <- keyword.control.using +# ^ keyword.other +# ^ variable.parameter + +<# +# <- punctuation.definition.comment.block.begin + .Synopsis + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Short description + .DESCRIPTION + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Long description + .EXAMPLE + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Example of how to use this cmdlet + .EXAMPLE + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Another example of how to use this cmdlet + .INPUTS + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Inputs to this cmdlet (if any) + .OUTPUTS + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + Output from this cmdlet (if any) + .NOTES + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + General notes + .COMPONENT + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + The component this cmdlet belongs to + .ROLE + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + The role this cmdlet belongs to + .FUNCTIONALITY + # <- punctuation.definition.keyword + # ^ keyword.other.documentation + The functionality that best describes this cmdlet + + This should not be considered documentaton -> .role + # ^ - keyword.operator.documentation +#> +# <- punctuation.definition.comment.block.end +function Verb-Noun { +#^^^^^^^^^^^^^^^^^ meta.function +#^^^^^^^ storage.type +# ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition + [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + SupportsShouldProcess = $true, + # ^^^^^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^ meta.attribute constant.language + PositionalBinding = $false, + # ^^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute punctuation.definition.variable + # ^^^^^ meta.attribute constant.language + HelpUri = 'http://www.microsoft.com/', + # ^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + ConfirmImpact = 'Medium')] + # ^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [Alias()] + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.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 + Param + #^^^^^ keyword.declaration.parameter + ( + # <- punctuation.section.group.begin + # Param1 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(Mandatory=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipeline=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell + # ^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipelineByPropertyName = $true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + ValueFromRemainingArguments=$false, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + Position=0, + #^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ constant.numeric.integer + # ^ punctuation.separator + ParameterSetName = 'Parameter Set 1')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + # ^ - meta.attribute + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateNotNull()] + #^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateCount(0,5)] + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateSet("sun", "moon", "earth")] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [Alias("p1")] + #^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + $Param1, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.separator + + # Param2 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ support.function.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + # ^ - meta.attribute + [AllowNull()] + #^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [AllowEmptyCollection()] + #^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [AllowEmptyString()] + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [ValidateScript({$true})] + #^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ meta.attribute + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ meta.attribute + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateRange(0,5)] + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [int32] + # <- punctuation.section.brackets.begin + #^^^^^ storage.type + # ^ punctuation.section.brackets.end + $Param2, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.separator + + # Param3 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Another Parameter Set')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [ValidatePattern("[a-z]*")] + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^ meta.attribute string.quoted.double + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [ValidateLength(0,15)] + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute constant.numeric.integer + # ^ punctuation.separator + # ^^ meta.attribute constant.numeric.integer + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [String] + # <- punctuation.section.brackets.begin + #^^^^^^ storage.type + # ^ punctuation.section.brackets.end + $Param3, + # <- punctuation.definition.variable + #^^^^^^ variable.other.readwrite + # ^ punctuation.separator + + # Param4 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^ meta.attribute meta.block + # ^^^^^^^^^ meta.block support.function + # ^ meta.block punctuation.definition.variable + # ^ meta.block variable.language + # ^ meta.attribute meta.block + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [string] + # <- punctuation.section.brackets.begin + # ^ storage.type + # ^ punctuation.section.brackets.end + $Param4, + # <- punctuation.definition.variable + # ^ variable.other.readwrite + # ^ punctuation.separator + + # Param5 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(ParameterSetName='Parameter Set 1')] + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^ meta.attribute variable.parameter.attribute + # ^ meta.attribute keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + [ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting + # <- meta.attribute punctuation.section.brackets.begin + # ^ meta.attribute support.function.attribute + # ^ meta.attribute punctuation.section.group.begin + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute string.quoted.single + # ^ meta.attribute punctuation.section.group.end + # ^ meta.attribute punctuation.section.brackets.end + # ^ comment.line punctuation.definition.comment + # ^ comment.line + [string] + # <- punctuation.section.brackets.begin + # ^ storage.type + # ^ punctuation.section.brackets.end + $Param5 + # <- punctuation.definition.variable + # ^ variable.other.readwrite + ) + # <- punctuation.section.group.end + + Begin + #^^^^^ keyword.context.block.begin + { + } + Process { + # <- keyword.control + 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 + } + } + End { + #^^^ keyword.context.block.end + + } +} diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 new file mode 100644 index 0000000..119d609 --- /dev/null +++ b/Tests/syntax_test_PowerShell.ps1 @@ -0,0 +1,1532 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" +using namespace System.Management.Automation +# <- keyword.control.using +# ^ keyword.other +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter +#Requires -PSSnapin DiskSnapin -Version 1.2 +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter +# ^^^^^^^^ variable.parameter +#Requires -PSSnapin DiskSnapin +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter +#Requires -Version 3 +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +#Requires -Version 3.0 +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +#Requires -Version 3 -RunAsAdministrator +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^^^^^^^^^^^^^^^^^^^ variable.parameter +#Requires -RunAsAdministrator +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^^ variable.parameter +#Requires -Modules PSWorkflow +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +#Requires -Modules PSWorkflow -ThisIsInvalid +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^^^^^^^^ - variable.parameter +#Requires -Modules PSWorkflow, ActiveDirectory +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator +#Requires -Modules PSWorkflow,ActiveDirectory +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator +#Requires -ShellId MyLocalShell +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +#Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"} +# <- punctuation.definition.keyword +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.requires +#^^^^^^^^ keyword.control.import.require +# ^^^^^^^^ variable.parameter +# ^ punctuation.separator +# ^^^^^^^^^^ meta.requires meta.hashtable variable.other.readwrite +# ^ meta.requires meta.hashtable +# ^^^^^^^^^^^^^^^^ meta.requires meta.hashtable string.quoted.double +# ^ 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 + +# 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 + +# Hashtable +$properties = @{ +# <- punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ keyword.other.hashtable.begin +# ^ punctuation.section.braces.begin + Name = 'Name' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^ meta.hashtable string.quoted.single + Something = $else + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # Atom-grammar-test is not tokenizing this correctly... Need to test in Atom - TODO + Number = 16 + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^ meta.hashtable constant.numeric.integer + from = 'hello world' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^^^^^^^^^^^^ meta.hashtable string.quoted.single + hash = @{ + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^ keyword.other.hashtable.begin + # ^ punctuation.section.braces.begin + hello = 'world' + # <- meta.hashtable meta.hashtable.assignment variable.other.readwrite + # ^ meta.hashtable meta.hashtable.assignment keyword.operator.assignment + # ^^^^^^^ meta.hashtable string.quoted.single + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# Spatting + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + +# ScriptBlock + {Invoke-Something @properties} +# ^ punctuation.section.braces.begin +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.braces.end +{ +# <- punctuation.section.braces.begin + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +} +# <- punctuation.section.braces.end +$sb = { +# <- punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ punctuation.section.braces.begin + Invoke-Something @properties +# ^^^^^^^^^^^^^^^^ support.function +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +} +# <- punctuation.section.braces.end + +# Arrays +$a1 = @(1,2,3,4) +# <- variable.other.readwrite punctuation.definition.variable +#^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end +# ^^^^^^^ meta.group.array-expression +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence +# ^ constant.numeric.integer +$a2 = ('one','two','three','four') +# <- variable.other.readwrite punctuation.definition.variable +#^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ punctuation.section.group.begin +# ^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^^^ string.quoted.single +# ^ punctuation.separator.sequence +# ^^^^^^ string.quoted.single +# ^ punctuation.section.group.end +$a3 = $one, $two, $three, $four +# <- variable.other.readwrite punctuation.definition.variable +#^^ variable.other.readwrite +# ^ punctuation.definition.variable +# ^^^^ variable.other.readwrite +# ^ punctuation.definition.variable +# ^^^^ variable.other.readwrite +# ^ punctuation.definition.variable +# ^^^^^^ variable.other.readwrite +# ^ punctuation.definition.variable +# ^^^^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^ punctuation.separator +# ^ punctuation.separator +# ^ punctuation.separator +$a1[0] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.brackets.begin +# ^ constant.numeric.integer +# ^ punctuation.section.brackets.end +# ^^^ meta.brackets.indexer +$a2[-1] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.brackets.begin +# ^ constant.numeric.integer +# ^ punctuation.section.brackets.end +# ^^^^ meta.brackets.indexer +$a3[1..2] +# <- variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.brackets.begin +# ^ constant.numeric.integer +# ^^ keyword.operator.range +# ^ constant.numeric.integer +# ^ punctuation.section.brackets.end +# ^^^^^^ meta.brackets.indexer + @(@($a)) +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^^ punctuation.section.group.end + @(($i = 10); (++$j)) +# ^ keyword.other.array.begin +# ^^ punctuation.section.group.begin +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ punctuation.terminator.statement +# ^ punctuation.section.group.begin +# ^^ keyword.operator.assignment +# ^ variable.other.readwrite punctuation.definition.variable +# ^ variable.other.readwrite +# ^^ punctuation.section.group.end + @($i = 10) +# ^ keyword.other.array.begin +# ^ punctuation.section.group.begin +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ punctuation.section.group.end + $i[($y - 1) + $x] +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^ punctuation.section.brackets.begin +# ^ punctuation.section.group.begin +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^ keyword.operator.arithmetic +# ^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ keyword.operator.arithmetic +# ^ variable.other.readwrite punctuation.definition.variable +# ^^ variable.other.readwrite +# ^ 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 + "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 + +# Numeric constants + -3 +# ^ keyword.operator.unary +# ^ constant.numeric.integer + .5 +# ^^ constant.numeric.float + +.5 +# ^ keyword.operator.unary +# ^^ constant.numeric.float + 1. +# ^^ constant.numeric.float + 1.d +# ^^^ constant.numeric.float + 1.lGB +# ^^^ constant.numeric.float - unclear whether float or int +# ^^ keyword.other.unit + 1.dGB +# ^^^ constant.numeric.float +# ^^ keyword.other.unit + 1.e+12d +# ^^^^^^^ constant.numeric.float + 1e+12d +# ^^^^^^ constant.numeric.float + 1.5 +# ^^^ constant.numeric.float + -1.5 +# ^ keyword.operator.unary +# ^^^ constant.numeric.float + -3 + -2 +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer + -3+-2 +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer + 3++2 +# ^ constant.numeric.integer +# ^ keyword.operator.arithmetic +# ^ keyword.operator.unary +# ^ constant.numeric.integer + +2 +# ^ keyword.operator.unary +# ^ constant.numeric.integer + -3+- +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^^ keyword.operator + 10/-10 +# ^^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^ keyword.operator + 10/-10D +# ^^ constant.numeric.integer +# ^^^ constant.numeric.float +# ^ keyword.operator + -10.002L +# ^ keyword.operator.unary +# ^^^^^^^ constant.numeric.float - unclear whether float or int + $x..5.40D +# ^ punctuation.definition.variable +# ^^ variable.other.readwrite +# ^^ keyword.operator.range +# ^^^^^ constant.numeric.float + -500..-495 +# ^ keyword.operator.unary +# ^^^ constant.numeric.integer +# ^^ keyword.operator.range +# ^ keyword.operator.unary +# ^^^ constant.numeric.integer + $true..3 +# ^ punctuation.definition.variable +# ^^^^ constant.language +# ^^ keyword.operator.range +# ^ constant.numeric.integer + -2..$null +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^^ keyword.operator.range +# ^^^^^ constant.language +# ^ punctuation.definition.variable + -3..3 +# ^ keyword.operator.unary +# ^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^ keyword.operator.range + 1..3 +# ^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^ keyword.operator.range + 6,10,-3 +# ^ constant.numeric.integer +# ^ punctuation.separator.sequence -constant +# ^^ constant.numeric.integer +# ^ punctuation.separator.sequence -constant +# ^ constant.numeric.integer + 0x476 +# ^^ punctuation.definition.numeric.base +# ^^^^^ constant.numeric.integer.hexadecimal + +0x20 +# ^ keyword.operator.unary +# ^^ punctuation.definition.numeric.base +# ^^^^ constant.numeric.integer.hexadecimal + -0x20 +# ^ keyword.operator.unary +# ^^ punctuation.definition.numeric.base +# ^^^^ constant.numeric.integer.hexadecimal + +# Types +[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 +Invoke-Something -foobar value +# <- support.function +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option +Invoke-Something -foobar:$true +# <- support.function +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option +# ^ punctuation.definition.variable +# ^^^^ constant.language +Invoke-Something -foobar: $true +# <- support.function +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option +Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose +# <- support.function +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^^ constant.numeric.integer +# ^^^^^^ - keyword +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +Invoke-Something (1..20 | Invoke-Something) -p2 'value' +# <- support.function +# ^^ keyword.operator.range +Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch +# <- support.function +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^^ constant.numeric.integer +# ^ keyword.operator.logical.pipe +# ^ support.function +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option - keyword +Invoke-Something -p1 { +# <- support.function +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option + Invoke-Something -foobar:$true +# ^ support.function +# ^ punctuation.definition.parameter +# ^^^^^^^ variable.parameter.option +# ^ punctuation.definition.variable +# ^^^^ constant.language +} | Invoke-Something +# <- punctuation.section.braces.end +# ^ keyword.operator.logical.pipe +# ^ support.function +Invoke-Something -p1 value ` +# <- support.function +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ punctuation.separator.continuation + -p2 14.4 ` +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^^^^ constant.numeric.float +# ^ punctuation.separator.continuation + -p3 $value | Invoke-Something -verbose +# ^ punctuation.definition.parameter +# ^^^ variable.parameter.option +# ^ 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 + +# switch +switch ("fourteen") {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch -CaseSensitive ("fourteen") {} +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^^^^^^^^^ variable.parameter.option +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch -Regex ("fourteen") {} +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option +# ^ punctuation.section.group.begin +# ^ string.quoted.double +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch -Wildcard ($a) {} +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^^^^ variable.parameter.option +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch -regex -file .\somefile.txt {} +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^ variable.parameter.option +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch (3) {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +switch (4, 2) {} +# <- keyword.control +# ^ punctuation.section.group.begin +# ^ constant.numeric.integer +# ^ constant.numeric.integer +# ^ punctuation.separator +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end + +switch -Regex -File $filePath { +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^ variable.parameter.option +# ^ punctuation.definition.variable +# ^ meta.block punctuation.section.braces.begin + '.' {} +# ^^^ string.quoted.single +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +} +# <- meta.block punctuation.section.braces.end + +switch -Wildcard -CaseSensitive ($something) { +# <- keyword.control +# ^ punctuation.definition.parameter +# ^^^^^^^^^ variable.parameter.option +# ^ punctuation.definition.parameter +# ^^^^^^^^^^^^^^ variable.parameter.option +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin + '.' {} +# ^^^ string.quoted.single +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +} +# <- meta.block punctuation.section.braces.end + +switch ('this') { +# <- keyword.control +# ^ punctuation.section.group.begin +# ^^^^^^ string.quoted.single +# ^ punctuation.section.group.end +# ^ meta.block punctuation.section.braces.begin + 'this' {} +# ^^^^^^ string.quoted.single +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end + default {} +# ^^^^^^^ keyword.control +# ^ meta.block punctuation.section.braces.begin +# ^ meta.block punctuation.section.braces.end +} +# <- meta.block punctuation.section.braces.end + +# Functions and filters +functioN MyFunction{} +# <- storage.type +# ^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function My-Function {} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +Function My.Function{} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function My-Function.Other{} +# <- storage.type +# ^^^^^^^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function Some.other.function{} +# <- storage.type +# ^^^^^^^^^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +FUNCTION MyFunction2 {} +# <- storage.type +# ^^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function New-File { } +# <- storage.type +# ^^^^^^^^ entity.name.function +# @@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function New-File ($Name) { } +# <- storage.type +# ^^^^^^^^ entity.name.function +# @@@@@@@@ definition +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +function NewFile($Name) { } +# <- storage.type +# ^^^^^^^ entity.name.function +# @@@@@@@ definition +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +filter myfilter($param) {} +# <- storage.type +# ^^^^^^^^ entity.name.function +# @@@@@@@@ definition +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +Filter my-Filter ($param){} +# <- storage.type +# ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition +# ^ punctuation.section.group.begin +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + +# Note that the # in the path should highlight as a comment! +function Test-Drive([string]$roman) { +# <- storage.type +# ^^^^^^^^^^ entity.name.function +# @@@@@@@@@@ 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 + $roman | c:\users\Me\Documents\Programming\F#\test.exe $roman +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ keyword.operator.logical.pipe +# ^ punctuation.definition.comment +# ^^^^ comment.line +} +# <- punctuation.section.braces.end + +function Verb-Noun +#^^^^^^^^^^^^^^^^^ meta.function +#^^^^^^^ storage.type +# ^^^^^^^^^ meta.function entity.name.function +# @@@@@@@@@ definition +{ +# <- punctuation.section.braces.begin + + Param + #^^^^^ keyword.declaration.parameter + ( + # <- punctuation.section.group.begin + # Param1 help description + # <- comment.line punctuation.definition.comment + # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line + [Parameter(Mandatory=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipeline=$true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell + # ^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^ constant.language + # ^ punctuation.separator + ValueFromPipelineByPropertyName = $true, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + ValueFromRemainingArguments=$false, + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ punctuation.definition.variable + # ^^^^^ constant.language + # ^ punctuation.separator + Position=0, + #^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^ constant.numeric.integer + # ^ punctuation.separator + SupportsPaging, + #^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ punctuation.separator + ParameterSetName = 'Parameter Set 1')] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # ^^^^^^^^^^^^^^^^ variable.parameter.attribute + # ^ keyword.operator.assignment + # ^^^^^^^^^^^^^^^^^ string.quoted.single + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + # ^ - meta.attribute + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateNotNull()] + #^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateNotNullOrEmpty()] + #^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateCount(0,5)] + #^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^^^^^^^^^^^^ support.function.attribute + # ^ punctuation.section.group.begin + # ^ constant.numeric.integer + # ^ punctuation.separator + # ^ constant.numeric.integer + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [ValidateSet("sun", "moon", "earth")] + #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^ string.quoted.double + # ^ punctuation.separator + # ^^^^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + [Alias("p1")] + #^^^^^^^^^^^^ meta.attribute + # <- punctuation.section.brackets.begin + # ^ support.function.attribute + # ^ punctuation.section.group.begin + # ^^^^ string.quoted.double + # ^ punctuation.section.group.end + # ^ punctuation.section.brackets.end + $Param1 + # <- punctuation.definition.variable + # ^ variable.other.readwrite + ) + # <- punctuation.section.group.end + + # Do Something.... + +} +# <- punctuation.section.braces.end + +# Class +class Vehicle { +# <- storage.type.class +# ^^^^^^^ entity.name.class +# @@@@@@@ definition +# ^ punctuation.section.braces.begin + Vehicle() {} +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + Vehicle([string]$Owner) { +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite +# ^ punctuation.section.braces.begin + $this.Owner = $Owner + } + + [int]$Mileage +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + [int]$Age +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + [string]$Owner +# ^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + + [void]Drive([int]$NumberOfMiles) { +# ^^^^ storage.type +# ^^^ storage.type +# ^ punctuation.definition.variable +# ^ variable.other.readwrite + $this.Mileage += $NumberOfMiles +# ^^^^^ variable.language +# ^ punctuation.definition.variable +# ^^^^^^^ variable.other.member +# ^^ keyword.operator.assignment + + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# Control words +foreach ($item in $collection) { +# <- keyword.control +# ^ punctuation.section.group.begin +# ^^ keyword.control +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.definition.variable +# ^ punctuation.definition.variable +} +# <- punctuation.section.braces.end + +try { } +# <- keyword.control +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +catch { } +# <- keyword.control +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end + +# Reserved words +Configuration Crazyness { +# <- storage.type +# ^^^^^^^^^ entity.name.function +# @@@@@@@@@ definition +# ^ punctuation.section.braces.begin + Node Whatever { +# ^ punctuation.section.braces.begin + } + # <- punctuation.section.braces.end +} +# <- punctuation.section.braces.end + +# 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 +# ^^ constant.numeric.integer +# ^^^^ keyword.operator.comparison +# ^^^ constant.numeric.integer +# ^ punctuation.section.group.end +# ^ punctuation.section.braces.begin +# ^ punctuation.section.braces.end +$a -is $b +# ^^^ keyword.operator.logical +$b -contains $c +# ^^^^^^^^^ keyword.operator.logical +$x -notcontains $c +# ^^^^^^^^^^^^ keyword.operator.logical +$c -in $b +# ^^^ keyword.operator.logical +$c -notin $x +# ^^^^^^ keyword.operator.logical +$a -match $b +# ^^^^^^ keyword.operator.logical +$a -notmatch $b +# ^^^^^^^^^ keyword.operator.logical +$x -like $c +# ^^^^^ keyword.operator.logical +100 -and 0 +# ^^^^ keyword.operator.logical +# ^ constant.numeric.integer +$a -ceq 4 -and $a -ine $d -or +# ^^^^ keyword.operator.comparison +# ^ constant.numeric.integer +# ^^^^ keyword.operator.logical +# ^ punctuation.definition.variable +# ^^^^ keyword.operator.comparison +# ^^^ keyword.operator.logical +$c -is [Type] +# ^^^ keyword.operator.logical +# ^ storage.type +$c -isnot [Type] +# ^^^^^^ keyword.operator.logical +# ^ storage.type +$c -as [Type] +# ^^^ keyword.operator.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 +# ^ constant.numeric.integer +# ^^ constant.numeric.integer +# ^^^^ keyword.operator.bitwise +$r = 10 -shr 1 +# ^ keyword.operator.assignment +# ^^ constant.numeric.integer +# ^ constant.numeric.integer +# ^^^^ keyword.operator.bitwise +$k = $y -xor $b +# ^ keyword.operator.assignment +# ^ keyword.operator.logical +$k = $y -bxor $b +# ^ keyword.operator.assignment +# ^ keyword.operator.bitwise +$a -icontains $c +# ^^^^^^^^^^ keyword.operator.logical +$a -ccontains $c +# ^^^^^^^^^^ keyword.operator.logical +$a -iNotContains $c +# ^^^^^^^^^^^^^ keyword.operator.logical +$a -cNotContains $c +# ^^^^^^^^^^^^^ keyword.operator.logical +$a -cmatch $c +# ^^^^^^^ keyword.operator.logical +$x -iMatch $c +# ^^^^^^^ keyword.operator.logical +$x -iNotMatch $c +# ^^^^^^^^^^ keyword.operator.logical +$a -iLike $b +# ^^^^^^ keyword.operator.logical +$b -cLike $c +# ^^^^^^ keyword.operator.logical +"hey" -cgt "Hey" +# ^^^^ keyword.operator.comparison +"Hey" -igt "hey" +# ^^^^ keyword.operator.comparison +"hey" -cge "Hey" +# ^^^^ keyword.operator.comparison +"Hey" -ige "hey" +# ^^^^ keyword.operator.comparison +"HEY" -clt "hey" +# ^^^^ keyword.operator.comparison +"HEY" -ilt "hey" +# ^^^^ keyword.operator.comparison +"HEY" -cle "hey" +# ^^^^ keyword.operator.comparison +"HEY" -ile "hey" +# ^^^^ keyword.operator.comparison + +# format + "{0:N2}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:D8}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:C2}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:P0}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:X0}" -f $a +# ^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + (1.11).ToString("#.#") +# ^ punctuation.section.group.begin +# ^ punctuation.section.group.begin +# ^^^^ constant.numeric.float +# ^ string.quoted.double + "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 +# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format +# ^^^ constant.numeric.integer + ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) +# ^^ keyword.operator.string-format +# ^^^^ constant.numeric.float +# ^^^^^^^^^^^^^ string.quoted.double +# ^^ keyword.operator.string-format + "{0:R}" -f (1mb/2.0) +# ^ keyword.operator.string-format +# ^ constant.numeric.integer +# ^^ keyword.other.unit + "{0:00.0}" -f 4.12341234 +# ^ keyword.operator.string-format + "{0:##.#}" -f 4.12341234 +# ^ string.quoted.double +# ^ keyword.operator.string-format +# ^^^^^^^^^^ constant.numeric.float.decimal + "{0:#,#.#}" -f 1234.121234 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:##,,.000}" -f 1048576 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{this is not a #comment}" +# ^ - comment + "{0:##.#E000}" -f 2.71828 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:#.00'##'}" -f 2.71828 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:POS;NEG;ZERO}" -f -14 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0:$## Please}" -f 14 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0,-8:P1}" -f 1.75 +# ^ string.quoted.double +# ^ keyword.operator.string-format + "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 +# ^ keyword.operator.string-format + '{0:00000.000}' -f 7.125 +# ^ string.quoted.single +# ^ keyword.operator.string-format + +# Misc test cases +Test-Function -Class ClassName +# ^^^^^ - storage.type +New-Object -TypeName System.Diagnostics.Process +# ^^^^^^^ - keyword.control +New-Object -TypeName System.Data +# ^^^^ - keyword.control +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 +$file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" +# <- punctuation.definition.variable +# ^ support.function +# ^ support.variable.drive +# ^ variable.other.readwrite +# ^^ meta.string meta.interpolation punctuation.section.interpolation.begin +# ^ storage.type +# @@@@@@@@@@@@@@@@@ reference +$ScriptBlock | Out-File $file -Force +# <- punctuation.definition.variable +# ^ keyword.operator.logical.pipe +# ^ 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 +get-thing | Out-WithYou > $null # destroy +# ^^^^^^^ support.function +# ^^^^^^^^^^^ support.function +# ^ keyword.operator.logical.pipe +# ^ keyword.operator.redirection +# ^ punctuation.definition.variable +# ^ constant.language +# ^ punctuation.definition.comment +# ^^^^^^^^^ 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 +"When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" +# ^^ punctuation.section.interpolation.begin - source.powershell.embedded +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.powershell.embedded +# ^ keyword.operator.logical.pipe +# ^ meta.group.complex.subexpression punctuation.section.group.begin +# ^^^^^^ storage.type +# ^^ punctuation.accessor.double-colon +# ^^^^^^ meta.function-call variable.function +# @@@@@@ reference +# ^ meta.group.complex.subexpression punctuation.section.arguments.begin +# ^ meta.group.complex.subexpression punctuation.section.arguments.end +# ^ meta.group.complex.subexpression punctuation.section.group.end +# ^ punctuation.definition.variable +# ^ punctuation.section.interpolation.end - source.powershell.embedded +"This is the DebugPreference variable: $DebugPreference" +#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string string.quoted.double +# ^^^^^^^^^^^^^^^^ meta.string meta.interpolation variable.language - string + + $ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^ variable.language - punctuation + $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + + $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation + $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^ variable.language - punctuation + $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $PSSessionConfigurationName $PSSessionOption $ProgressPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^^ variable.language - punctuation + $VerbosePreference $WarningPreference $WhatIfPreference +#^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^^ variable.language - punctuation +# ^ variable.language punctuation +# ^^^^^^^^^^^^^^^^ variable.language - punctuation diff --git a/Tests/syntax_test_reindent.ps1 b/Tests/syntax_test_reindent.ps1 new file mode 100644 index 0000000..5c99463 --- /dev/null +++ b/Tests/syntax_test_reindent.ps1 @@ -0,0 +1,13 @@ +# SYNTAX TEST reindent "Packages/PowerShell/PowerShell.sublime-syntax" +Function Get-ForegroundWindow { + Add-Type @" + using System; using System.Runtime.InteropServices; public class ClassGetForegroundWindow { + [DllImport("user32.dll")] + public static extern IntPtr GetForegroundWindow(); + } +"@ + + return [ClassGetForegroundWindow]::GetForegroundWindow() +} + +Get-ForegroundWindow