├── .github ├── CODE_OF_CONDUCT.md └── SECURITY.md ├── .gitignore ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── PowerShellSyntax.tmLanguage ├── README.md ├── Third Party Notices.txt ├── appveyor.yml ├── build.ps1 ├── examples ├── TheBigTestFile.ps1 ├── advancedFunction.ps1 ├── class.ps1 └── test.ps1 ├── package-lock.json ├── package.json ├── spec ├── powershell-spec.coffee └── testfiles │ ├── syntax_test_Class.ps1 │ ├── syntax_test_Function.ps1 │ └── syntax_test_TheBigTestFile.ps1 └── tools ├── banners.ps1 ├── build-grammar.js └── build-helpers.ps1 /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | - Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support) 11 | -------------------------------------------------------------------------------- /.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin) and [PowerShell](https://github.com/PowerShell). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | syntaxes/ 2 | grammars/ 3 | node_modules/ 4 | atom/ 5 | atom.zip -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Your help is greatly appreciated! This project, like all other open-source projects, thrives through an active community; However, with great power comes great responsibility. So, we have devised a few ground rules that should be followed when contributing. 4 | 5 | ## Get started 6 | 7 | There are a number of ways you can get your feet wet and help us out. 8 | 9 | * [Issues](#Issues): The easiest way to contribute is to identify that something is broken or that a feature is missing and create an issue from it. Even better would be fixing an open issue that has no assignee yet. You can of course do both - find something that is missing and fix it yourself! 10 | * [Reviews](#Reviews): With more contributions coming in we will likely see more pull requests. Reviewing them is not always the most fun, but it is very necessary and would help a lot. 11 | 12 | ### Open an issue 13 | 14 | Opening issues is very easy. Head to our [Issues tab](https://github.com/PowerShell/EditorSyntax/issues) and open one if it does not exist already by clicking [New issue](https://github.com/PowerShell/EditorSyntax/issues/new) and filling out the provided template. Make sure to check the open issues first so you don't duplicate an existing issue! 15 | 16 | If an issue already exists that is in some way related to the one you are opening, e.g. is the basis for something your are requesting, please link to it. See: [Autolinked references and URLs](https://help.github.com/articles/autolinked-references-and-urls/) 17 | 18 | When open your issue be as detailed as possible. The more detail and context you provide in your issue the easier it will be for someone to reproduce and fix. 19 | 20 | ### Fix an issue 21 | 22 | Ready to go deeper and fix an existing issue? 23 | 24 | 1. Leave a comment to tell us that you are working on it so work isn't duplicated by multiple contributors. 25 | 1. [Fork](https://help.github.com/articles/fork-a-repo/) our repository, and base your changes off of the **master** branch by creating a new branch from **master** which will contain your changes. You can name the branch whatever you like but when working on multiple issues descriptive names are best (e.g. "variable-scopes"). 26 | 1. [Fix the issue](https://knowyourmeme.com/memes/how-to-draw-an-owl) in your fork. 27 | 1. Include a [test spec](spec/testfiles) to prevent regressions in the future. 28 | 1. Make sure you have [pushed your commits](https://help.github.com/articles/pushing-to-a-remote/) to your new branch up to Github and then [create a pull request](https://help.github.com/articles/creating-a-pull-request/) to the EditorSyntax **master** branch. 29 | 1. If prompted to sign the CLA, please follow the steps provided. 30 | 31 | See the [Contributing Guide](#contributing-guide) for a detailed step-by-step guide. 32 | 33 | #### Helpful tools/links 34 | 35 | * [TextMate Language Grammars Documentation](https://macromates.com/manual/en/language_grammars) 36 | * [Regular Expressions 101](https://regex101.com/) - Online regex tester, debugger with highlighting for PHP, PCRE, Python, Golang and JavaScript. 37 | * [RegExr](https://regexr.com/) - Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns. 38 | * [Understanding XML Property Lists](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/UnderstandXMLPlist/UnderstandXMLPlist.html#//apple_ref/doc/uid/10000048i-CH6-SW1) 39 | 40 | ## Reviews 41 | 42 | We are using GitHub's [internal capabilities](https://github.com/features/code-review/) for our code reviews. Either we, the EditorSyntax team, or you, the community, can review the changes and add comments. The author of the pull request can then go through all of the issues, fix them and add new commits to their branch, which will show up in the pull request. When all issues are fixed and there is nothing else to do, we will gladly merge the pull request. 43 | 44 | * Changes to the grammar file or continuous integration process should have the approval of two people before being merged. 45 | 46 | # Contributing Guide 47 | 48 | Below is a step by step guide for making changes to the grammar file. 49 | 50 | ## On scopes 51 | 52 | Before working on the grammar file it is important to understand how scopes work at a basic level and how to select an appropriate scope for any additions or modifications. Scopes are names assigned to elements in code by the grammar definition starting with the most generic type first and becoming more specific the further right you go before ending with the language (`.powershell`.) The scope selector on which themes are built reads the scopes right-to-left allowing themes to be as specific or as generic as they wish. 53 | 54 | Take for example comments which could be a line style comment, a block comment, or documentation. Each one would be scoped starting with `comment` allowing the themes to easily assign a colour to all three with a single rule; However, in the grammar we would be more specific so that if they wish themes could delineate them: 55 | 56 | * `comment.line.powershell` 57 | * `comment.block.powershell` 58 | * `comment.documentation.powershell` 59 | 60 | By doing it this way themes can target all three together (`comment`,) one individually (`comment.line`,) and even restrict their colour choice to just PowerShell (`comment.line.powershell`.) 61 | 62 | See: [Introduction to scopes](https://macromates.com/blog/2005/introduction-to-scopes/) for more details. 63 | 64 | ### Scope selection 65 | 66 | When selecting scopes try as much as possible to stick to the [Scope Naming guide](https://www.sublimetext.com/docs/3/scope_naming.html) from [Sublime Text](https://www.sublimetext.com/). It is important to balance these factors: 67 | 68 | * **Accuracy**: The grammar should strive to be as accurate as possible not only at an obvious level (comments not scoped as variables) but also at a finer level (constants not scoped as read-write variables.) 69 | * **Consistency**: Themes should not need to make a special case for PowerShell as themes should be mostly language agnostic so the grammar should strive to define PowerShell in the same way that similar languages are defined. When a user goes back and forth between languages their highlighting experience should be the same. For example, `$Variable.Member` in PowerShell should colour like `$Variable->Member` in PHP. 70 | * **Expectation**: While it is not the job of the grammar to define where colour goes (only where it can go) sweeping changes that have a noticeable impact across a large number of themes should be approached carefully and may result in extended review and discussion. 71 | 72 | There are multiple discussions you can join on the selection of scopes open in our [Issues](https://github.com/PowerShell/EditorSyntax/issues) the most recent being [How we decide on which scopes to use.](https://github.com/PowerShell/EditorSyntax/issues/138) 73 | 74 | ## Fork the repository and create a branch 75 | 76 | Once you're ready to contribute changes to the project you will want to create your own copy to work from. 77 | 78 | 1. Open the [EditorSyntax](https://github.com/PowerShell/EditorSyntax/) project in a browser. 79 | 1. Locate the **Fork** button just below your GitHub avatar in the top-right corner and give it a click. On your own GitHub profile you will now have a YOUR-USER-NAME/EditorSyntax repository to work from. 80 | 1. Clone your fork to your computer using the Git command line: `git clone https://github.com/YOUR-USER-NAME/EditorSyntax.git` 81 | 1. Navigate into your clone: `cd EditorSyntax` 82 | 1. Create a [branch](https://www.atlassian.com/git/tutorials/using-branches) in which to make your changes: `git checkout -b my-branch-name` (`checkout -b` creates a new branch and opens it in a single step.) 83 | 84 | ## Edit the grammar file 85 | 86 | Once you're on your new branch (`git branch` to be sure) the actual magic happens in the file called `PowerShellSyntax.tmLanguage` which is an XML-plist file. You can either open it directly in your favourite editor or in editors that support it you can open the whole directory as you will likely need to [update the test specs](#Test-locally) later. 87 | 88 | The grammar file uses [regular expressions](https://en.wikipedia.org/wiki/Regular_expression) to define the characteristics of the language so tools like [Regular Expressions 101](https://regex101.com/) can be especially useful for testing patterns. 89 | 90 | A very basic rule has two elements, a pattern and a scope name, and will assign the scope name to anything that matches the regular expression. Example: 91 | 92 | ```XML 93 | 94 | match 95 | (?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w) 96 | name 97 | keyword.control.powershell 98 | 99 | ``` 100 | 101 | This rule applies the scope `keyword.control.powershell` to anything that matches the capture group inside the pattern. **Note** the use of `<` instead of `<` at the beginning of the rule. Due to XML format it is important that XML characters like `<` and `>` be translated to their [entity format](https://dev.w3.org/html5/html-author/charref) (does not apply to quotation marks.) 102 | 103 | There are a number of guides on how to write a grammar file such as https://macromates.com/manual/en/language_grammars, and https://www.apeth.com/nonblog/stories/textmatebundle.html but you may find it easier to read and try to understand the file itself. 104 | 105 | ## Test locally 106 | 107 | In order to test your changes you will need a JSON version of the grammar file. 108 | 109 | 1. From the command line run `.\build.ps1` without parameters to generate the JSON from the .tmLanguage file in `.\grammars\powershell.tmLanguage.json`. 110 | 111 | You will then need to replace the JSON file your editor is using and reload it. For example, if you're using [Visual Studio Code](https://code.visualstudio.com/): 112 | 113 | 1. Locate your VS Code installation directory and find `.\resources\app\extensions\powershell\syntaxes`. For the system installer version on Windows the path should be `C:\Program Files\Microsoft VS Code\resources\app\extensions\powershell\syntaxes`. 114 | 1. Rename `powershell.tmLanguage.json` in the directory to `powershell.tmLanguage.json_official` or similar. 115 | 1. Copy the JSON file you generated from `.\grammars` in the EditorSyntax folder to the `.\syntaxes` folder above. 116 | 1. Reload VS Code using the `Reload Windows` command from the command palette. 117 | 118 | Once you've loaded your modified version in your editor you will want to make sure you've fixed what you set out to fix and that highlighting still appears to be working in general. In VS Code there is a command in the command palette called `Developer: Inspect TM Scopes` which is useful for making sure scopes have been applied the way you expect. 119 | 120 | ## Run the automated tests 121 | 122 | In order to prevent against regression we've included a number of specs in `.\spec` that specify what scopes are expected and are compared against those actually assigned by the grammar file. Before submitting a pull request you should always run the tests as they will be run against your PR and failures will block merging. 123 | 124 | 1. Currently the tests require you to have [Atom](https://atom.io/) installed on your computer (it's free) as they use Atom's tokenizer. (Atom needs to be in your PATH.) 125 | 1. Run the build.ps1 script with the `-Test` switch: `.\build.ps1 -Test` and you should get an output like this: 126 | ``` 127 | Running specs... 128 | 129 | ................................................................................. 130 | 131 | Finished in 24.42 seconds 132 | 367 tests, 3524 assertions, 0 failures, 0 skipped 133 | ``` 134 | 135 | If installing Atom is not an option or you cannot get it working you can submit a PR with "[WIP]" for Work-In-Progress in the title and our continuous integration tools will run the tests for you. 136 | 137 | If you get any errors that were unexpected make sure to fix them and run the tests again. If your change caused a test to break on purpose or if you need to create tests for something entirely new, continue to the next section. 138 | 139 | ## Create tests and/or modify existing tests 140 | 141 | There are two types of tests included in the `.\spec` directory, Mocha tests in `powershell-spec.coffee`, and specs that use the [Sublime Syntax test format](https://www.sublimetext.com/docs/3/syntax.html#testing) in `.\testfiles\*.ps1`. The Mocha tests exist just for comments as the spec format uses comments in its syntax. Unless you're changing how comments work or adding new ps1 files to `.\testfiles` you should not need to modify the CoffeeScript file. 142 | 143 | Specs in the three `ps1` files under `.\spec\testfiles` use comments below real PowerShell code to tell the tokenizer what scope is expected at a particular column (use a monospaced font when working on specs.) The specs use the same format defined here: [Sublime Syntax test format](https://www.sublimetext.com/docs/3/syntax.html#testing) 144 | 145 | This example spec: 146 | 147 | ```PowerShell 148 | 'This is a string' 149 | # <- punctuation.definition.string.begin.powershell string.quoted.single.powershell 150 | # ^^^^^^^^^^^^^^^ string.quoted.single.powershell 151 | # ^ punctuation.definition.string.end.powershell 152 | ``` 153 | 154 | Is saying the very first character (`# <-` means the first column or what is vertically in line with the comment symbol) should have the scopes `punctuation.definition.string.begin.powershell` and `string.quoted.single.powershell`, that the text in between should have the scope `string.quoted.single.powershell`, and the final character should have the scope `punctuation.definition.string.end.powershell`. As you can see the carats point at the elements on the actual code line and are trailed by the expected scopes. 155 | 156 | Keep in mind that it is not necessary to point to the whole string unless there's an expectation that something it contains might break it: 157 | 158 | ```PowerShell 159 | 'This is a string' 160 | # <- punctuation.definition.string.begin.powershell string.quoted.single.powershell 161 | # ^ string.quoted.single.powershell 162 | # ^ punctuation.definition.string.end.powershell 163 | ``` 164 | 165 | is just as valid. 166 | 167 | **Note:** your can also use `not:scope.name` to make sure something doesn't inherit a scope in a spec. 168 | 169 | Once you've made your changes to the grammar file you will want to modify any specs that broke as a result (as long as it was expected) and add new specs for your changes. Be sure to account for things that should happen and things that shouldn't. Ie, if your change should only scope something when it is inside a string you should have a spec that makes sure that happens and a spec that makes sure it doesn't match outside of a string. 170 | 171 | ## Submit your changes 172 | 173 | When you're ready and all the tests are passing it's time to submit a pull request! 174 | 175 | 1. Commit your changes to your branch if you haven't already: `git commit -am ""` 176 | 1. Push your changes to GitHub: `git push --set-upstream origin ` 177 | 1. Open the official [EditorSyntax](https://github.com/PowerShell/EditorSyntax) page in a browser. 178 | 1. You should see a link for opening a pull request based on your recent push. If not use the [New Pull Request](https://github.com/PowerShell/EditorSyntax/compare?expand=1) button to create one from scratch. 179 | 1. Fill out the title and details and [link to any issues](https://help.github.com/articles/autolinked-references-and-urls/) your PR fixes using wording like "fixes #100". 180 | 1. Submit the pull request and complete the CLA if prompted. 181 | 182 | ## Updating software that uses the grammar 183 | 184 | The PowerShell grammar file is used by multiple editors and tools and in order to see all of the shiny changes being made they need to be updated periodically. 185 | 186 | ### GitHub Linguist 187 | 188 | * Project link: https://github.com/github/linguist 189 | 190 | **Steps** 191 | 192 | *Linguist is updated automatically every time they release.* 193 | 194 | ### Visual Studio Code 195 | 196 | * Project link: https://github.com/Microsoft/vscode/ 197 | 198 | **Steps** 199 | 200 | -Coming Soon- 201 | 202 | ### Atom 203 | 204 | * Project link: https://github.com/atom/atom 205 | 206 | **Steps** 207 | 208 | -Coming Soon- 209 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ### Environment 12 | 13 | - Editor and Version (VS Code, Atom, Sublime): 14 | - Your primary theme: 15 | 16 | ### Issue Description 17 | 18 | 19 | 20 | #### Screenshots 21 | 22 | 23 | 24 | ### Expected Behavior 25 | 26 | 27 | 28 | ### Code Samples 29 | 30 | 34 | 35 | ```PowerShell 36 | 37 | 38 | ``` 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation 2 | 3 | All rights reserved. 4 | 5 | MIT License 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. 24 | -------------------------------------------------------------------------------- /PowerShellSyntax.tmLanguage: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | fileTypes 6 | 7 | ps1 8 | psm1 9 | psd1 10 | 11 | name 12 | PowerShell 13 | patterns 14 | 15 | 16 | begin 17 | <# 18 | beginCaptures 19 | 20 | 0 21 | 22 | name 23 | punctuation.definition.comment.block.begin.powershell 24 | 25 | 26 | end 27 | #> 28 | endCaptures 29 | 30 | 0 31 | 32 | name 33 | punctuation.definition.comment.block.end.powershell 34 | 35 | 36 | name 37 | comment.block.powershell 38 | patterns 39 | 40 | 41 | include 42 | #commentEmbeddedDocs 43 | 44 | 45 | 46 | 47 | match 48 | [2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>> 49 | name 50 | keyword.operator.redirection.powershell 51 | 52 | 53 | include 54 | #commands 55 | 56 | 57 | include 58 | #commentLine 59 | 60 | 61 | include 62 | #variable 63 | 64 | 65 | include 66 | #subexpression 67 | 68 | 69 | include 70 | #function 71 | 72 | 73 | include 74 | #attribute 75 | 76 | 77 | include 78 | #UsingDirective 79 | 80 | 81 | include 82 | #type 83 | 84 | 85 | include 86 | #hashtable 87 | 88 | 89 | include 90 | #doubleQuotedString 91 | 92 | 93 | include 94 | #scriptblock 95 | 96 | 97 | comment 98 | Needed to parse stuff correctly in 'argument mode'. (See about_parsing.) 99 | include 100 | #doubleQuotedStringEscapes 101 | 102 | 103 | begin 104 | ['\x{2018}-\x{201B}] 105 | beginCaptures 106 | 107 | 0 108 | 109 | name 110 | punctuation.definition.string.begin.powershell 111 | 112 | 113 | end 114 | ['\x{2018}-\x{201B}] 115 | applyEndPatternLast 116 | 117 | endCaptures 118 | 119 | 0 120 | 121 | name 122 | punctuation.definition.string.end.powershell 123 | 124 | 125 | name 126 | string.quoted.single.powershell 127 | patterns 128 | 129 | 130 | match 131 | ['\x{2018}-\x{201B}]{2} 132 | name 133 | constant.character.escape.powershell 134 | 135 | 136 | 137 | 138 | begin 139 | (@["\x{201C}-\x{201E}])\s*$ 140 | beginCaptures 141 | 142 | 1 143 | 144 | name 145 | punctuation.definition.string.begin.powershell 146 | 147 | 148 | end 149 | ^["\x{201C}-\x{201E}]@ 150 | endCaptures 151 | 152 | 0 153 | 154 | name 155 | punctuation.definition.string.end.powershell 156 | 157 | 158 | name 159 | string.quoted.double.heredoc.powershell 160 | patterns 161 | 162 | 163 | include 164 | #variableNoProperty 165 | 166 | 167 | include 168 | #doubleQuotedStringEscapes 169 | 170 | 171 | include 172 | #interpolation 173 | 174 | 175 | 176 | 177 | begin 178 | (@['\x{2018}-\x{201B}])\s*$ 179 | beginCaptures 180 | 181 | 1 182 | 183 | name 184 | punctuation.definition.string.begin.powershell 185 | 186 | 187 | end 188 | ^['\x{2018}-\x{201B}]@ 189 | endCaptures 190 | 191 | 0 192 | 193 | name 194 | punctuation.definition.string.end.powershell 195 | 196 | 197 | name 198 | string.quoted.single.heredoc.powershell 199 | 200 | 201 | include 202 | #numericConstant 203 | 204 | 205 | begin 206 | (@)(\() 207 | beginCaptures 208 | 209 | 1 210 | 211 | name 212 | keyword.other.array.begin.powershell 213 | 214 | 2 215 | 216 | name 217 | punctuation.section.group.begin.powershell 218 | 219 | 220 | end 221 | \) 222 | endCaptures 223 | 224 | 0 225 | 226 | name 227 | punctuation.section.group.end.powershell 228 | 229 | 230 | name 231 | meta.group.array-expression.powershell 232 | patterns 233 | 234 | 235 | include 236 | $self 237 | 238 | 239 | 240 | 241 | begin 242 | ((\$))(\() 243 | beginCaptures 244 | 245 | 1 246 | 247 | name 248 | keyword.other.substatement.powershell 249 | 250 | 2 251 | 252 | name 253 | punctuation.definition.subexpression.powershell 254 | 255 | 3 256 | 257 | name 258 | punctuation.section.group.begin.powershell 259 | 260 | 261 | comment 262 | TODO: move to repo; make recursive. 263 | end 264 | \) 265 | endCaptures 266 | 267 | 0 268 | 269 | name 270 | punctuation.section.group.end.powershell 271 | 272 | 273 | name 274 | meta.group.complex.subexpression.powershell 275 | patterns 276 | 277 | 278 | include 279 | $self 280 | 281 | 282 | 283 | 284 | match 285 | (\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b) 286 | name 287 | support.function.powershell 288 | 289 | 290 | match 291 | (?<!\w|-|\.)((?i:begin|break|catch|clean|continue|data|default|define|do|dynamicparam|else|elseif|end|exit|finally|for|from|if|in|inlinescript|parallel|param|process|return|sequence|switch|throw|trap|try|until|var|while)|%|\?)(?!\w) 292 | name 293 | keyword.control.powershell 294 | 295 | 296 | match 297 | (?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w) 298 | name 299 | keyword.control.powershell 300 | 301 | 302 | begin 303 | (?<!\w)(--%)(?!\w) 304 | beginCaptures 305 | 306 | 1 307 | 308 | name 309 | keyword.control.powershell 310 | 311 | 312 | end 313 | $ 314 | patterns 315 | 316 | 317 | match 318 | .+ 319 | name 320 | string.unquoted.powershell 321 | 322 | 323 | comment 324 | This should be moved to the repository at some point. 325 | 326 | 327 | comment 328 | This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix. 329 | match 330 | (?<!\w)((?i:hidden|static))(?!\w) 331 | name 332 | storage.modifier.powershell 333 | 334 | 335 | captures 336 | 337 | 1 338 | 339 | name 340 | storage.type.powershell 341 | 342 | 2 343 | 344 | name 345 | entity.name.function 346 | 347 | 348 | comment 349 | capture should be entity.name.type, but it doesn't provide a good color in the default schema. 350 | match 351 | (?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b 352 | 353 | 354 | match 355 | (?<!\w)-(?i:is(?:not)?|as)\b 356 | name 357 | keyword.operator.comparison.powershell 358 | 359 | 360 | match 361 | (?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L}) 362 | name 363 | keyword.operator.comparison.powershell 364 | 365 | 366 | match 367 | (?<!\w)-(?i:join|split)(?!\p{L})|! 368 | name 369 | keyword.operator.unary.powershell 370 | 371 | 372 | match 373 | (?<!\w)-(?i:and|or|not|xor)(?!\p{L})|! 374 | name 375 | keyword.operator.logical.powershell 376 | 377 | 378 | match 379 | (?<!\w)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L}) 380 | name 381 | keyword.operator.bitwise.powershell 382 | 383 | 384 | match 385 | (?<!\w)-(?i:f)(?!\p{L}) 386 | name 387 | keyword.operator.string-format.powershell 388 | 389 | 390 | match 391 | [+%*/-]?=|[+/*%-] 392 | name 393 | keyword.operator.assignment.powershell 394 | 395 | 396 | match 397 | \|{2}|&{2}|; 398 | name 399 | punctuation.terminator.statement.powershell 400 | 401 | 402 | match 403 | &|(?<!\w)\.(?= )|`|,|\| 404 | name 405 | keyword.operator.other.powershell 406 | 407 | 408 | comment 409 | This is very imprecise, is there a syntax for 'must come after...' 410 | match 411 | (?<!\s|^)\.\.(?=\-?\d|\(|\$) 412 | name 413 | keyword.operator.range.powershell 414 | 415 | 416 | repository 417 | 418 | commentLine 419 | 420 | begin 421 | (?<![`\\-])(#)#* 422 | captures 423 | 424 | 1 425 | 426 | name 427 | punctuation.definition.comment.powershell 428 | 429 | 430 | end 431 | $\n? 432 | name 433 | comment.line.powershell 434 | patterns 435 | 436 | 437 | include 438 | #commentEmbeddedDocs 439 | 440 | 441 | include 442 | #RequiresDirective 443 | 444 | 445 | 446 | attribute 447 | 448 | begin 449 | (\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength|supportswildcards)\b 450 | beginCaptures 451 | 452 | 1 453 | 454 | name 455 | punctuation.section.bracket.begin.powershell 456 | 457 | 2 458 | 459 | name 460 | support.function.attribute.powershell 461 | 462 | 463 | end 464 | (\]) 465 | endCaptures 466 | 467 | 1 468 | 469 | name 470 | punctuation.section.bracket.end.powershell 471 | 472 | 473 | name 474 | meta.attribute.powershell 475 | patterns 476 | 477 | 478 | begin 479 | \( 480 | beginCaptures 481 | 482 | 0 483 | 484 | name 485 | punctuation.section.group.begin.powershell 486 | 487 | 488 | end 489 | \) 490 | endCaptures 491 | 492 | 0 493 | 494 | name 495 | punctuation.section.group.end.powershell 496 | 497 | 498 | patterns 499 | 500 | 501 | include 502 | $self 503 | 504 | 505 | match 506 | (?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=)? 507 | captures 508 | 509 | 1 510 | 511 | name 512 | variable.parameter.attribute.powershell 513 | 514 | 2 515 | 516 | name 517 | keyword.operator.assignment.powershell 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | commands 526 | 527 | patterns 528 | 529 | 530 | comment 531 | Verb-Noun pattern: 532 | match 533 | (?:(\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 534 | name 535 | support.function.powershell 536 | 537 | 538 | comment 539 | Builtin cmdlets with reserved verbs 540 | match 541 | (?<!\w)(?i:foreach-object)(?!\w) 542 | name 543 | support.function.powershell 544 | 545 | 546 | comment 547 | Builtin cmdlets with reserved verbs 548 | match 549 | (?<!\w)(?i:where-object)(?!\w) 550 | name 551 | support.function.powershell 552 | 553 | 554 | comment 555 | Builtin cmdlets with reserved verbs 556 | match 557 | (?<!\w)(?i:sort-object)(?!\w) 558 | name 559 | support.function.powershell 560 | 561 | 562 | comment 563 | Builtin cmdlets with reserved verbs 564 | match 565 | (?<!\w)(?i:tee-object)(?!\w) 566 | name 567 | support.function.powershell 568 | 569 | 570 | 571 | commentEmbeddedDocs 572 | 573 | patterns 574 | 575 | 576 | captures 577 | 578 | 1 579 | 580 | name 581 | constant.string.documentation.powershell 582 | 583 | 2 584 | 585 | name 586 | keyword.operator.documentation.powershell 587 | 588 | 589 | comment 590 | these embedded doc keywords do not support arguments, must be the only thing on the line 591 | match 592 | (?:^|\G)(?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|ROLE|SYNOPSIS))\s*$ 593 | name 594 | comment.documentation.embedded.powershell 595 | 596 | 597 | captures 598 | 599 | 1 600 | 601 | name 602 | constant.string.documentation.powershell 603 | 604 | 2 605 | 606 | name 607 | keyword.operator.documentation.powershell 608 | 609 | 3 610 | 611 | name 612 | keyword.operator.documentation.powershell 613 | 614 | 615 | comment 616 | these embedded doc keywords require arguments though the type required may be inconsistent, they may not all be able to use the same argument match 617 | match 618 | (?:^|\G)(?i:\s*(\.)(EXTERNALHELP|FORWARDHELP(?:CATEGORY|TARGETNAME)|PARAMETER|REMOTEHELPRUNSPACE))\s+(.+?)\s*$ 619 | name 620 | comment.documentation.embedded.powershell 621 | 622 | 623 | 624 | doubleQuotedStringEscapes 625 | 626 | patterns 627 | 628 | 629 | match 630 | `[`0abefnrtv'"\x{2018}-\x{201E}$] 631 | name 632 | constant.character.escape.powershell 633 | 634 | 635 | include 636 | #unicodeEscape 637 | 638 | 639 | 640 | unicodeEscape 641 | 642 | comment 643 | `u{xxxx} added in PowerShell 6.0 644 | patterns 645 | 646 | 647 | match 648 | `u\{(?:(?:10)?([0-9a-fA-F]){1,4}|0?\g<1>{1,5})} 649 | name 650 | constant.character.escape.powershell 651 | 652 | 653 | match 654 | `u(?:\{[0-9a-fA-F]{,6}.)? 655 | name 656 | invalid.character.escape.powershell 657 | 658 | 659 | 660 | function 661 | 662 | begin 663 | ^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+) 664 | beginCaptures 665 | 666 | 0 667 | 668 | name 669 | meta.function.powershell 670 | 671 | 1 672 | 673 | name 674 | storage.type.powershell 675 | 676 | 2 677 | 678 | name 679 | storage.modifier.scope.powershell 680 | 681 | 3 682 | 683 | name 684 | entity.name.function.powershell 685 | 686 | 687 | end 688 | (?=\{|\() 689 | patterns 690 | 691 | 692 | include 693 | #commentLine 694 | 695 | 696 | 697 | subexpression 698 | 699 | begin 700 | \( 701 | beginCaptures 702 | 703 | 0 704 | 705 | name 706 | punctuation.section.group.begin.powershell 707 | 708 | 709 | end 710 | \) 711 | endCaptures 712 | 713 | 0 714 | 715 | name 716 | punctuation.section.group.end.powershell 717 | 718 | 719 | name 720 | meta.group.simple.subexpression.powershell 721 | patterns 722 | 723 | 724 | include 725 | $self 726 | 727 | 728 | 729 | interpolation 730 | 731 | begin 732 | (((\$)))((\()) 733 | beginCaptures 734 | 735 | 1 736 | 737 | name 738 | keyword.other.substatement.powershell 739 | 740 | 2 741 | 742 | name 743 | punctuation.definition.substatement.powershell 744 | 745 | 3 746 | 747 | name 748 | punctuation.section.embedded.substatement.begin.powershell 749 | 750 | 4 751 | 752 | name 753 | punctuation.section.group.begin.powershell 754 | 755 | 5 756 | 757 | name 758 | punctuation.section.embedded.substatement.begin.powershell 759 | 760 | 761 | contentName 762 | interpolated.complex.source.powershell 763 | end 764 | (\)) 765 | endCaptures 766 | 767 | 0 768 | 769 | name 770 | punctuation.section.group.end.powershell 771 | 772 | 1 773 | 774 | name 775 | punctuation.section.embedded.substatement.end.powershell 776 | 777 | 778 | name 779 | meta.embedded.substatement.powershell 780 | patterns 781 | 782 | 783 | include 784 | $self 785 | 786 | 787 | 788 | numericConstant 789 | 790 | patterns 791 | 792 | 793 | captures 794 | 795 | 1 796 | 797 | name 798 | constant.numeric.hex.powershell 799 | 800 | 2 801 | 802 | name 803 | keyword.other.powershell 804 | 805 | 806 | match 807 | (?<!\w)([-+]?0(?:x|X)[0-9a-fA-F_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b 808 | 809 | 810 | captures 811 | 812 | 1 813 | 814 | name 815 | constant.numeric.integer.powershell 816 | 817 | 2 818 | 819 | name 820 | keyword.other.powershell 821 | 822 | 823 | match 824 | (?<!\w)([-+]?(?:[0-9_]+)?\.[0-9_]+(?:(?:e|E)[0-9]+)?(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b 825 | 826 | 827 | captures 828 | 829 | 1 830 | 831 | name 832 | constant.numeric.octal.powershell 833 | 834 | 2 835 | 836 | name 837 | keyword.other.powershell 838 | 839 | 840 | match 841 | (?<!\w)([-+]?0(?:b|B)[01_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b 842 | 843 | 844 | captures 845 | 846 | 1 847 | 848 | name 849 | constant.numeric.integer.powershell 850 | 851 | 2 852 | 853 | name 854 | keyword.other.powershell 855 | 856 | 857 | match 858 | (?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b 859 | 860 | 861 | captures 862 | 863 | 1 864 | 865 | name 866 | constant.numeric.integer.powershell 867 | 868 | 2 869 | 870 | name 871 | keyword.other.powershell 872 | 873 | 874 | match 875 | (?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b 876 | 877 | 878 | captures 879 | 880 | 1 881 | 882 | name 883 | constant.numeric.integer.powershell 884 | 885 | 2 886 | 887 | name 888 | keyword.other.powershell 889 | 890 | 891 | match 892 | (?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b 893 | 894 | 895 | captures 896 | 897 | 1 898 | 899 | name 900 | constant.numeric.integer.powershell 901 | 902 | 2 903 | 904 | name 905 | keyword.other.powershell 906 | 907 | 908 | match 909 | (?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b 910 | 911 | 912 | 913 | scriptblock 914 | 915 | begin 916 | \{ 917 | beginCaptures 918 | 919 | 0 920 | 921 | name 922 | punctuation.section.braces.begin.powershell 923 | 924 | 925 | end 926 | \} 927 | endCaptures 928 | 929 | 0 930 | 931 | name 932 | punctuation.section.braces.end.powershell 933 | 934 | 935 | name 936 | meta.scriptblock.powershell 937 | patterns 938 | 939 | 940 | include 941 | $self 942 | 943 | 944 | 945 | type 946 | 947 | begin 948 | \[ 949 | beginCaptures 950 | 951 | 0 952 | 953 | name 954 | punctuation.section.bracket.begin.powershell 955 | 956 | 957 | end 958 | \] 959 | endCaptures 960 | 961 | 0 962 | 963 | name 964 | punctuation.section.bracket.end.powershell 965 | 966 | 967 | patterns 968 | 969 | 970 | match 971 | (?!\d+|\.)(?:\p{L}|\p{N}|\.)+ 972 | name 973 | storage.type.powershell 974 | 975 | 976 | include 977 | $self 978 | 979 | 980 | 981 | variable 982 | 983 | patterns 984 | 985 | 986 | captures 987 | 988 | 0 989 | 990 | name 991 | constant.language.powershell 992 | 993 | 1 994 | 995 | name 996 | punctuation.definition.variable.powershell 997 | 998 | 999 | comment 1000 | These are special constants. 1001 | match 1002 | (\$)(?i:(False|Null|True))\b 1003 | 1004 | 1005 | captures 1006 | 1007 | 0 1008 | 1009 | name 1010 | support.constant.variable.powershell 1011 | 1012 | 1 1013 | 1014 | name 1015 | punctuation.definition.variable.powershell 1016 | 1017 | 3 1018 | 1019 | name 1020 | variable.other.member.powershell 1021 | 1022 | 1023 | comment 1024 | These are the other built-in constants. 1025 | match 1026 | (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b 1027 | 1028 | 1029 | captures 1030 | 1031 | 0 1032 | 1033 | name 1034 | support.variable.automatic.powershell 1035 | 1036 | 1 1037 | 1038 | name 1039 | punctuation.definition.variable.powershell 1040 | 1041 | 3 1042 | 1043 | name 1044 | variable.other.member.powershell 1045 | 1046 | 1047 | comment 1048 | 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. 1049 | match 1050 | (\$)((?:[$^?])|(?i:_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b)((?:\.(?:\p{L}|\d|_)+)*\b)? 1051 | 1052 | 1053 | captures 1054 | 1055 | 0 1056 | 1057 | name 1058 | variable.language.powershell 1059 | 1060 | 1 1061 | 1062 | name 1063 | punctuation.definition.variable.powershell 1064 | 1065 | 3 1066 | 1067 | name 1068 | variable.other.member.powershell 1069 | 1070 | 1071 | comment 1072 | Style preference variables as language variables so that they stand out. 1073 | match 1074 | (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|InformationPreference|LogCommandHealthEvent|LogCommandLifecycleEvent|LogEngineHealthEvent|LogEngineLifecycleEvent|LogProviderHealthEvent|LogProviderLifecycleEvent|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|PSCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoLoadingPreference|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|ProgressPreference|VerbosePreference|WarningPreference|WhatIfPreference))((?:\.(?:\p{L}|\d|_)+)*\b)?\b 1075 | 1076 | 1077 | captures 1078 | 1079 | 0 1080 | 1081 | name 1082 | variable.other.readwrite.powershell 1083 | 1084 | 1 1085 | 1086 | name 1087 | punctuation.definition.variable.powershell 1088 | 1089 | 2 1090 | 1091 | name 1092 | storage.modifier.scope.powershell 1093 | 1094 | 4 1095 | 1096 | name 1097 | variable.other.member.powershell 1098 | 1099 | 1100 | match 1101 | (?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? 1102 | 1103 | 1104 | captures 1105 | 1106 | 0 1107 | 1108 | name 1109 | variable.other.readwrite.powershell 1110 | 1111 | 1 1112 | 1113 | name 1114 | punctuation.definition.variable.powershell 1115 | 1116 | 2 1117 | 1118 | name 1119 | punctuation.section.braces.begin.powershell 1120 | 1121 | 3 1122 | 1123 | name 1124 | storage.modifier.scope.powershell 1125 | 1126 | 5 1127 | 1128 | name 1129 | punctuation.section.braces.end.powershell 1130 | 1131 | 6 1132 | 1133 | name 1134 | variable.other.member.powershell 1135 | 1136 | 1137 | match 1138 | (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? 1139 | 1140 | 1141 | captures 1142 | 1143 | 0 1144 | 1145 | name 1146 | variable.other.readwrite.powershell 1147 | 1148 | 1 1149 | 1150 | name 1151 | punctuation.definition.variable.powershell 1152 | 1153 | 2 1154 | 1155 | name 1156 | support.variable.drive.powershell 1157 | 1158 | 4 1159 | 1160 | name 1161 | variable.other.member.powershell 1162 | 1163 | 1164 | match 1165 | (?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)? 1166 | 1167 | 1168 | captures 1169 | 1170 | 0 1171 | 1172 | name 1173 | variable.other.readwrite.powershell 1174 | 1175 | 1 1176 | 1177 | name 1178 | punctuation.definition.variable.powershell 1179 | 1180 | 2 1181 | 1182 | name 1183 | punctuation.section.braces.begin.powershell 1184 | 1185 | 3 1186 | 1187 | name 1188 | support.variable.drive.powershell 1189 | 1190 | 5 1191 | 1192 | name 1193 | punctuation.section.braces.end.powershell 1194 | 1195 | 6 1196 | 1197 | name 1198 | variable.other.member.powershell 1199 | 1200 | 1201 | match 1202 | (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)? 1203 | 1204 | 1205 | 1206 | UsingDirective 1207 | 1208 | match 1209 | (?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+)) 1210 | captures 1211 | 1212 | 1 1213 | 1214 | name 1215 | keyword.control.using.powershell 1216 | 1217 | 2 1218 | 1219 | name 1220 | keyword.other.powershell 1221 | 1222 | 3 1223 | 1224 | name 1225 | variable.parameter.powershell 1226 | 1227 | 1228 | 1229 | RequiresDirective 1230 | 1231 | begin 1232 | (?<=#)(?i:(requires))\s 1233 | beginCaptures 1234 | 1235 | 0 1236 | 1237 | name 1238 | keyword.control.requires.powershell 1239 | 1240 | 1241 | end 1242 | $ 1243 | name 1244 | meta.requires.powershell 1245 | patterns 1246 | 1247 | 1248 | match 1249 | \-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version|Assembly|PSEdition) 1250 | name 1251 | keyword.other.powershell 1252 | 1253 | 1254 | match 1255 | (?<!-)\b\p{L}+|\d+(?:\.\d+)* 1256 | name 1257 | variable.parameter.powershell 1258 | 1259 | 1260 | include 1261 | #hashtable 1262 | 1263 | 1264 | 1265 | variableNoProperty 1266 | 1267 | patterns 1268 | 1269 | 1270 | captures 1271 | 1272 | 0 1273 | 1274 | name 1275 | constant.language.powershell 1276 | 1277 | 1 1278 | 1279 | name 1280 | punctuation.definition.variable.powershell 1281 | 1282 | 1283 | comment 1284 | These are special constants. 1285 | match 1286 | (\$)(?i:(False|Null|True))\b 1287 | 1288 | 1289 | captures 1290 | 1291 | 0 1292 | 1293 | name 1294 | support.constant.variable.powershell 1295 | 1296 | 1 1297 | 1298 | name 1299 | punctuation.definition.variable.powershell 1300 | 1301 | 3 1302 | 1303 | name 1304 | variable.other.member.powershell 1305 | 1306 | 1307 | comment 1308 | These are the other built-in constants. 1309 | match 1310 | (\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b 1311 | 1312 | 1313 | captures 1314 | 1315 | 0 1316 | 1317 | name 1318 | support.variable.automatic.powershell 1319 | 1320 | 1 1321 | 1322 | name 1323 | punctuation.definition.variable.powershell 1324 | 1325 | 3 1326 | 1327 | name 1328 | variable.other.member.powershell 1329 | 1330 | 1331 | comment 1332 | Automatic variables are not constants, but they are read-only... 1333 | match 1334 | (\$)((?:[$^?])|(?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) 1335 | 1336 | 1337 | captures 1338 | 1339 | 0 1340 | 1341 | name 1342 | variable.language.powershell 1343 | 1344 | 1 1345 | 1346 | name 1347 | punctuation.definition.variable.powershell 1348 | 1349 | 3 1350 | 1351 | name 1352 | variable.other.member.powershell 1353 | 1354 | 1355 | comment 1356 | Style preference variables as language variables so that they stand out. 1357 | match 1358 | (\$)(?i:(ConfirmPreference|DebugPreference|ErrorActionPreference|ErrorView|FormatEnumerationLimit|InformationPreference|LogCommandHealthEvent|LogCommandLifecycleEvent|LogEngineHealthEvent|LogEngineLifecycleEvent|LogProviderHealthEvent|LogProviderLifecycleEvent|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount|MaximumHistoryCount|MaximumVariableCount|OFS|OutputEncoding|PSCulture|PSDebugContext|PSDefaultParameterValues|PSEmailServer|PSItem|PSModuleAutoLoadingPreference|PSModuleAutoloadingPreference|PSSenderInfo|PSSessionApplicationName|PSSessionConfigurationName|PSSessionOption|ProgressPreference|VerbosePreference|WarningPreference|WhatIfPreference))\b 1359 | 1360 | 1361 | captures 1362 | 1363 | 0 1364 | 1365 | name 1366 | variable.other.readwrite.powershell 1367 | 1368 | 1 1369 | 1370 | name 1371 | punctuation.definition.variable.powershell 1372 | 1373 | 2 1374 | 1375 | name 1376 | storage.modifier.scope.powershell 1377 | 1378 | 4 1379 | 1380 | name 1381 | variable.other.member.powershell 1382 | 1383 | 1384 | match 1385 | (?i:(\$)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+)) 1386 | 1387 | 1388 | captures 1389 | 1390 | 0 1391 | 1392 | name 1393 | variable.other.readwrite.powershell 1394 | 1395 | 1 1396 | 1397 | name 1398 | punctuation.definition.variable.powershell 1399 | 1400 | 2 1401 | 1402 | name 1403 | storage.modifier.scope.powershell 1404 | 1405 | 4 1406 | 1407 | name 1408 | keyword.other.powershell 1409 | 1410 | 5 1411 | 1412 | name 1413 | variable.other.member.powershell 1414 | 1415 | 1416 | match 1417 | (?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\})) 1418 | 1419 | 1420 | captures 1421 | 1422 | 0 1423 | 1424 | name 1425 | variable.other.readwrite.powershell 1426 | 1427 | 1 1428 | 1429 | name 1430 | punctuation.definition.variable.powershell 1431 | 1432 | 2 1433 | 1434 | name 1435 | support.variable.drive.powershell 1436 | 1437 | 4 1438 | 1439 | name 1440 | variable.other.member.powershell 1441 | 1442 | 1443 | match 1444 | (?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+)) 1445 | 1446 | 1447 | captures 1448 | 1449 | 0 1450 | 1451 | name 1452 | variable.other.readwrite.powershell 1453 | 1454 | 1 1455 | 1456 | name 1457 | punctuation.definition.variable.powershell 1458 | 1459 | 2 1460 | 1461 | name 1462 | punctuation.section.braces.begin 1463 | 1464 | 3 1465 | 1466 | name 1467 | support.variable.drive.powershell 1468 | 1469 | 5 1470 | 1471 | name 1472 | punctuation.section.braces.end 1473 | 1474 | 1475 | match 1476 | (?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\})) 1477 | 1478 | 1479 | 1480 | hashtable 1481 | 1482 | begin 1483 | (@)(\{) 1484 | beginCaptures 1485 | 1486 | 1 1487 | 1488 | name 1489 | keyword.other.hashtable.begin.powershell 1490 | 1491 | 2 1492 | 1493 | name 1494 | punctuation.section.braces.begin.powershell 1495 | 1496 | 1497 | end 1498 | (\}) 1499 | endCaptures 1500 | 1501 | 1 1502 | 1503 | name 1504 | punctuation.section.braces.end.powershell 1505 | 1506 | 1507 | name 1508 | meta.hashtable.powershell 1509 | patterns 1510 | 1511 | 1512 | captures 1513 | 1514 | 1 1515 | 1516 | name 1517 | punctuation.definition.string.begin.powershell 1518 | 1519 | 2 1520 | 1521 | name 1522 | variable.other.readwrite.powershell 1523 | 1524 | 3 1525 | 1526 | name 1527 | punctuation.definition.string.end.powershell 1528 | 1529 | 4 1530 | 1531 | name 1532 | keyword.operator.assignment.powershell 1533 | 1534 | 1535 | match 1536 | \b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)? 1537 | name 1538 | meta.hashtable.assignment.powershell 1539 | 1540 | 1541 | include 1542 | #scriptblock 1543 | 1544 | 1545 | include 1546 | $self 1547 | 1548 | 1549 | 1550 | doubleQuotedString 1551 | 1552 | begin 1553 | ["\x{201C}-\x{201E}] 1554 | beginCaptures 1555 | 1556 | 0 1557 | 1558 | name 1559 | punctuation.definition.string.begin.powershell 1560 | 1561 | 1562 | end 1563 | ["\x{201C}-\x{201E}] 1564 | applyEndPatternLast 1565 | 1566 | endCaptures 1567 | 1568 | 0 1569 | 1570 | name 1571 | punctuation.definition.string.end.powershell 1572 | 1573 | 1574 | name 1575 | string.quoted.double.powershell 1576 | patterns 1577 | 1578 | 1579 | match 1580 | (?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b 1581 | 1582 | 1583 | include 1584 | #variableNoProperty 1585 | 1586 | 1587 | include 1588 | #doubleQuotedStringEscapes 1589 | 1590 | 1591 | match 1592 | ["\x{201C}-\x{201E}]{2} 1593 | name 1594 | constant.character.escape.powershell 1595 | 1596 | 1597 | include 1598 | #interpolation 1599 | 1600 | 1601 | match 1602 | `\s*$ 1603 | name 1604 | keyword.other.powershell 1605 | 1606 | 1607 | 1608 | 1609 | scopeName 1610 | source.powershell 1611 | uuid 1612 | f8f5ffb0-503e-11df-9879-0800200c9a66 1613 | 1614 | 1615 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PowerShell Syntax Definition for Editors 2 | 3 | This project establishes the central development and maintenance of syntax definition 4 | files for the PowerShell language used by editors that leverage the XML version of the 5 | [TextMate language grammar format](http://manual.macromates.com/en/language_grammars). 6 | 7 | Currently this syntax definition is used in the following editors and extensions: 8 | 9 | - [Visual Studio Code](https://github.com/Microsoft/vscode) by Microsoft 10 | - [PowerShell Package for Sublime Text](https://github.com/SublimeText/PowerShell) by [Guillermo López-Anglada](https://github.com/guillermooo) 11 | - [language-powershell for Atom](https://github.com/jugglingnutcase/language-powershell) by [James Sconfitto](https://github.com/jugglingnutcase/) 12 | 13 | In the future we may find a more common syntax that allows us to generate syntax 14 | definitions for editors that don't leverage the TextMate format. 15 | 16 | ## Status 17 | 18 | We are starting with the current state of the TextMate grammar that is being used in 19 | both VS Code and Sublime Text. There are a number of existing issues with the grammar 20 | that we need to track down and fix. Please see [issue #1](https://github.com/PowerShell/EditorSyntax/issues/1) 21 | for more details. 22 | 23 | ### Prerequisites 24 | 25 | - Node.JS, >= 8.9.1 26 | - Atom text editor (tests) 27 | 28 | ### Build (build.ps1) 29 | 30 | 1. Run `build.ps1` to generate the grammar. 31 | 32 | ``` 33 | PS> .\build.ps1 34 | ``` 35 | 36 | 2. The .json file will be generated in `./grammars/` at the root of the project. 37 | 38 | ### Test (build.ps1) 39 | 40 | > Requires the Atom text editor be installed. 41 | 42 | 1. Run `.\build.ps1` with `-Test`. Which will build the grammar file and run all of the specs. 43 | 44 | ``` 45 | PS> .\build.ps1 -Test 46 | ``` 47 | 48 | ### Build (npm) 49 | 50 | 1. Use `npm` to install dependencies: 51 | 52 | ``` 53 | npm install 54 | ``` 55 | 56 | 2. Run the `build-grammar` script to generate the json file. 57 | 58 | ``` 59 | npm run build-grammar 60 | ``` 61 | 62 | 3. The .json file will be generated in `./grammars/` at the root of the project. 63 | 64 | ### Test (Atom cli) 65 | 66 | 1. Build the grammar file using the above steps. 67 | 68 | 3. Use the Atom cli command for your os (atom.cmd or atom.sh) to run the tests from the root of the EditorSystax project folder. 69 | 70 | ``` 71 | atom --test spec 72 | ``` 73 | 74 | ## Contributing 75 | 76 | We would love to have community contributions to this project to make PowerShell syntax 77 | highlighting great in as many editors as we can. Please feel free to file issues or 78 | send pull requests if you'd like to contribute. 79 | 80 | ## Maintainers 81 | 82 | - [Andy Jordan](https://github.com/andyleejordan) 83 | - [Nick James](https://github.com/omniomi) 84 | 85 | ## License 86 | 87 | This extension is [licensed under the MIT License](LICENSE). Please see the 88 | [third-party notices](Third%20Party%20Notices.txt) file for details on the original 89 | source of the TextMate definition that we use. 90 | 91 | ## Code of Conduct 92 | 93 | Please see our [Code of Conduct](.github/CODE_OF_CONDUCT.md) before participating in this project. 94 | 95 | ## Security Policy 96 | 97 | For any security issues, please see our [Security Policy](.github/SECURITY.md). 98 | -------------------------------------------------------------------------------- /Third Party Notices.txt: -------------------------------------------------------------------------------- 1 | Third Party Notices for PowerShell Editor Syntax 2 | 3 | This Microsoft Open Source project incorporates material from the project(s) listed below (“Third Party Code”). Microsoft is not the original author of the Third Party Code. Microsoft reserves all other rights not expressly granted, whether by implication, estoppel or otherwise. 4 | 5 | Copyright (c) 2011 Guillermo López-Anglada 6 | 7 | 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: 8 | 9 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 | 13 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | image: Visual Studio 2017 3 | skip_tags: true 4 | 5 | branches: 6 | only: 7 | - master 8 | - development 9 | - appveyor 10 | 11 | pull_requests: 12 | do_not_increment_build_number: true 13 | 14 | skip_commits: 15 | message: /skip\-build/ 16 | files: 17 | - .vscode/ 18 | - README.md 19 | - .gitattributes 20 | - .gitignore 21 | 22 | install: 23 | - ps: . .\tools\banners.ps1 24 | - ps: . .\tools\build-helpers.ps1 25 | - ps: SyntaxBanner 26 | - ps: Install-Product node '8.9.1' 27 | - ps: Set-Location $env:APPVEYOR_BUILD_FOLDER 28 | - ps: npm install 29 | - ps: DownloadAtom 30 | 31 | build_script: 32 | - ps: BuildBanner 33 | - ps: npm run build-grammar 34 | 35 | test_script: 36 | - ps: TestBanner 37 | - ps: Set-Location $env:APPVEYOR_BUILD_FOLDER 38 | - ps: $script:ATOM_EXE_PATH = Join-Path $pwd 'Atom\Atom.exe' 39 | - ps: RunSpecs 40 | 41 | on_finish: 42 | - ps: EndBanner 43 | - ps: Push-AppveyorArtifact (Join-Path $env:APPVEYOR_BUILD_FOLDER '\grammars\powershell.tmLanguage.json') 44 | -------------------------------------------------------------------------------- /build.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .Synopsis 3 | Convert the grammar file to json and/or run tests. 4 | 5 | .DESCRIPTION 6 | Build: Converts the .tmLanguage file to .json for use in VSCode or Atom. 7 | 8 | Test: Uses Atom and atom-grammar-test to run tests against specs and sample files to guard against regression. 9 | 10 | .EXAMPLE 11 | PS C:\EditorSyntax> .\build.ps1 12 | [Starting] Converting ../PowerShellSyntax.tmLanguage to json. 13 | ... Reading source file. 14 | ... Parsing content. 15 | ... Building contents. 16 | ... Creating directory: ./grammars 17 | [Finished] File written to: ../grammars/powershell.tmLanguage.json 18 | 19 | .EXAMPLE 20 | PS C:\EditorSyntax> .\build.ps1 Test 21 | Running specs... 22 | 23 | ..... 24 | 25 | Finished in 0.281 seconds 26 | 2 tests, 5 assertions, 0 failures, 0 skipped 27 | #> 28 | param( 29 | [switch] 30 | $Test 31 | ) 32 | 33 | # Load Helpers 34 | . .\tools\build-helpers.ps1 35 | . .\tools\banners.ps1 36 | 37 | SyntaxBanner 38 | 39 | if (-not (npm -v)) { 40 | throw 'Requires Node.js - Could not find npm.' 41 | } 42 | 43 | npm install 44 | 45 | # helper tasks 46 | function RunBuild() { 47 | BuildBanner 48 | try { 49 | Write-Host "Building grammar file(s)..." 50 | npm run build-grammar 51 | } 52 | catch { 53 | $PSCmdlet.ThrowTerminatingError($PSItem) 54 | } 55 | } 56 | 57 | function RunTests() { 58 | $script:ATOM_EXE_PATH = (Get-Command atom).Path 59 | if (-not $script:ATOM_EXE_PATH) { 60 | throw "Atom not found. Install it from https://atom.io/" 61 | } 62 | } 63 | 64 | RunBuild 65 | 66 | if ($Test) { 67 | RunTests 68 | TestBanner 69 | RunSpecs 70 | } 71 | 72 | EndBanner 73 | -------------------------------------------------------------------------------- /examples/TheBigTestFile.ps1: -------------------------------------------------------------------------------- 1 | using namespace System.Management.Automation 2 | #Requires -PSSnapin DiskSnapin -Version 1.2 3 | #Requires -PSSnapin DiskSnapin 4 | #Requires -Version 3 5 | #Requires -Version 3.0 6 | #Requires -Version 3 -RunAsAdministrator 7 | #Requires -RunAsAdministrator 8 | #Requires -Modules PSWorkflow 9 | #Requires -Modules PSWorkflow -ThisIsInvalid 10 | #Requires -Modules PSWorkflow, ActiveDirectory 11 | #Requires -Modules PSWorkflow,ActiveDirectory 12 | #Requires -ShellId MyLocalShell 13 | #Requires -PSEdition Core 14 | #Requires -Assembly System 15 | #Requires -Modules PSWorkflow @{ 16 | ModuleName="PSScheduledJob" 17 | ModuleVersion="1.0.0.0" 18 | } 19 | 20 | throw "Do not run this file!" 21 | 22 | <# 23 | 24 | The big PowerShell syntax highlighting test file 25 | 26 | #> 27 | 28 | # Stop parsing 29 | & tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment 30 | 31 | # Automatic variables 32 | $_ 33 | $args 34 | $error 35 | $home 36 | $foreach 37 | 38 | # Normal variables 39 | $variable 40 | $script:variable 41 | $ENV:ComputerName 42 | # This is not allowed 43 | $ENV: 44 | ${variable} 45 | ${script:variable} 46 | ${#variableName} 47 | ${'variableName'} 48 | ${"$variableName"} 49 | ${variable name} 50 | ${script:this`{name`}is"valid"} 51 | 52 | # Variable properties should be highlighted 53 | $variable.Name 54 | ($variable).Name 55 | 56 | # In double-quoted strings, only the variable should be highlighted, not the property 57 | "This is my $variable.Name!" 58 | 59 | # When used in a subexpression, both should be highlighted 60 | "This is my $($variable.Name)!" 61 | 62 | # $ENV:ComputerName should be highlighted 63 | "This is the name of my computer: $ENV:ComputerName" 64 | 65 | # Here as well 66 | "This is the name of my computer: ${ENV:ComputerName}" 67 | 68 | # This is still not allowed though 69 | "This is the name of my computer $ENV: " 70 | 71 | # This is an illegal variable name 72 | $variable-name 73 | 74 | # Hashtable 75 | $properties = @{ 76 | Name = 'Name' 77 | Something = $else 78 | Number = 16 79 | from = 'hello world' 80 | hash = @{ 81 | hello = 'world' 82 | } 83 | } 84 | 85 | # Spatting 86 | Invoke-Something @properties 87 | 88 | # ScriptBlock 89 | {Invoke-Something @properties} 90 | { 91 | Invoke-Something @properties 92 | } 93 | $sb = { 94 | Invoke-Something @properties 95 | } 96 | 97 | # Arrays 98 | $a1 = @(1,2,3,4) 99 | $a2 = ('one','two','three','four') 100 | $a3 = $one, $two, $three, $four 101 | $a1[0] 102 | $a2[-1] 103 | $a3[1..2] 104 | @(@($a)) 105 | @(($i = 10); (++$j)) 106 | @($i = 10) 107 | $i[($y - 1) + $x] 108 | 109 | # Single quoted strings 110 | 'This is a single quoted string.' 111 | '$This is a single ''quoted'' string.' 112 | 'This is a 113 | single quoted string.' 114 | 'This #also' 115 | '$(Invoke-Something)' 116 | 'This "string" is nice.' 117 | 118 | # Single quoted here-string 119 | @' 120 | $This is a ''single quoted'' 121 | $('Here-String') 122 | Isn't it "nice"?? 123 | '@ 124 | 125 | # Double quoted strings 126 | "This is a double quoted string." 127 | "$This is a double ""quoted"" string." 128 | "This is a 129 | double quoted string." 130 | "This #also" 131 | "$(Invoke-Something)" 132 | "This 'string' is nice." 133 | 134 | # Double quoted here-string 135 | @" 136 | $This is a 'double quoted' 137 | $('Here-String') 138 | Isn't it "nice"?? 139 | "@ 140 | 141 | # Numeric constants 142 | -3 143 | .5 144 | +.5 145 | 1. 146 | 1.d 147 | 1.lGB 148 | 1.e+12d 149 | 1e+12d 150 | 1.5 151 | -1.5 152 | -3 + -2 153 | -3+-2 154 | 3++2 155 | +2 156 | -3+- 157 | 10/-10 158 | 10/-10D 159 | -10.002L 160 | $x..5.40D 161 | -500..-495 162 | $true..3 163 | -2..$null 164 | -3..3 165 | 1 .. 3kb 166 | 1..3 167 | 6,10,-3 168 | 0x476 169 | +0x20 170 | -0x20 171 | 172 | # Types 173 | [string] 174 | [string[]] 175 | [int32] 176 | [System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] 177 | [System.Array+SZArrayEnumerator] 178 | [int]::MinValue 179 | [System.DateTime]::Parse('2016/09/21') 180 | 181 | # Commands (functions) 182 | Invoke-Something -foobar 183 | Invoke-Something -foobar value 184 | Invoke-Something -foobar:$true 185 | Invoke-Something -foobar: $true 186 | Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose 187 | Invoke-Something (1..20 | Invoke-Something) -p2 'value' 188 | Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch 189 | Invoke-Something -p1 { 190 | Invoke-Something -foobar:$true 191 | } | Invoke-Something 192 | Invoke-Something -p1 value ` 193 | -p2 14.4 ` 194 | -p3 $value | Invoke-Something -verbose 195 | 196 | # Commands (Built-in variables) 197 | ls *.ps1 -recurse 198 | 199 | # Commands (executable files) 200 | . .\scripts\myscript.ps1 -parameter 'value' 201 | & tool.exe 202 | something.cmd 203 | øyvind.com # this should also highlight - TODO! 204 | 205 | # But this should not highlight anything 206 | file.1 207 | This.txt 208 | Function.txt 209 | Where.txt 210 | ForEach-Object.txt 211 | 212 | # switch 213 | switch ("fourteen") {} 214 | switch -CaseSensitive ("fourteen") {} 215 | switch -Illegal ("fourteen") {} # Using illegal switch parameter 216 | switch -Regex ("fourteen") {} 217 | switch -Wildcard ($a) {} 218 | switch -regex -file .\somefile.txt {} 219 | switch (3) {} 220 | switch (4, 2) {} 221 | 222 | switch -Regex -File $filePath { 223 | '.' {} 224 | default {} 225 | } 226 | 227 | switch -Wildcard -CaseSensitive ($something) { 228 | '.' {} 229 | default {} 230 | } 231 | 232 | switch ('this') { 233 | 'this' {} 234 | default {} 235 | } 236 | 237 | # Illegal backtick 238 | Invoke-Command -arg1 $val1 ` 239 | -arg2 $val2 ` 240 | 241 | # Functions and filters 242 | functioN MyFunction{} 243 | function My-Function {} 244 | Function My.Function{} 245 | function My-Function.Other{} 246 | function Some.other.function{} 247 | FUNCTION MyFunction2 {} 248 | function MyFunction3 249 | { 250 | 251 | } 252 | function New-File { } 253 | function New-File ($Name) { } 254 | function NewFile($Name) { } 255 | functionMyFunction{} 256 | filter myfilter($param) {} 257 | Filter my-Filter ($param){} 258 | 259 | function foo 260 | #comment 261 | { 262 | 263 | } 264 | 265 | # This one will not highlight the function name, 266 | # because of the comments after 'function'. TODO? 267 | function 268 | <# another comment #> 269 | test 270 | ( 271 | [string] 272 | <# another comment #> 273 | [parameter(mandatory)] 274 | $s 275 | ) 276 | { 277 | "test $s" 278 | } 279 | 280 | # Note that the # in the path should highlight as a comment! 281 | function Test-Drive([string]$roman) { 282 | $roman | c:\users\Me\Documents\Programming\F#\test.exe $roman 283 | } 284 | 285 | function Get-EscapedPath 286 | { 287 | param( 288 | [Parameter( 289 | Position=0, 290 | Mandatory=$true 291 | ValueFromPipeline=$true, 292 | ValueFromPipelineByPropertyName=$true) 293 | ] 294 | [string]$path 295 | ) 296 | 297 | process { 298 | if ($path.Contains(' ')) 299 | { 300 | return '"' + $path + '"' 301 | } 302 | return $path 303 | } 304 | } 305 | 306 | # Enum 307 | enum test 308 | { 309 | listItem1 310 | listItem2 311 | listItem3 312 | } 313 | 314 | # Illegal enum name 315 | enum my-Enum { 316 | 317 | } 318 | 319 | # Class 320 | class Vehicle { 321 | Vehicle() {} 322 | Vehicle([string]$Owner) { 323 | $this.Owner = $Owner 324 | } 325 | 326 | [int]$Mileage 327 | [int]$Age 328 | [string]$Owner 329 | 330 | [void]Drive([int]$NumberOfMiles) { 331 | $this.Mileage += $NumberOfMiles 332 | } 333 | } 334 | 335 | class Car: Vehicle { 336 | Car() {} 337 | 338 | Car([int]$Age) { 339 | $this.Age = $Age 340 | } 341 | 342 | Car([int]$Age, [string]$Owner) : base([string]$Owner) { 343 | $this.Age = $Age 344 | $this.Owner = $Owner 345 | } 346 | 347 | hidden [int]$Length 348 | static [int]$Width 349 | 350 | SetLength([int]$Length) { 351 | $this.Length = $Length 352 | } 353 | } 354 | 355 | # Illegal class name 356 | class my-class {} 357 | 358 | # Control words 359 | foreach ($item in $collection) { 360 | try { 361 | if ($item -gt 100) { 362 | continue 363 | } 364 | } 365 | catch { 366 | break 367 | } 368 | } 369 | 370 | # Reserved words 371 | Configuration Crazyness { 372 | Node Whatever { 373 | } 374 | } 375 | param () 376 | 377 | # Redirection 378 | notepad.exe > log.txt 379 | notepad.exe 1> log.txt 380 | notepad.exe 2>&1 381 | notepad.exe 3>&1 382 | notepad.exe 4>&1 383 | notepad.exe 5>&1 384 | notepad.exe 6>&1 385 | notepad.exe 2>&1> log.txt 386 | 387 | # Note: 7 isn't a valid stream 388 | notepad.exe 7>&1 389 | 390 | # Operators 391 | if (10 -cgt 100) { } 392 | $a -is $b 393 | $b -contains $c 394 | $x -notcontains $c 395 | $c -in $b 396 | $c -notin $x 397 | $a -match $b 398 | $a -notmatch $b 399 | $x -like $c 400 | 100 -and 0 401 | $a -ceq 4 -and $a -ine $d -or 402 | $c -is [Type] 403 | $c -isnot [Type] 404 | $c -as [Type] 405 | $k = $y -bor $k 406 | $x = $y -band $x 407 | $z = -bnot $x 408 | $k = $y -xor $b 409 | $k = $y -bxor $b 410 | $a -icontains $c 411 | $a -ccontains $c 412 | $a -iNotContains $c 413 | $a -cNotContains $c 414 | $a -cmatch $c 415 | $x -iMatch $c 416 | $x -iNotMatch $c 417 | $a -iLike $b 418 | $b -cLike $c 419 | "hey" -cgt "Hey" 420 | "Hey" -igt "hey" 421 | "hey" -cge "Hey" 422 | "Hey" -ige "hey" 423 | "HEY" -clt "hey" 424 | "HEY" -ilt "hey" 425 | "HEY" -cle "hey" 426 | "HEY" -ile "hey" 427 | 428 | # this isn't a valid operator: 429 | $x -foobar $y 430 | 431 | # Negative: these are cmdlets with unapproved verbs 432 | # we should not highlight keywords in them 433 | Foo-Is 434 | Foo-Not 435 | Foo-Join 436 | Foo-Bxor 437 | Foo-f 438 | Foo-eq 439 | Foo-match 440 | 441 | # format 442 | "{0:N2}" -f $a 443 | "{0:D8}" -f $a 444 | "{0:C2}" -f $a 445 | "{0:P0}" -f $a 446 | "{0:X0}" -f $a 447 | (1.11).tostring("#.#") 448 | "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 449 | ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) 450 | "{0:R}" -f (1mb/2.0) 451 | "{0:00.0}" -f 4.12341234 452 | "{0:##.#}" -f 4.12341234 453 | "{0:#,#.#}" -f 1234.121234 454 | "{0:##,,.000}" -f 1048576 455 | "{this is not a #comment}" 456 | "{0:##.#E000}" -f 2.71828 457 | "{0:#.00'##'}" -f 2.71828 458 | "{0:POS;NEG;ZERO}" -f -14 459 | "{0:$## Please}" -f 14 460 | "{0,-8:P1}" -f 1.75 461 | "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 462 | '{0:00000.000}' -f 7.125 463 | 464 | # Help Directives (Comment based help) 465 | 466 | # Should also be able to use with line comments 467 | # .DESCRIPTION 468 | # .EXAMPLE sdkl 469 | # 470 | # .EXTERNALHELP some 471 | # .REMOTEHELPRUNSPACE some 472 | # .ExternalHelp some 473 | 474 | <# 475 | .DESCRIPTION 476 | This is a description. 477 | .REMOTEHELPRUNSPACE some 478 | .example 479 | .EXAMPLE 480 | Get-Power 3 4 481 | 81 482 | 483 | .ExternalHelp C:\MyScripts\Update-Month-Help.xml 484 | 485 | .FORWARDHELPCATEGORY Cmdlet 486 | 487 | .FORWARDHELPTARGETNAME Get-Help 488 | 489 | .INPUTS 490 | None. 491 | 492 | .LINK 493 | Online version: http://www.acmecorp.com/widget.html 494 | .LINK 495 | Set-ProcedureName 496 | 497 | .NOTES 498 | Something. 499 | 500 | .OUTPUTS 501 | None unless the -PassThru switch parameter is used. 502 | 503 | .PARAMETER ParameterName 504 | 505 | .SYNOPSIS 506 | Something. 507 | #> 508 | 509 | # Misc test cases 510 | @("any","array","has").foreach({ $_ }) 511 | @('any','array','has').foreach{ $_ } 512 | @("any","array","has").where({ $_.Length -gt 3 }) 513 | @("any","array","has").where{ $_.Length -gt 3 } 514 | foo "$(x).exe" 515 | $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" 516 | $ScriptBlock | Out-File $file -Force 517 | workflow w1 {} 518 | Workflow work {} 519 | get-thing | Out-WithYou > $null # destroy 520 | "Escaped chars: `", `n, `$, `b, `t, `"" 521 | 'But here they''re not escape chars: `", `n, `$, `b, `"' 522 | "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" 523 | foo 524 | $a = $("Guess what, happens ""here, hey""" | "Hm... $("this, is" strange.) you can't really pipe to a string, but nevermind for now.") 525 | this-isnot.ps1 526 | a_mistake.here.ps1 527 | "anothermistake.ps1" 528 | $users.Split(',').Trim() 529 | TestConfiguration -OutputPath $workingDirectory 530 | "blablabla $(invoke-foo baz $a.bar) blablabla" 531 | invoke-foo baz $a.bar 532 | var 533 | -var 534 | _var 535 | jvar 536 | varj 537 | [ValidatePattern('^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] 538 | $foo.bar 539 | ($foo).bar 540 | (Invoke-Something).bar 541 | #comment 542 | some#comment # we need a space before the # for it to become a comment 543 | -------------------------------------------------------------------------------- /examples/advancedFunction.ps1: -------------------------------------------------------------------------------- 1 | using module Microsoft.PowerShell.Management 2 | 3 | <# 4 | .Synopsis 5 | Short description 6 | .DESCRIPTION 7 | Long description 8 | .EXAMPLE 9 | Example of how to use this cmdlet 10 | .EXAMPLE 11 | Another example of how to use this cmdlet 12 | .INPUTS 13 | Inputs to this cmdlet (if any) 14 | .OUTPUTS 15 | Output from this cmdlet (if any) 16 | .NOTES 17 | General notes 18 | .COMPONENT 19 | The component this cmdlet belongs to 20 | .ROLE 21 | The role this cmdlet belongs to 22 | .FUNCTIONALITY 23 | The functionality that best describes this cmdlet 24 | #> 25 | function Verb-Noun 26 | { 27 | [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', 28 | SupportsShouldProcess = $true, 29 | PositionalBinding = $false, 30 | HelpUri = 'http://www.microsoft.com/', 31 | ConfirmImpact = 'Medium')] 32 | [Alias()] 33 | [OutputType([String])] 34 | Param 35 | ( 36 | # Param1 help description 37 | [Parameter(Mandatory=$true, 38 | ValueFromPipeline=$true, 39 | ValueFromPipelineByPropertyName = $true, 40 | ValueFromRemainingArguments=$false, 41 | Position=0, 42 | ParameterSetName = 'Parameter Set 1')] 43 | [ValidateNotNull()] 44 | [ValidateNotNullOrEmpty()] 45 | [ValidateCount(0,5)] 46 | [ValidateSet("sun", "moon", "earth")] 47 | [Alias("p1")] 48 | $Param1, 49 | 50 | # Param2 help description 51 | [Parameter(ParameterSetName='Parameter Set 1')] 52 | [AllowNull()] 53 | [AllowEmptyCollection()] 54 | [AllowEmptyString()] 55 | [ValidateScript({$true})] 56 | [ValidateRange(0,5)] 57 | [int32] 58 | $Param2, 59 | 60 | 61 | # Param3 help description 62 | [Parameter(ParameterSetName='Another Parameter Set')] 63 | [ValidatePattern("[a-z]*")] 64 | [ValidateLength(0,15)] 65 | [String] 66 | $Param3, 67 | 68 | # Param4 help description 69 | [Parameter(ParameterSetName='Parameter Set 1')] 70 | [ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting 71 | [string] 72 | $Param4, 73 | 74 | # Param4 help description 75 | [Parameter(ParameterSetName='Parameter Set 1')] 76 | [ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting 77 | [string] 78 | $Param5 79 | ) 80 | 81 | Begin 82 | { 83 | } 84 | Process 85 | { 86 | if ($pscmdlet.ShouldProcess("Target", "Operation")) 87 | { 88 | } 89 | } 90 | End 91 | { 92 | } 93 | Clean 94 | { 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/class.ps1: -------------------------------------------------------------------------------- 1 | using namespace system.management.automation 2 | 3 | # Define a class 4 | class TypeName 5 | { 6 | # Property with validate set 7 | [ValidateSet("val1", "Val2")] 8 | [string] $P1 9 | 10 | # Static property 11 | static [hashtable] $P2 12 | 13 | # Hidden property does not show as result of Get-Member 14 | hidden [int] $P3 15 | 16 | # Constructor 17 | TypeName ([string] $s) 18 | { 19 | $this.P1 = $s 20 | } 21 | 22 | # Static method 23 | static [void] MemberMethod1([hashtable] $h) 24 | { 25 | [TypeName]::P2 = $h 26 | } 27 | 28 | # Instance method 29 | [int] MemberMethod2([int] $i) 30 | { 31 | $this.P3 = $i 32 | return $this.P3 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/test.ps1: -------------------------------------------------------------------------------- 1 | # Testing PowerShell syntax highlighting rules. 2 | 3 | ## Strings ## 4 | 5 | ### Single quoted strings 6 | 'Single quoted string.' 7 | 'Single "quoted" string.' 8 | 'Single ''quoted'' string.' 9 | 'Single quoted #string.' 10 | 'Single $quoted string.' 11 | 12 | ### Double quoted strings 13 | "Double quoted string." 14 | "Double 'quoted' string." 15 | "Double ""quoted"" string." 16 | "Double `"quoted`" string." 17 | "Double quoted #string." 18 | "Double $quoted string." 19 | 20 | ### Single quoted here-string 21 | @' 22 | Single quoted here-string. 23 | Single 'quoted' here-string. 24 | Single "quoted" here-string. 25 | Single quoted #here-string. 26 | Single $quoted here-string. 27 | '@ 28 | 29 | ### Double quoted here-string 30 | @" 31 | Double quoted here-string. 32 | Double "quoted" here-string. 33 | Double 'quoted' here-string. 34 | Double quoted #here-string. 35 | Double $quoted here-string. 36 | "@ 37 | 38 | ### Complex strings 39 | '^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)' 40 | 41 | # This one currently fails. It's the exact same string as the one above. Uncomment to check. 42 | #[ValidatePattern('^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] 43 | 44 | # Stop Parsing 45 | # Synatx highlighting should stop after --%, with the exception of the comment. 46 | command.exe -parameter 1 --% -parameter 2 /switch /par1:value # comment 47 | 48 | # Variables 49 | $name = 'value' 50 | "variable in a $string" 51 | "variable in a $($subExpression)" 52 | $global:name = 'value' 53 | $script:name = 'value' 54 | $local:name = 'value' 55 | $private:name = 'value' 56 | $using:name = 'value' 57 | ${name} = 'value' 58 | ${variable-name} = 'value' 59 | ${#name} = 'value' 60 | ${123} = 'value' 61 | ${'name'} = 'value' 62 | ${variable name} = 'value' 63 | ${global: variable name} = 'value' 64 | ${script:this`{value`}is} = 'valid' # don't currently work correctly 65 | $_ = $null 66 | $123 = 'value' 67 | $variable_name = 'value' 68 | $variable-name = 'value' # - in variable name is not allowed 69 | $$ 70 | 71 | # Syntax highlighting not consistent in these cases! 72 | $foo.bar 73 | ($foo).bar 74 | (Invoke-Something).bar 75 | 76 | # Sub Expression 77 | # Syntax highlighting not consistent in these two cases! 78 | "blablabla $(invoke-foo baz $a.bar) blablabla" 79 | invoke-foo baz $a.bar 80 | 81 | # Arrays 82 | @('One', 2, $three) 83 | ('One', 2, $three) 84 | $p = @(Get-Process Notepad) 85 | $a[0] 86 | $a[-3..-1] 87 | $a[0,2+4..6] 88 | ,(1,2,3) 89 | ,$a 90 | $t = $a[0,1 + 3..($a.length - 1)] 91 | 92 | # Hash Table 93 | @{ 94 | Key = 'Value' 95 | Key = 123 96 | Key = $value 97 | } 98 | 99 | $ht = @{ 100 | Key = 'Value' 101 | Key = 123 102 | Key = $value 103 | } 104 | 105 | $hash = [ordered]@{ Number = 1; Shape = "Square"; Color = "Blue"} 106 | 107 | # Splatting 108 | Invoke-Something @parameters 109 | 110 | # Script Block 111 | { 112 | 'String' 113 | Invoke-Something -p1 'value' -p2 $value 114 | } 115 | 116 | $sb = { 117 | 'String' 118 | Invoke-Something -p1 'value' -p2 $value 119 | } 120 | 121 | # Types and .NET classes 122 | [string]$var = 'string' 123 | [system.string]$var = 'string' 124 | [int]$var = 100 125 | [uint64]$var = 100 126 | [System.String]::Empty 127 | [System.DateTime]::Parse('2016/09/21') 128 | [int32[]]$ia = 1500,2230,3350,4000 129 | 130 | # Numeric constants 131 | 1 132 | 9,9 133 | 9.9 134 | 10gb 135 | 2/5kb 136 | 137 | # Numeric formatting 138 | # {index[,alignment][:formatString]} 139 | $a = 348 140 | "{0:N2}" -f $a 141 | "{0:D8}" -f $a 142 | "{0:C2}" -f $a 143 | "{0:P0}" -f $a 144 | "{0:X0}" -f $a 145 | (1.11).tostring("#.#") 146 | "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 147 | ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) 148 | "{0:R}" -f (1mb/2.0) 149 | "{0:00.0}" -f 4.12341234 150 | "{0:##.#}" -f 4.12341234 151 | "{0:#,#.#}" -f 1234.121234 152 | "{0:##,,.000}" -f 1048576 153 | "{this is not a #comment}" 154 | "{0:##.#E000}" -f 2.71828 155 | "{0:#.00'##'}" -f 2.71828 156 | "{0:POS;NEG;ZERO}" -f -14 157 | "{0:$## Please}" -f 14 158 | "{0,-8:P1}" -f 1.75 159 | "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 160 | '{0:00000.000}' -f 7.125 161 | 162 | # Operators 163 | $i = 0 164 | $i++ 165 | $i += 10 166 | $a -band $b 167 | $x -gt $y 168 | $string -not $null 169 | $int -as [double] 170 | if (! $variable) {} 171 | if (-not $variable) {} 172 | $a -band $b 173 | $a -shr $b 174 | $a -eq $b 175 | $a -le $b 176 | $a -less $b # -less is not a valid operator and shouldn't be tagged and highlighted as such. 177 | 178 | # Parameters 179 | Write-Host -Message 'This is a message' 180 | Write-Host 'This is a message' 181 | Write-Host something something 182 | Get-WmiObject -Class Win32_OperatingSystem -ComputerName localhost | Select-Object -Property CSName,LastBootupTime 183 | 184 | # Functions and filters 185 | functioN MyFunction{} 186 | function My-Function {} 187 | Function My.Function{} 188 | function My-Function.Other{} 189 | function Some.other.function{} 190 | FUNCTION MyFunction2 {} 191 | function MyFunction3 192 | { 193 | 194 | } 195 | function New-File { } 196 | function New-File ($Name) { } 197 | function NewFile($Name) { } 198 | functionMyFunction{} 199 | filter myfilter($param) {} 200 | Filter my-Filter ($param){} 201 | function global:Invoke-Something {} 202 | 203 | # This variant don't work properly 204 | function 205 | #comment 206 | <# another comment #> 207 | test 208 | ( 209 | [string] 210 | <# another comment #> 211 | [parameter(mandatory)] 212 | $s 213 | ) 214 | { 215 | "test $s" 216 | } 217 | 218 | # Enum 219 | enum myEnum 220 | { 221 | listItem1 222 | listItem2 223 | listItem3 224 | } 225 | 226 | # - in enum name is not allowed 227 | enum my-Enum { 228 | listItem1 229 | listItem2 230 | listItem3 231 | } 232 | 233 | # Class 234 | class myClass {} 235 | 236 | # - in class name is not allowed 237 | class my-Class {} 238 | 239 | # DSC 240 | configuration myConfiguration { 241 | node web01, web02, web03 { 242 | 243 | } 244 | } 245 | 246 | # Switch 247 | # switch [-regex|-wildcard|-exact][-casesensitive] () 248 | # switch [-regex|-wildcard|-exact][-casesensitive] -file filename 249 | switch ($variable) 250 | { 251 | 'Value' { 252 | return $false 253 | } 254 | 255 | 2 {} 256 | 257 | {$value -le 100} {} 258 | 259 | default { 260 | return $true 261 | } 262 | } 263 | 264 | switch ("fourteen") {} 265 | switch -CaseSensitive ("fourteen") {} 266 | switch -Illegal ("fourteen") {} 267 | switch -Regex ("fourteen") {} 268 | switch -Wildcard ($a) {} 269 | switch -regex -file .\somefile.txt {} 270 | switch (3) {} 271 | switch (4, 2) {} 272 | 273 | # Executable files 274 | . .\otherScript.ps1 275 | & cmd.exe 276 | c:\windows\system32\command.com 277 | c:\file.txt 278 | file.txt 279 | command.cmd 280 | co.cmd 281 | a.bat 282 | aa.bat 283 | aaa.bat 284 | aaaa.bat 285 | øyvind.ps1 286 | my file.exe 287 | 288 | # Comment based help and keywords 289 | # .ExternalHelp psake.psm1-help.xml 290 | #Requires -Version 2.0 # <-- should #Requires statements be highlighted differently? 291 | 292 | <# 293 | .PARAMETER 294 | Something 295 | .SYNOPSISIS 296 | Something 297 | .SYNOPSIS 298 | .INPUTS 299 | #> 300 | 301 | # Methods 302 | # Only the first method name is highlighted correctly. 303 | $users.Split(',').Trim() 304 | 305 | # Redirection 306 | # Examples from https://technet.microsoft.com/en-us/library/hh847746.aspx 307 | Get-Process > Process.txt 308 | dir *.ps1 >> Scripts.txt 309 | Get-Process none 2> Errors.txt 310 | Get-Process none 2>> Save-Errors.txt 311 | Get-Process none, Powershell 2>&1 312 | Write-Warning "Test!" 3> Warnings.txt 313 | Write-Warning "Test!" 3>> Save-Warnings.txt 314 | Test-Warning 3>&1 315 | Import-Module * -Verbose 4> Verbose.txt 316 | Import-Module * -Verbose 4>> Save-Verbose.txt 317 | Import-Module * -Verbose 4>&1 318 | Write-Debug "Starting" 5> Debug.txt 319 | Write-Debug "Saving" 5>> Save-Debug.txt 320 | Test-Debug 5>&1 321 | Test-Output *> Test-Output.txt 322 | Test-Output *>> Test-Output.txt 323 | Test-Output *>&1 324 | 325 | # Special characters 326 | # Should these be highlighted differently? 327 | "`0" 328 | for ($i = 0; $i -le 1; $i++){"`a"} 329 | "backup`b`b out" 330 | "There are two line breaks`n`nhere." 331 | Write-Host "Let's not move`rDelete everything before this point." 332 | "Column1`t`tColumn2`t`tColumn3" 333 | 334 | # Range 335 | Get-ChildItem c:\techdocs\[a-l]*.txt 336 | 337 | # Other - strange cases 338 | [string] 339 | [string('string')] 340 | [string("string")] 341 | [string(Something = $true)] 342 | [Parameter(Something = $true)] 343 | string('string') 344 | 'string' 345 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EditorSyntax", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "atom-grammar-test": { 8 | "version": "0.6.4", 9 | "resolved": "https://registry.npmjs.org/atom-grammar-test/-/atom-grammar-test-0.6.4.tgz", 10 | "integrity": "sha1-2KU1A9H+k5mX9Ji3SirDEARKfU4=", 11 | "requires": { 12 | "chevrotain": "0.18.0", 13 | "escape-string-regexp": "1.0.5" 14 | } 15 | }, 16 | "chevrotain": { 17 | "version": "0.18.0", 18 | "resolved": "https://registry.npmjs.org/chevrotain/-/chevrotain-0.18.0.tgz", 19 | "integrity": "sha1-sodxTjFZC64sXR4vYRZz7+xHnYA=" 20 | }, 21 | "escape-string-regexp": { 22 | "version": "1.0.5", 23 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 24 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" 25 | }, 26 | "fast-plist": { 27 | "version": "0.1.2", 28 | "resolved": "https://registry.npmjs.org/fast-plist/-/fast-plist-0.1.2.tgz", 29 | "integrity": "sha1-pFr/NFGWAG1AbKbNzQX2kFHvNbg=" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EditorSyntax", 3 | "license": "MIT", 4 | "description": "PowerShell language syntax", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/PowerShell/EditorSyntax.git" 8 | }, 9 | "version": "1.0.0", 10 | "engines": { 11 | "atom": "*", 12 | "node": "*" 13 | }, 14 | "dependencies": { 15 | "fast-plist": "0.1.2", 16 | "atom-grammar-test": "^0.6.3" 17 | }, 18 | "scripts": { 19 | "build-grammar": "node ./tools/build-grammar.js ./PowerShellSyntax.tmLanguage ./grammars/powershell.tmLanguage.json" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spec/powershell-spec.coffee: -------------------------------------------------------------------------------- 1 | grammarTest = require 'atom-grammar-test' 2 | path = require 'path' 3 | 4 | ####################################################################### 5 | # Scopes 6 | ####################################################################### 7 | # 8 | # When modifying or adding scopes do so using the variables below. Tests 9 | # should use the variables and not strings to avoid duplication of work and errors. 10 | # 11 | # If a symbol or construct has different scopes under different conditions make 12 | # sure it makes sense like @ defining a splat and @ defining a hashtable. Otherwise 13 | # aim for consistency as much as possible. 14 | # 15 | # - Scope naming: https://www.sublimetext.com/docs/3/scope_naming.html 16 | # - Language specific: All scopes should end with '.powershell'. 17 | # - Exceptions: when an exception is made for cosmetic or consistency reasons 18 | # leave a comment above the scope with the reasoning. 19 | # 20 | # This file should be used as a reference when working on the 'examples\'. When you 21 | # change a scope make sure you check the example files for any occurances. 22 | 23 | # ------------------------------- Setup ------------------------------- 24 | 25 | atomPackage = 'EditorSyntax' 26 | docScope = 'source.powershell' 27 | 28 | # -------------------------- Tokens / Symbols ------------------------- 29 | 30 | # Comments 31 | singleLineCommentOpen = 'punctuation.definition.comment.powershell' # # 32 | commentBlockOpen = 'punctuation.definition.comment.block.begin.powershell' # <# 33 | commentBlockClose = 'punctuation.definition.comment.block.end.powershell' # #> 34 | 35 | # ------------------------------- Basic ------------------------------- 36 | 37 | # Comments 38 | singleLineComment = 'comment.line.powershell' 39 | commentDocSection = 'comment.block.documentation.powershell' 40 | commentDocKeyword = 'keyword.operator.documentation.powershell' 41 | 42 | # ---------------------------- Meta Scopes ---------------------------- 43 | 44 | # Comments 45 | metaCommentBlock = 'comment.block.powershell' 46 | 47 | ####################################################################### 48 | # Tests 49 | ####################################################################### 50 | 51 | describe 'PowerShell Grammar', -> 52 | grammar = null 53 | 54 | beforeEach -> 55 | waitsForPromise -> 56 | atom.packages.activatePackage atomPackage, 57 | 58 | runs -> 59 | grammar = atom.grammars.grammarForScopeName(docScope) 60 | 61 | it 'parses the grammar', -> 62 | expect(grammar).toBeTruthy() 63 | expect(grammar.scopeName).toBe docScope 64 | 65 | # Directly test comments as comment tokens are used for atom-grammar-test 66 | describe 'Comments', -> 67 | it 'tokenizes single line comments correctly.', -> 68 | {tokens} = grammar.tokenizeLine '# This is a comment.' 69 | 70 | expect(tokens[0]).toEqual value: '#', scopes: [docScope, singleLineComment, singleLineCommentOpen] 71 | expect(tokens[1]).toEqual value: ' This is a comment.', scopes: [docScope, singleLineComment] 72 | 73 | it 'tokenizes comment blocks correctly.', -> 74 | lines = grammar.tokenizeLines ''' 75 | <# 76 | This is a comment block 77 | #> 78 | <# 79 | # This is still a comment block 80 | #> 81 | ''' 82 | 83 | expect(lines[0][0]).toEqual value: '<#', scopes: [docScope, metaCommentBlock, commentBlockOpen] 84 | expect(lines[1][0]).toEqual value: ' This is a comment block', scopes: [docScope, metaCommentBlock] 85 | expect(lines[2][0]).toEqual value: '#>', scopes: [docScope, metaCommentBlock, commentBlockClose] 86 | expect(lines[3][0]).toEqual value: '<#', scopes: [docScope, metaCommentBlock, commentBlockOpen] 87 | expect(lines[4][0]).toEqual value: '# This is still a comment block', scopes: [docScope, metaCommentBlock] 88 | expect(lines[5][0]).toEqual value: '#>', scopes: [docScope, metaCommentBlock, commentBlockClose] 89 | 90 | describe 'Automated tests', -> 91 | describe 'syntax_test_Function.ps1', -> 92 | grammarTest path.join(__dirname, 'testfiles/syntax_test_Function.ps1') 93 | describe 'syntax_test_Class.ps1', -> 94 | grammarTest path.join(__dirname, 'testfiles/syntax_test_Class.ps1') 95 | describe 'syntax_test_TheBigTestFile.ps1', -> 96 | grammarTest path.join(__dirname, 'testfiles/syntax_test_TheBigTestFile.ps1') 97 | -------------------------------------------------------------------------------- /spec/testfiles/syntax_test_Class.ps1: -------------------------------------------------------------------------------- 1 | # SYNTAX TEST "source.powershell" 2 | using namespace system.management.automation 3 | # <- keyword.control.using.powershell 4 | # ^ keyword.other.powershell 5 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.powershell 6 | 7 | # Define a class 8 | class TypeName 9 | # <- storage.type.powershell 10 | # ^ entity.name.function 11 | { 12 | # Property with validate set 13 | # <- punctuation.definition.comment.powershell 14 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 15 | [ValidateSet("val1", "Val2")] 16 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 17 | # ^ meta.attribute.powershell support.function.attribute.powershell 18 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 19 | # ^^^^^^ meta.attribute.powershell string.quoted.double.powershell 20 | # ^ meta.attribute.powershell keyword.operator.other.powershell 21 | # ^^^^^^ meta.attribute.powershell string.quoted.double.powershell 22 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 23 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 24 | [string] $P1 25 | # <- punctuation.section.bracket.begin.powershell 26 | # ^ storage.type.powershell 27 | # ^ punctuation.section.bracket.end.powershell 28 | # ^ punctuation.definition.variable.powershell 29 | # ^^ variable.other.readwrite.powershell 30 | 31 | # Static property 32 | # <- punctuation.definition.comment.powershell 33 | # ^^^^^^^^^^^^^^^ comment.line.powershell 34 | static [hashtable] $P2 35 | # <- storage.modifier.powershell 36 | # ^ punctuation.section.bracket.begin.powershell 37 | # ^ storage.type.powershell 38 | # ^ punctuation.section.bracket.end.powershell 39 | # ^ punctuation.definition.variable.powershell 40 | # ^^ variable.other.readwrite.powershell 41 | 42 | # Hidden property does not show as result of Get-Member 43 | # <- punctuation.definition.comment.powershell 44 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 45 | hidden [int] $P3 46 | # <- storage.modifier.powershell 47 | # ^ punctuation.section.bracket.begin.powershell 48 | # ^ storage.type.powershell 49 | # ^ punctuation.section.bracket.end.powershell 50 | # ^ punctuation.definition.variable.powershell 51 | # ^^ variable.other.readwrite.powershell 52 | 53 | # Constructor 54 | # <- punctuation.definition.comment.powershell 55 | # ^^^^^^^^^^^ comment.line.powershell 56 | TypeName ([string] $s) { 57 | # ^ punctuation.section.group.begin.powershell 58 | # ^ punctuation.section.bracket.begin.powershell 59 | # ^^^^^^ storage.type.powershell 60 | # ^ punctuation.section.bracket.end.powershell 61 | # ^ punctuation.definition.variable.powershell 62 | # ^ variable.other.readwrite.powershell 63 | # ^ punctuation.section.group.end.powershell 64 | $this.P1 = $s 65 | # <- punctuation.definition.variable.powershell 66 | # ^ support.variable.automatic.powershell 67 | # ^^ variable.other.member.powershell 68 | # ^ keyword.operator.assignment.powershell 69 | # ^ punctuation.definition.variable.powershell 70 | # ^ variable.other.readwrite.powershell 71 | } 72 | 73 | # Static method 74 | # <- punctuation.definition.comment.powershell 75 | # ^^^^^^^^^^^^^ comment.line.powershell 76 | static [void] MemberMethod1([hashtable] $h) { 77 | # <- storage.modifier.powershell 78 | # ^ punctuation.section.bracket.begin.powershell 79 | # ^^^^ storage.type.powershell 80 | # ^ punctuation.section.bracket.end.powershell 81 | # ^ punctuation.section.group.begin.powershell 82 | # ^ punctuation.section.bracket.begin.powershell 83 | # ^^^^^^^^^ storage.type.powershell 84 | # ^ punctuation.section.bracket.end.powershell 85 | # ^ punctuation.definition.variable.powershell 86 | # ^ variable.other.readwrite.powershell 87 | # ^ punctuation.section.group.end.powershell 88 | [TypeName]::P2 = $h 89 | # <- punctuation.section.bracket.begin.powershell 90 | # ^ storage.type.powershell 91 | # ^ punctuation.section.bracket.end.powershell 92 | # ^ keyword.operator.assignment.powershell 93 | # ^ punctuation.definition.variable.powershell 94 | # ^ variable.other.readwrite.powershell 95 | } 96 | 97 | # Instance method 98 | # <- punctuation.definition.comment.powershell 99 | # ^^^^^^^^^^^^^^^ comment.line.powershell 100 | [int] MemberMethod2([int] $i) { 101 | # <- punctuation.section.bracket.begin.powershell 102 | # ^ storage.type.powershell 103 | # ^ punctuation.section.bracket.end.powershell 104 | # ^ punctuation.section.group.begin.powershell 105 | # ^ punctuation.section.bracket.begin.powershell 106 | # ^^^ storage.type.powershell 107 | # ^ punctuation.section.bracket.end.powershell 108 | # ^ punctuation.definition.variable.powershell 109 | # ^ variable.other.readwrite.powershell 110 | # ^ punctuation.section.group.end.powershell 111 | $this.P3 = $i 112 | # <- punctuation.definition.variable.powershell 113 | # ^ support.variable.automatic.powershell 114 | # ^^ variable.other.member.powershell 115 | # ^ keyword.operator.assignment.powershell 116 | # ^ punctuation.definition.variable.powershell 117 | # ^ variable.other.readwrite.powershell 118 | return $this.P3 119 | # <- keyword.control.powershell 120 | # ^ punctuation.definition.variable.powershell 121 | # ^^^^ support.variable.automatic.powershell 122 | # ^^ variable.other.member.powershell 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /spec/testfiles/syntax_test_Function.ps1: -------------------------------------------------------------------------------- 1 | # SYNTAX TEST "source.powershell" 2 | using module Microsoft.PowerShell.Management 3 | # <- keyword.control.using.powershell 4 | # ^ keyword.other.powershell 5 | # ^ variable.parameter.powershell 6 | 7 | <# 8 | # <- punctuation.definition.comment.block.begin.powershell 9 | .Synopsis 10 | # <- constant.string.documentation.powershell 11 | # ^ keyword.operator.documentation.powershell 12 | Short description 13 | .DESCRIPTION 14 | # <- constant.string.documentation.powershell 15 | # ^ keyword.operator.documentation.powershell 16 | Long description 17 | .EXAMPLE 18 | # <- constant.string.documentation.powershell 19 | # ^ keyword.operator.documentation.powershell 20 | Example of how to use this cmdlet 21 | .EXAMPLE 22 | # <- constant.string.documentation.powershell 23 | # ^ keyword.operator.documentation.powershell 24 | Another example of how to use this cmdlet 25 | .INPUTS 26 | # <- constant.string.documentation.powershell 27 | # ^ keyword.operator.documentation.powershell 28 | Inputs to this cmdlet (if any) 29 | .OUTPUTS 30 | # <- constant.string.documentation.powershell 31 | # ^ keyword.operator.documentation.powershell 32 | Output from this cmdlet (if any) 33 | .NOTES 34 | # <- constant.string.documentation.powershell 35 | # ^ keyword.operator.documentation.powershell 36 | General notes 37 | .COMPONENT 38 | # <- constant.string.documentation.powershell 39 | # ^ keyword.operator.documentation.powershell 40 | The component this cmdlet belongs to 41 | .ROLE 42 | # <- constant.string.documentation.powershell 43 | # ^ keyword.operator.documentation.powershell 44 | The role this cmdlet belongs to 45 | .FUNCTIONALITY 46 | # <- constant.string.documentation.powershell 47 | # ^ keyword.operator.documentation.powershell 48 | The functionality that best describes this cmdlet 49 | 50 | This should not be considered documentaton -> .role 51 | # ^ not:keyword.operator.documentation.powershell 52 | #> 53 | # <- punctuation.definition.comment.block.end.powershell 54 | function Verb-Noun { 55 | # <- meta.function storage.type 56 | # ^ meta.function entity.name.function.powershell 57 | [CmdletBinding(DefaultParameterSetName = 'Parameter Set 1', 58 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 59 | # ^ meta.attribute.powershell support.function.attribute.powershell 60 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 61 | # ^ meta.attribute.powershell variable.parameter.attribute.powershell 62 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 63 | # ^ meta.attribute.powershell string.quoted.single.powershell 64 | SupportsShouldProcess = $true, 65 | # ^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 66 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 67 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 68 | # ^^^^ meta.attribute.powershell constant.language.powershell 69 | PositionalBinding = $false, 70 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 71 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 72 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 73 | # ^^^^^ meta.attribute.powershell constant.language.powershell 74 | HelpUri = 'http://www.microsoft.com/', 75 | # ^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 76 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 77 | # ^ meta.attribute.powershell string.quoted.single.powershell 78 | ConfirmImpact = 'Medium')] 79 | # ^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 80 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 81 | # ^ meta.attribute.powershell string.quoted.single.powershell 82 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 83 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 84 | [Alias()] 85 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 86 | # ^ meta.attribute.powershell support.function.attribute.powershell 87 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 88 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 89 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 90 | [OutputType([String])] 91 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 92 | # ^ meta.attribute.powershell support.function.attribute.powershell 93 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 94 | # ^ meta.attribute.powershell punctuation.section.bracket.begin.powershell 95 | # ^^^^^^ meta.attribute.powershell storage.type.powershell 96 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 97 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 98 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 99 | Param 100 | # <- keyword.control.powershell 101 | ( 102 | # <- punctuation.section.group.begin.powershell 103 | # Param1 help description 104 | # <- comment.line.powershell punctuation.definition.comment.powershell 105 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 106 | [Parameter(Mandatory=$true, 107 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 108 | # ^ meta.attribute.powershell support.function.attribute.powershell 109 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 110 | # ^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 111 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 112 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 113 | # ^^^^ meta.attribute.powershell constant.language.powershell 114 | # ^ meta.attribute.powershell keyword.operator.other.powershell 115 | ValueFromPipeline=$true, 116 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 117 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 118 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 119 | # ^^^^ meta.attribute.powershell constant.language.powershell 120 | # ^ meta.attribute.powershell keyword.operator.other.powershell 121 | ValueFromPipelineByPropertyName = $true, 122 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 123 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 124 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 125 | # ^^^^ meta.attribute.powershell constant.language.powershell 126 | # ^ meta.attribute.powershell keyword.operator.other.powershell 127 | ValueFromRemainingArguments=$false, 128 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 129 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 130 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 131 | # ^^^^^ meta.attribute.powershell constant.language.powershell 132 | # ^ meta.attribute.powershell keyword.operator.other.powershell 133 | Position=0, 134 | # ^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 135 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 136 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 137 | # ^ meta.attribute.powershell keyword.operator.other.powershell 138 | ParameterSetName = 'Parameter Set 1')] 139 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 140 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 141 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 142 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 143 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 144 | [ValidateNotNullOrEmpty()] 145 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 146 | # ^ meta.attribute.powershell support.function.attribute.powershell 147 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 148 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 149 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 150 | [ValidateNotNull()] 151 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 152 | # ^ meta.attribute.powershell support.function.attribute.powershell 153 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 154 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 155 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 156 | [ValidateNotNullOrEmpty()] 157 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 158 | # ^ meta.attribute.powershell support.function.attribute.powershell 159 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 160 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 161 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 162 | [ValidateCount(0,5)] 163 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 164 | # ^ meta.attribute.powershell support.function.attribute.powershell 165 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 166 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 167 | # ^ meta.attribute.powershell keyword.operator.other.powershell 168 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 169 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 170 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 171 | [ValidateSet("sun", "moon", "earth")] 172 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 173 | # ^ meta.attribute.powershell support.function.attribute.powershell 174 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 175 | # ^^^^ meta.attribute.powershell string.quoted.double.powershell 176 | # ^ meta.attribute.powershell keyword.operator.other.powershell 177 | # ^^^^^^ meta.attribute.powershell string.quoted.double.powershell 178 | # ^ meta.attribute.powershell keyword.operator.other.powershell 179 | # ^^^^^^^ meta.attribute.powershell string.quoted.double.powershell 180 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 181 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 182 | [Alias("p1")] 183 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 184 | # ^ meta.attribute.powershell support.function.attribute.powershell 185 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 186 | # ^^^^ meta.attribute.powershell string.quoted.double.powershell 187 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 188 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 189 | $Param1, 190 | # <- punctuation.definition.variable.powershell 191 | # ^ variable.other.readwrite.powershell 192 | # ^ keyword.operator.other.powershell 193 | 194 | # Param2 help description 195 | # <- comment.line.powershell punctuation.definition.comment.powershell 196 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 197 | [Parameter(ParameterSetName='Parameter Set 1')] 198 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 199 | # ^ meta.attribute.powershell support.function.attribute.powershell 200 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 201 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 202 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 203 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 204 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 205 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 206 | [AllowNull()] 207 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 208 | # ^ meta.attribute.powershell support.function.attribute.powershell 209 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 210 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 211 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 212 | [AllowEmptyCollection()] 213 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 214 | # ^ meta.attribute.powershell support.function.attribute.powershell 215 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 216 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 217 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 218 | [AllowEmptyString()] 219 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 220 | # ^ meta.attribute.powershell support.function.attribute.powershell 221 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 222 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 223 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 224 | [ValidateScript({$true})] 225 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 226 | # ^ meta.attribute.powershell support.function.attribute.powershell 227 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 228 | # ^ meta.scriptblock.powershell meta.attribute.powershell 229 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 230 | # ^^^^ meta.scriptblock.powershell constant.language.powershell 231 | # ^ meta.scriptblock.powershell meta.attribute.powershell 232 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 233 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 234 | [ValidateRange(0,5)] 235 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 236 | # ^ meta.attribute.powershell support.function.attribute.powershell 237 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 238 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 239 | # ^ meta.attribute.powershell keyword.operator.other.powershell 240 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 241 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 242 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 243 | [int32] 244 | # <- punctuation.section.bracket.begin.powershell 245 | # ^ storage.type.powershell 246 | # ^ punctuation.section.bracket.end.powershell 247 | $Param2, 248 | # <- punctuation.definition.variable.powershell 249 | # ^ variable.other.readwrite.powershell 250 | # ^ keyword.operator.other.powershell 251 | 252 | # Param3 help description 253 | # <- comment.line.powershell punctuation.definition.comment.powershell 254 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 255 | [Parameter(ParameterSetName='Another Parameter Set')] 256 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 257 | # ^ meta.attribute.powershell support.function.attribute.powershell 258 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 259 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 260 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 261 | # ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 262 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 263 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 264 | [ValidatePattern("[a-z]*")] 265 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 266 | # ^ meta.attribute.powershell support.function.attribute.powershell 267 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 268 | # ^^^^^^^^ meta.attribute.powershell string.quoted.double.powershell 269 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 270 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 271 | [ValidateLength(0,15)] 272 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 273 | # ^ meta.attribute.powershell support.function.attribute.powershell 274 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 275 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 276 | # ^ meta.attribute.powershell keyword.operator.other.powershell 277 | # ^^ meta.attribute.powershell constant.numeric.integer.powershell 278 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 279 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 280 | [String] 281 | # <- punctuation.section.bracket.begin.powershell 282 | # ^ storage.type.powershell 283 | # ^ punctuation.section.bracket.end.powershell 284 | $Param3, 285 | # <- punctuation.definition.variable.powershell 286 | # ^ variable.other.readwrite.powershell 287 | # ^ keyword.operator.other.powershell 288 | 289 | # Param4 help description 290 | # <- comment.line.powershell punctuation.definition.comment.powershell 291 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 292 | [Parameter(ParameterSetName='Parameter Set 1')] 293 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 294 | # ^ meta.attribute.powershell support.function.attribute.powershell 295 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 296 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 297 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 298 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 299 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 300 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 301 | [ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting 302 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 303 | # ^ meta.attribute.powershell support.function.attribute.powershell 304 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 305 | # ^ meta.attribute.powershell meta.scriptblock.powershell 306 | # ^^^^^^^^^ meta.scriptblock.powershell support.function.powershell 307 | # ^ meta.scriptblock.powershell punctuation.definition.variable.powershell 308 | # ^ meta.scriptblock.powershell support.variable.automatic.powershell 309 | # ^ meta.attribute.powershell meta.scriptblock.powershell 310 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 311 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 312 | [string] 313 | # <- punctuation.section.bracket.begin.powershell 314 | # ^ storage.type.powershell 315 | # ^ punctuation.section.bracket.end.powershell 316 | $Param4, 317 | # <- punctuation.definition.variable.powershell 318 | # ^ variable.other.readwrite.powershell 319 | # ^ keyword.operator.other.powershell 320 | 321 | # Param5 help description 322 | # <- comment.line.powershell punctuation.definition.comment.powershell 323 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 324 | [Parameter(ParameterSetName='Parameter Set 1')] 325 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 326 | # ^ meta.attribute.powershell support.function.attribute.powershell 327 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 328 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 329 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 330 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 331 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 332 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 333 | [ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting 334 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 335 | # ^ meta.attribute.powershell support.function.attribute.powershell 336 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 337 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 338 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 339 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 340 | # ^ comment.line.powershell punctuation.definition.comment.powershell 341 | # ^ comment.line.powershell 342 | [string] 343 | # <- punctuation.section.bracket.begin.powershell 344 | # ^ storage.type.powershell 345 | # ^ punctuation.section.bracket.end.powershell 346 | $Param5 347 | # <- punctuation.definition.variable.powershell 348 | # ^ variable.other.readwrite.powershell 349 | ) 350 | # <- punctuation.section.group.end.powershell 351 | 352 | Begin 353 | # <- keyword.control.powershell 354 | { 355 | } 356 | Process { 357 | # <- keyword.control.powershell 358 | if ($pscmdlet.ShouldProcess("Target", "Operation")) { 359 | # <- keyword.control.powershell 360 | # ^ punctuation.section.group.begin.powershell 361 | # ^ punctuation.definition.variable.powershell 362 | # ^^^^^^^^ support.variable.automatic.powershell 363 | # ^^^^^^^^^^^^^ variable.other.member.powershell 364 | # ^ punctuation.section.group.begin.powershell 365 | # ^ punctuation.section.group.end.powershell 366 | # ^ punctuation.section.group.end.powershell 367 | } 368 | } 369 | End { 370 | # <- keyword.control.powershell 371 | 372 | } 373 | Clean { 374 | # <- keyword.control.powershell 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /spec/testfiles/syntax_test_TheBigTestFile.ps1: -------------------------------------------------------------------------------- 1 | # SYNTAX TEST "source.powershell" 2 | using namespace System.Management.Automation 3 | # <- keyword.control.using.powershell 4 | # ^ keyword.other.powershell 5 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.powershell 6 | #Requires -PSSnapin DiskSnapin -Version 1.2 7 | # <- punctuation.definition.comment.powershell 8 | # ^ meta.requires.powershell keyword.control.requires.powershell 9 | # ^^^^^^^^^ meta.requires.powershell keyword.other.powershell 10 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 11 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 12 | # ^^^ meta.requires.powershell variable.parameter.powershell 13 | #Requires -PSSnapin DiskSnapin 14 | # <- punctuation.definition.comment.powershell 15 | # ^ meta.requires.powershell keyword.control.requires.powershell 16 | # ^^^^^^^^^ meta.requires.powershell keyword.other.powershell 17 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 18 | #Requires -Version 3 19 | # <- punctuation.definition.comment.powershell 20 | # ^ meta.requires.powershell keyword.control.requires.powershell 21 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 22 | # ^ meta.requires.powershell variable.parameter.powershell 23 | #Requires -Version 3.0 24 | # <- punctuation.definition.comment.powershell 25 | # ^ meta.requires.powershell keyword.control.requires.powershell 26 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 27 | # ^^^ meta.requires.powershell variable.parameter.powershell 28 | #Requires -Version 3 -RunAsAdministrator 29 | # <- punctuation.definition.comment.powershell 30 | # ^ meta.requires.powershell keyword.control.requires.powershell 31 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 32 | # ^ meta.requires.powershell variable.parameter.powershell 33 | # ^^^^^^^^^^^^^^^^^^^ meta.requires.powershell keyword.other.powershell 34 | #Requires -RunAsAdministrator 35 | # <- punctuation.definition.comment.powershell 36 | # ^ meta.requires.powershell keyword.control.requires.powershell 37 | # ^^^^^^^^^^^^^^^^^^^ meta.requires.powershell keyword.other.powershell 38 | #Requires -Modules PSWorkflow 39 | # <- punctuation.definition.comment.powershell 40 | # ^ meta.requires.powershell keyword.control.requires.powershell 41 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 42 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 43 | #Requires -Modules PSWorkflow -ThisIsInvalid 44 | # <- punctuation.definition.comment.powershell 45 | # ^ meta.requires.powershell keyword.control.requires.powershell 46 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 47 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 48 | # ^^^^^^^^^^^^^^ meta.requires.powershell 49 | #Requires -Modules PSWorkflow, ActiveDirectory 50 | # <- punctuation.definition.comment.powershell 51 | # ^ meta.requires.powershell keyword.control.requires.powershell 52 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 53 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 54 | # ^^^^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 55 | #Requires -Modules PSWorkflow,ActiveDirectory 56 | # <- punctuation.definition.comment.powershell 57 | # ^ meta.requires.powershell keyword.control.requires.powershell 58 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 59 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 60 | # ^^^^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 61 | #Requires -ShellId MyLocalShell 62 | # <- punctuation.definition.comment.powershell 63 | # ^ meta.requires.powershell keyword.control.requires.powershell 64 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 65 | # ^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 66 | #Requires -PSEdition Core 67 | # <- punctuation.definition.comment.powershell 68 | # ^ meta.requires.powershell keyword.control.requires.powershell 69 | # ^^^^^^^^^^ meta.requires.powershell keyword.other.powershell 70 | # ^^^^ meta.requires.powershell variable.parameter.powershell 71 | #Requires -Assembly System 72 | # <- punctuation.definition.comment.powershell 73 | # ^ meta.requires.powershell keyword.control.requires.powershell 74 | # ^^^^^^^^^ meta.requires.powershell keyword.other.powershell 75 | # ^^^^^^ meta.requires.powershell variable.parameter.powershell 76 | #Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"} 77 | # <- punctuation.definition.comment.powershell 78 | # ^ meta.requires.powershell keyword.control.requires.powershell 79 | # ^^^^^^^^ meta.requires.powershell keyword.other.powershell 80 | # ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell 81 | # ^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell variable.other.readwrite.powershell 82 | # ^ meta.requires.powershell meta.hashtable.powershell 83 | # ^^^^^^^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell string.quoted.double.powershell 84 | # ^ meta.requires.powershell meta.hashtable.powershell punctuation.terminator.statement.powershell 85 | # ^^^^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell variable.other.readwrite.powershell 86 | # ^ meta.requires.powershell meta.hashtable.powershell 87 | # ^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell string.quoted.double.powershell 88 | 89 | throw "Do not run this file!" 90 | # <- keyword.control.powershell 91 | # ^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 92 | 93 | # Stop parsing 94 | & tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment 95 | # <- keyword.operator.other.powershell 96 | # ^^^^^^^^ support.function.powershell 97 | # ^ ^ keyword.operator.assignment.powershell 98 | # ^^^ keyword.control.powershell 99 | # ^^ ^^ ^^ ^^ ^ ^ string.unquoted.powershell 100 | 101 | # Automatic variables 102 | $_, $$, $^, $? 103 | # <- punctuation.definition.variable.powershell 104 | # <- support.variable.automatic.powershell 105 | # ^ punctuation.definition.variable.powershell 106 | # ^ support.variable.automatic.powershell 107 | # ^ punctuation.definition.variable.powershell 108 | # ^ support.variable.automatic.powershell 109 | # ^ punctuation.definition.variable.powershell 110 | # ^ support.variable.automatic.powershell 111 | $args 112 | # <- punctuation.definition.variable.powershell 113 | # ^ support.variable.automatic.powershell 114 | $error 115 | # <- punctuation.definition.variable.powershell 116 | # ^ support.constant.variable.powershell 117 | $home 118 | # <- punctuation.definition.variable.powershell 119 | # ^ support.constant.variable.powershell 120 | $foreach 121 | # <- punctuation.definition.variable.powershell 122 | # ^ support.variable.automatic.powershell 123 | 124 | # Normal variables 125 | $variable 126 | # <- punctuation.definition.variable.powershell 127 | # ^ variable.other.readwrite.powershell 128 | $script:variable 129 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 130 | # ^ storage.modifier.scope.powershell 131 | # ^ variable.other.readwrite.powershell 132 | $ENV:ComputerName 133 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 134 | # ^ support.variable.drive.powershell 135 | # ^ variable.other.readwrite.powershell 136 | ${variable} 137 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 138 | # <- punctuation.section.braces.begin.powershell 139 | # ^^^^^^^^ variable.other.readwrite.powershell 140 | # ^ punctuation.section.braces.end.powershell 141 | ${script:variable} 142 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 143 | # <- punctuation.section.braces.begin.powershell 144 | # ^ storage.modifier.scope.powershell 145 | # ^ variable.other.readwrite.powershell 146 | # ^ punctuation.section.braces.end.powershell 147 | 148 | # Variable properties should be highlighted 149 | $variable.Name 150 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 151 | # ^ variable.other.readwrite.powershell 152 | # ^^^^ variable.other.member.powershell 153 | 154 | # In double-quoted strings, only the variable should be highlighted, not the property 155 | "This is my $variable.Name!" 156 | # <- punctuation.definition.string.begin.powershell string.quoted.double.powershell 157 | # ^^^^^^^^^^ ^^^^^^^ string.quoted.double.powershell 158 | # ^ punctuation.definition.variable.powershell 159 | # ^^^^^^^^ variable.other.readwrite.powershell 160 | # ^ punctuation.definition.string.end.powershell 161 | 162 | # When used in a subexpression, both should be highlighted 163 | "This is my $($variable.Name)!" 164 | # <- punctuation.definition.string.begin.powershell string.quoted.double.powershell 165 | # ^^^^^^^^^^ ^^ string.quoted.double.powershell 166 | # ^^ punctuation.section.embedded.substatement.begin.powershell 167 | # ^ punctuation.section.embedded.substatement.end.powershell 168 | # ^^^^^^^^^^^^^^^^^ meta.embedded.substatement.powershell 169 | # ^ keyword.other.substatement.powershell 170 | # ^ punctuation.definition.variable.powershell 171 | # ^ punctuation.section.group.begin.powershell 172 | # ^ punctuation.section.group.end.powershell 173 | # ^^^^^^^^ variable.other.readwrite.powershell 174 | # ^^^^ variable.other.member.powershell 175 | # ^ punctuation.definition.string.end.powershell 176 | 177 | # $ENV:ComputerName should be highlighted 178 | "This is the name of my computer: $ENV:ComputerName" 179 | # <- punctuation.definition.string.begin.powershell string.quoted.double.powershell 180 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 181 | # ^ punctuation.definition.variable.powershell 182 | # ^^^^ support.variable.drive.powershell 183 | # ^^^^^^^^^^^^ variable.other.readwrite.powershell 184 | # ^ punctuation.definition.string.end.powershell 185 | 186 | # Here as well 187 | "This is the name of my computer: ${ENV:ComputerName}" 188 | # <- punctuation.definition.string.begin.powershell string.quoted.double.powershell 189 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ string.quoted.double.powershell 190 | # ^ punctuation.definition.variable.powershell 191 | # ^ punctuation.section.braces.begin.powershell 192 | # ^^^^ support.variable.drive.powershell 193 | # ^^^^^^^^^^^^ variable.other.readwrite.powershell 194 | # ^ punctuation.definition.string.end.powershell 195 | 196 | # @splat references only work in argument mode, should not highlight in strings 197 | "This is a @double quoted string." 198 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 199 | # ^ not:punctuation.definition.variable.powershell 200 | # ^ not:variable.other.readwrite.powershell 201 | 202 | # double check scopes for automatic variables in strings 203 | "$_ $$ $Pwd" 204 | # ^ support.variable.automatic.powershell 205 | # ^ support.variable.automatic.powershell 206 | # ^ support.variable.automatic.powershell 207 | 208 | # Single quotes string 209 | 'This is a string' 210 | # <- punctuation.definition.string.begin.powershell string.quoted.single.powershell 211 | # ^^^^^^^^^^^^^^^ string.quoted.single.powershell 212 | # ^ punctuation.definition.string.end.powershell 213 | 214 | # Hashtable 215 | $properties = @{ 216 | # <- punctuation.definition.variable.powershell 217 | # ^ variable.other.readwrite.powershell 218 | # ^ keyword.operator.assignment.powershell 219 | # ^ keyword.other.hashtable.begin.powershell 220 | # ^ punctuation.section.braces.begin.powershell 221 | Name = 'Name' 222 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 223 | # ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell 224 | # ^ meta.hashtable.powershell string.quoted.single.powershell 225 | Something = $else 226 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 227 | # Atom-grammar-test is not tokenizing this correctly... Need to test in Atom - TODO 228 | Number = 16 229 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 230 | # ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell 231 | # ^^ meta.hashtable.powershell constant.numeric.integer.powershell 232 | from = 'hello world' 233 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 234 | # ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell 235 | # ^^^^^^^^^^^^^ meta.hashtable.powershell string.quoted.single.powershell 236 | hash = @{ 237 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 238 | # ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell 239 | # ^ keyword.other.hashtable.begin.powershell 240 | # ^ punctuation.section.braces.begin.powershell 241 | hello = 'world' 242 | # <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell 243 | # ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell 244 | # ^^^^^^^ meta.hashtable.powershell string.quoted.single.powershell 245 | } 246 | # <- punctuation.section.braces.end.powershell 247 | } 248 | # <- punctuation.section.braces.end.powershell 249 | 250 | # Spatting 251 | Invoke-Something @properties 252 | # ^^^^^^^^^^^^^^^^ support.function.powershell 253 | # ^ punctuation.definition.variable.powershell 254 | # ^ variable.other.readwrite.powershell 255 | 256 | # ScriptBlock 257 | {Invoke-Something @properties} 258 | # ^ punctuation.section.braces.begin.powershell 259 | # ^^^^^^^^^^^^^^^^ support.function.powershell 260 | # ^ punctuation.definition.variable.powershell 261 | # ^ variable.other.readwrite.powershell 262 | # ^ punctuation.section.braces.end.powershell 263 | { 264 | # <- punctuation.section.braces.begin.powershell 265 | Invoke-Something @properties 266 | # ^^^^^^^^^^^^^^^^ support.function.powershell 267 | # ^ punctuation.definition.variable.powershell 268 | # ^ variable.other.readwrite.powershell 269 | } 270 | # <- punctuation.section.braces.end.powershell 271 | $sb = { 272 | # <- punctuation.definition.variable.powershell 273 | # ^ variable.other.readwrite.powershell 274 | # ^ keyword.operator.assignment.powershell 275 | # ^ punctuation.section.braces.begin.powershell 276 | Invoke-Something @properties 277 | # ^^^^^^^^^^^^^^^^ support.function.powershell 278 | # ^ punctuation.definition.variable.powershell 279 | # ^ variable.other.readwrite.powershell 280 | } 281 | # <- punctuation.section.braces.end.powershell 282 | 283 | # Arrays 284 | $a1 = @(1,2,3,4) 285 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 286 | # ^ variable.other.readwrite.powershell 287 | # ^ keyword.operator.assignment.powershell 288 | # ^ keyword.other.array.begin.powershell 289 | # ^ punctuation.section.group.begin.powershell 290 | # ^ punctuation.section.group.end.powershell 291 | # ^ ^ ^ ^ meta.group.array-expression.powershell constant.numeric.integer.powershell 292 | # ^ ^ ^ meta.group.array-expression.powershell keyword.operator.other.powershell 293 | $a2 = ('one','two','three','four') 294 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 295 | # ^ variable.other.readwrite.powershell 296 | # ^ keyword.operator.assignment.powershell 297 | # ^ punctuation.section.group.begin.powershell 298 | # ^^^^^ ^^^^^ ^^^^^^^ ^^^^^^ string.quoted.single.powershell 299 | # ^ ^ ^ keyword.operator.other.powershell 300 | # ^ punctuation.section.group.end.powershell 301 | $a3 = $one, $two, $three, $four 302 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 303 | # ^ ^ ^ ^ punctuation.definition.variable.powershell 304 | # ^ ^ ^ ^ ^ variable.other.readwrite.powershell 305 | # ^ keyword.operator.assignment.powershell 306 | # ^ ^ ^ keyword.operator.other.powershell 307 | $a1[0] 308 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 309 | # ^ variable.other.readwrite.powershell 310 | # ^ punctuation.section.bracket.begin.powershell 311 | # ^ constant.numeric.integer.powershell 312 | # ^ punctuation.section.bracket.end.powershell 313 | $a2[-1] 314 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 315 | # ^ variable.other.readwrite.powershell 316 | # ^ punctuation.section.bracket.begin.powershell 317 | # ^^ constant.numeric.integer.powershell 318 | # ^ punctuation.section.bracket.end.powershell 319 | $a3[1..2] 320 | # <- punctuation.definition.variable.powershell variable.other.readwrite.powershell 321 | # ^ variable.other.readwrite.powershell 322 | # ^ punctuation.section.bracket.begin.powershell 323 | # ^ ^ constant.numeric.integer.powershell 324 | # ^^ keyword.operator.range.powershell 325 | # ^ punctuation.section.bracket.end.powershell 326 | @(@($a)) 327 | # ^ ^ keyword.other.array.begin.powershell 328 | # ^ ^ punctuation.section.group.begin.powershell 329 | # ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell 330 | # ^ variable.other.readwrite.powershell 331 | # ^^ punctuation.section.group.end.powershell 332 | @(($i = 10); (++$j)) 333 | # ^ keyword.other.array.begin.powershell 334 | # ^^ ^ punctuation.section.group.begin.powershell 335 | # ^ ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell 336 | # ^ ^ variable.other.readwrite.powershell 337 | # ^ keyword.operator.assignment.powershell 338 | # ^^ constant.numeric.integer.powershell 339 | # ^ punctuation.terminator.statement.powershell 340 | # ^^ keyword.operator.assignment.powershell 341 | # ^ ^^ punctuation.section.group.end.powershell 342 | @($i = 10) 343 | # ^ keyword.other.array.begin.powershell 344 | # ^ punctuation.section.group.begin.powershell 345 | # ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell 346 | # ^ variable.other.readwrite.powershell 347 | # ^ keyword.operator.assignment.powershell 348 | # ^^ constant.numeric.integer.powershell 349 | # ^ punctuation.section.group.end.powershell 350 | $i[($y - 1) + $x] 351 | # ^ ^ ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell 352 | # ^ ^ ^ variable.other.readwrite.powershell 353 | # ^ punctuation.section.bracket.begin.powershell 354 | # ^ punctuation.section.group.begin.powershell 355 | # ^ ^ keyword.operator.assignment.powershell 356 | # ^ constant.numeric.integer.powershell 357 | # ^ punctuation.section.group.end.powershell 358 | # ^ punctuation.section.bracket.end.powershell 359 | 360 | # Single quoted strings 361 | 'This is a single quoted string.' 362 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell 363 | '$This is a single ''quoted'' string.' 364 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell 365 | 'This is a 366 | single quoted string.' 367 | # ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell 368 | 'This #also' 369 | # ^^^^^^^^^^^^ string.quoted.single.powershell 370 | '$(Invoke-Something)' 371 | # ^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell 372 | 'This "string" is nice.' 373 | # ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell 374 | 375 | # Double quoted strings 376 | "This is a double quoted string." 377 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 378 | "$This is a double ""quoted"" string." 379 | # ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 380 | # ^ punctuation.definition.variable.powershell support.variable.automatic.powershell 381 | # ^^^^ support.variable.automatic.powershell 382 | "This is a 383 | double quoted string." 384 | # ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 385 | "This #also" 386 | # ^^^^^^^^^^^^ string.quoted.double.powershell 387 | "$(Invoke-Something)" 388 | # ^ ^ string.quoted.double.powershell 389 | # ^^ punctuation.section.embedded.substatement.begin.powershell 390 | # ^ punctuation.section.embedded.substatement.end.powershell 391 | # ^^^^^^^^^^^^^^^^^^^ meta.embedded.substatement.powershell 392 | # ^ keyword.other.substatement.powershell 393 | # ^ punctuation.section.group.begin.powershell 394 | # ^ interpolated.complex.source.powershell support.function.powershell 395 | # ^ punctuation.section.group.end.powershell 396 | "This 'string' is nice." 397 | # ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell 398 | 399 | # Double quoted here-string, white space at end of start token allowed 400 | @" 401 | # <- string.quoted.double.heredoc.powershell 402 | # <- string.quoted.double.heredoc.powershell 403 | $This is a 'double quoted' 404 | # <- punctuation.definition.variable.powershell 405 | # ^ string.quoted.double.heredoc.powershell support.variable.automatic.powershell 406 | Isn't it ""nice""?? 407 | # ^^ not:constant.character.escape.powershell 408 | There is no @platting here! 409 | # ^ not:punctuation.definition.variable.powershell 410 | # ^ not:variable.other.readwrite.powershell 411 | "@ 412 | # <- string.quoted.double.heredoc.powershell 413 | # <- string.quoted.double.heredoc.powershell 414 | 415 | # Single quoted here-string, white space at end of start token allowed 416 | @' 417 | # <- string.quoted.single.heredoc.powershell 418 | # <- string.quoted.single.heredoc.powershell 419 | $This is a ''single quoted'' 420 | # ^^ not:constant.character.escape.powershell 421 | # <- not:punctuation.definition.variable.powershell 422 | # ^ string.quoted.single.heredoc.powershell not:support.variable.automatic.powershell 423 | Isn't it "nice"?? 424 | There is no @platting here! 425 | # ^ not:punctuation.definition.variable.powershell 426 | # ^ not:variable.other.readwrite.powershell 427 | '@ 428 | # <- string.quoted.single.heredoc.powershell 429 | # <- string.quoted.single.heredoc.powershell 430 | 431 | # Numeric constants 432 | -3 433 | # ^^ constant.numeric.integer.powershell 434 | .5 435 | # ^^ constant.numeric.integer.powershell 436 | +.5 437 | # ^^^ constant.numeric.integer.powershell 438 | 1. 439 | # ^ constant.numeric.integer.powershell 440 | # ^ source.powershell 441 | 1.d 442 | # ^^^ constant.numeric.integer.powershell 443 | 1.lGB 444 | # ^^^ constant.numeric.integer.powershell 445 | # ^^ keyword.other.powershell 446 | 1.e+12d 447 | # ^^^ ^^^ constant.numeric.integer.powershell 448 | # ^ keyword.operator.assignment.powershell 449 | 1e+12d 450 | # ^^ ^^^ constant.numeric.integer.powershell 451 | # ^ keyword.operator.assignment.powershell 452 | 1.5 453 | # ^^^ constant.numeric.integer.powershell 454 | -1.5 455 | # ^^^^ constant.numeric.integer.powershell 456 | -3 + -2 457 | # ^^ ^^ constant.numeric.integer.powershell 458 | # ^ keyword.operator.assignment.powershell 459 | -3+-2 460 | # ^^ ^^ constant.numeric.integer.powershell 461 | # ^ keyword.operator.assignment.powershell 462 | 3++2 463 | # ^ ^^ constant.numeric.integer.powershell 464 | # ^ keyword.operator.assignment.powershell 465 | +2 466 | # ^^ constant.numeric.integer.powershell 467 | -3+- 468 | # ^^ constant.numeric.integer.powershell 469 | # ^^ keyword.operator.assignment.powershell 470 | 10/-10 471 | # ^^ ^^^ constant.numeric.integer.powershell 472 | # ^ keyword.operator.assignment.powershell 473 | 10/-10D 474 | # ^^ ^^^^ constant.numeric.integer.powershell 475 | # ^ keyword.operator.assignment.powershell 476 | -10.002L 477 | # ^^^^^^^^ constant.numeric.integer.powershell 478 | $x..5.40D 479 | # ^ punctuation.definition.variable.powershell 480 | # ^ variable.other.readwrite.powershell 481 | # ^^ keyword.operator.range.powershell 482 | # ^^^^^ constant.numeric.integer.powershell 483 | -500..-495 484 | # ^^^^ ^^^^ constant.numeric.integer.powershell 485 | # ^^ keyword.operator.range.powershell 486 | $true..3 487 | # ^ punctuation.definition.variable.powershell 488 | # ^^^^ constant.language.powershell 489 | # ^^ keyword.operator.range.powershell 490 | # ^ constant.numeric.integer.powershell 491 | -2..$null 492 | # ^^ constant.numeric.integer.powershell 493 | # ^^ keyword.operator.range.powershell 494 | # ^ punctuation.definition.variable.powershell constant.language.powershell 495 | # ^^^^ constant.language.powershell 496 | -3..3 497 | # ^^ ^ constant.numeric.integer.powershell 498 | # ^^ keyword.operator.range.powershell 499 | 1..3 500 | # ^ ^ constant.numeric.integer.powershell 501 | # ^^ keyword.operator.range.powershell 502 | 6,10,-3 503 | # ^ ^^ ^^ constant.numeric.integer.powershell 504 | # ^ ^ keyword.operator.other.powershell 505 | 0x476 506 | # ^^^^^ constant.numeric.hex.powershell 507 | +0x20 508 | # ^^^^^ constant.numeric.hex.powershell 509 | -0x20 510 | # ^^^^^ constant.numeric.hex.powershell 511 | 512 | # Types 513 | [string] 514 | # <- punctuation.section.bracket.begin.powershell 515 | # ^ storage.type.powershell 516 | # ^ punctuation.section.bracket.end.powershell 517 | [string[]] 518 | # <- punctuation.section.bracket.begin.powershell 519 | # ^ storage.type.powershell 520 | # ^ punctuation.section.bracket.begin.powershell 521 | # ^^ punctuation.section.bracket.end.powershell 522 | [int32] 523 | # <- punctuation.section.bracket.begin.powershell 524 | # ^^^^ storage.type.powershell 525 | # ^ punctuation.section.bracket.end.powershell 526 | [System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]] 527 | # <- punctuation.section.bracket.begin.powershell 528 | # ^ ^ ^ ^ ^ storage.type.powershell 529 | # ^^ ^ punctuation.section.bracket.begin.powershell 530 | # ^ ^^^ punctuation.section.bracket.end.powershell 531 | [System.Array+SZArrayEnumerator] 532 | # <- punctuation.section.bracket.begin.powershell 533 | # ^ ^ storage.type.powershell 534 | # ^ keyword.operator.assignment.powershell 535 | # ^ punctuation.section.bracket.end.powershell 536 | [int]::MinValue 537 | # <- punctuation.section.bracket.begin.powershell 538 | # ^ storage.type.powershell 539 | # ^ punctuation.section.bracket.end.powershell 540 | [System.DateTime]::Parse('2016/09/21') 541 | # <- punctuation.section.bracket.begin.powershell 542 | # ^^^^^^^^^^^^^^ storage.type.powershell 543 | # ^ punctuation.section.bracket.end.powershell 544 | # ^ punctuation.section.group.begin.powershell 545 | # ^ punctuation.section.group.end.powershell 546 | 547 | # Commands (functions) 548 | Invoke-Something -foobar 549 | # <- support.function.powershell 550 | # ^ keyword.operator.assignment.powershell 551 | Invoke-Something -foobar value 552 | # <- support.function.powershell 553 | # ^ keyword.operator.assignment.powershell 554 | Invoke-Something -foobar:$true 555 | # <- support.function.powershell 556 | # ^ keyword.operator.assignment.powershell 557 | # ^ punctuation.definition.variable.powershell 558 | # ^^^^ constant.language.powershell 559 | Invoke-Something -foobar: $true 560 | # <- support.function.powershell 561 | # ^ keyword.operator.assignment.powershell 562 | Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose 563 | # <- support.function.powershell 564 | # ^ ^ ^ ^ ^ keyword.operator.assignment.powershell 565 | # ^^ constant.numeric.integer.powershell 566 | # ^ source.powershell 567 | Invoke-Something (1..20 | Invoke-Something) -p2 'value' 568 | # <- support.function.powershell 569 | Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch 570 | # <- support.function.powershell 571 | # ^ ^ ^ keyword.operator.assignment.powershell 572 | # ^^ constant.numeric.integer.powershell 573 | # ^ keyword.operator.other.powershell 574 | # ^ support.function.powershell 575 | # ^ source.powershell 576 | Invoke-Something -p1 { 577 | # <- support.function.powershell 578 | # ^ keyword.operator.assignment.powershell 579 | # ^ punctuation.section.braces.begin.powershell 580 | Invoke-Something -foobar:$true 581 | # ^ support.function.powershell 582 | # ^ keyword.operator.assignment.powershell 583 | # ^ punctuation.definition.variable.powershell 584 | # ^^^^ constant.language.powershell 585 | } | Invoke-Something 586 | # <- punctuation.section.braces.end.powershell 587 | # ^ keyword.operator.other.powershell 588 | # ^ support.function.powershell 589 | Invoke-Something -p1 value ` 590 | # <- support.function.powershell 591 | # ^ keyword.operator.assignment.powershell 592 | # ^ keyword.operator.other.powershell 593 | -p2 14.4 ` 594 | # ^ keyword.operator.assignment.powershell 595 | # ^^^^ constant.numeric.integer.powershell 596 | # ^ keyword.operator.other.powershell 597 | -p3 $value | Invoke-Something -verbose 598 | # ^ ^ keyword.operator.assignment.powershell 599 | # ^ punctuation.definition.variable.powershell 600 | # ^ keyword.operator.other.powershell 601 | # ^^^^^^^^^^^^^^^^ support.function.powershell 602 | 603 | # Commands (Built-in variables) 604 | ls *.ps1 -recurse 605 | # ^ ^ keyword.operator.assignment.powershell 606 | 607 | # Commands (executable files) 608 | . .\scripts\myscript.ps1 -parameter 'value' 609 | # <- keyword.operator.other.powershell 610 | # ^ keyword.operator.assignment.powershell 611 | # ^^^^^^^ string.quoted.single.powershell 612 | & tool.exe 613 | # <- keyword.operator.other.powershell 614 | # ^^^^^^^^ support.function.powershell 615 | something.cmd 616 | # <- support.function.powershell 617 | øyvind.com # this should also highlight - TODO 618 | 619 | # switch 620 | switch ("fourteen") {} 621 | # <- keyword.control.powershell 622 | # ^ punctuation.section.group.begin.powershell 623 | # ^ string.quoted.double.powershell 624 | # ^ punctuation.section.group.end.powershell 625 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 626 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 627 | switch -CaseSensitive ("fourteen") {} 628 | # <- keyword.control.powershell 629 | # ^ keyword.operator.assignment.powershell 630 | # ^ punctuation.section.group.begin.powershell 631 | # ^ string.quoted.double.powershell 632 | # ^ punctuation.section.group.end.powershell 633 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 634 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 635 | switch -Regex ("fourteen") {} 636 | # <- keyword.control.powershell 637 | # ^ keyword.operator.assignment.powershell 638 | # ^ punctuation.section.group.begin.powershell 639 | # ^ string.quoted.double.powershell 640 | # ^ punctuation.section.group.end.powershell 641 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 642 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 643 | switch -Wildcard ($a) {} 644 | # <- keyword.control.powershell 645 | # ^ keyword.operator.assignment.powershell 646 | # ^ punctuation.section.group.begin.powershell 647 | # ^ punctuation.definition.variable.powershell 648 | # ^ punctuation.section.group.end.powershell 649 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 650 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 651 | switch -regex -file .\somefile.txt {} 652 | # <- keyword.control.powershell 653 | # ^ ^ keyword.operator.assignment.powershell 654 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 655 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 656 | switch (3) {} 657 | # <- keyword.control.powershell 658 | # ^ punctuation.section.group.begin.powershell 659 | # ^ constant.numeric.integer.powershell 660 | # ^ punctuation.section.group.end.powershell 661 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 662 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 663 | switch (4, 2) {} 664 | # <- keyword.control.powershell 665 | # ^ punctuation.section.group.begin.powershell 666 | # ^ ^ constant.numeric.integer.powershell 667 | # ^ keyword.operator.other.powershell 668 | # ^ punctuation.section.group.end.powershell 669 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 670 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 671 | 672 | switch -Regex -File $filePath { 673 | # <- keyword.control.powershell 674 | # ^ ^ keyword.operator.assignment.powershell 675 | # ^ punctuation.definition.variable.powershell 676 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 677 | '.' {} 678 | # ^^^ string.quoted.single.powershell 679 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 680 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 681 | default {} 682 | # ^^^^^^^ keyword.control.powershell 683 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 684 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 685 | } 686 | # <- meta.scriptblock.powershell punctuation.section.braces.end.powershell 687 | 688 | switch -Wildcard -CaseSensitive ($something) { 689 | # <- keyword.control.powershell 690 | # ^ ^ keyword.operator.assignment.powershell 691 | # ^ punctuation.section.group.begin.powershell 692 | # ^ punctuation.definition.variable.powershell 693 | # ^ variable.other.readwrite.powershell 694 | # ^ punctuation.section.group.end.powershell 695 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 696 | '.' {} 697 | # ^^^ string.quoted.single.powershell 698 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 699 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 700 | default {} 701 | # ^^^^^^^ keyword.control.powershell 702 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 703 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 704 | } 705 | # <- meta.scriptblock.powershell punctuation.section.braces.end.powershell 706 | 707 | switch ('this') { 708 | # <- keyword.control.powershell 709 | # ^ punctuation.section.group.begin.powershell 710 | # ^^^^^^ string.quoted.single.powershell 711 | # ^ punctuation.section.group.end.powershell 712 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 713 | 'this' {} 714 | # ^^^^^^ string.quoted.single.powershell 715 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 716 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 717 | default {} 718 | # ^^^^^^^ keyword.control.powershell 719 | # ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell 720 | # ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell 721 | } 722 | # <- meta.scriptblock.powershell punctuation.section.braces.end.powershell 723 | 724 | # Functions and filters 725 | functioN MyFunction{} 726 | # <- storage.type.powershell 727 | # ^^^^^^^^^^ entity.name.function.powershell 728 | # ^ punctuation.section.braces.begin.powershell 729 | # ^ punctuation.section.braces.end.powershell 730 | function My-Function {} 731 | # <- storage.type.powershell 732 | # ^^^^^^^^^^^ entity.name.function.powershell 733 | # ^ punctuation.section.braces.begin.powershell 734 | # ^ punctuation.section.braces.end.powershell 735 | Function My.Function{} 736 | # <- storage.type.powershell 737 | # ^^^^^^^^^^^ entity.name.function.powershell 738 | # ^ punctuation.section.braces.begin.powershell 739 | # ^ punctuation.section.braces.end.powershell 740 | function My-Function.Other{} 741 | # <- storage.type.powershell 742 | # ^^^^^^^^^^^^^^^^^ entity.name.function.powershell 743 | # ^ punctuation.section.braces.begin.powershell 744 | # ^ punctuation.section.braces.end.powershell 745 | function Some.other.function{} 746 | # <- storage.type.powershell 747 | # ^^^^^^^^^^^^^^^^^^^ entity.name.function.powershell 748 | # ^ punctuation.section.braces.begin.powershell 749 | # ^ punctuation.section.braces.end.powershell 750 | FUNCTION MyFunction2 {} 751 | # <- storage.type.powershell 752 | # ^^^^^^^^^^^ entity.name.function.powershell 753 | # ^ punctuation.section.braces.begin.powershell 754 | # ^ punctuation.section.braces.end.powershell 755 | function New-File { } 756 | # <- storage.type.powershell 757 | # ^^^^^^^^ entity.name.function.powershell 758 | # ^ punctuation.section.braces.begin.powershell 759 | # ^ punctuation.section.braces.end.powershell 760 | function New-File ($Name) { } 761 | # <- storage.type.powershell 762 | # ^^^^^^^^ entity.name.function.powershell 763 | # ^ punctuation.section.braces.begin.powershell 764 | # ^ punctuation.section.braces.end.powershell 765 | function NewFile($Name) { } 766 | # <- storage.type.powershell 767 | # ^^^^^^^ entity.name.function.powershell 768 | # ^ punctuation.section.group.begin.powershell 769 | # ^ punctuation.definition.variable.powershell 770 | # ^ variable.other.readwrite.powershell 771 | # ^ punctuation.section.group.end.powershell 772 | # ^ punctuation.section.braces.begin.powershell 773 | # ^ punctuation.section.braces.end.powershell 774 | filter myfilter($param) {} 775 | # <- storage.type.powershell 776 | # ^^^^^^^^ entity.name.function.powershell 777 | # ^ punctuation.section.group.begin.powershell 778 | # ^ punctuation.definition.variable.powershell 779 | # ^ variable.other.readwrite.powershell 780 | # ^ punctuation.section.group.end.powershell 781 | # ^ punctuation.section.braces.begin.powershell 782 | # ^ punctuation.section.braces.end.powershell 783 | Filter my-Filter ($param){} 784 | # <- storage.type.powershell 785 | # ^^^^^^^^^ entity.name.function.powershell 786 | # ^ punctuation.section.group.begin.powershell 787 | # ^ punctuation.definition.variable.powershell 788 | # ^ variable.other.readwrite.powershell 789 | # ^ punctuation.section.group.end.powershell 790 | # ^ punctuation.section.braces.begin.powershell 791 | # ^ punctuation.section.braces.end.powershell 792 | 793 | # Note that the # in the path should highlight as a comment! 794 | function Test-Drive([string]$roman) { 795 | # <- storage.type.powershell 796 | # ^^^^^^^^^^ entity.name.function.powershell 797 | # ^ punctuation.section.group.begin.powershell 798 | # ^ punctuation.section.bracket.begin.powershell 799 | # ^^^^^^ storage.type.powershell 800 | # ^ punctuation.section.bracket.end.powershell 801 | # ^ punctuation.definition.variable.powershell 802 | # ^ variable.other.readwrite.powershell 803 | # ^ punctuation.section.group.end.powershell 804 | # ^ punctuation.section.braces.begin.powershell 805 | $roman | c:\users\Me\Documents\Programming\F#\test.exe $roman 806 | # ^ punctuation.definition.variable.powershell 807 | # ^ variable.other.readwrite.powershell 808 | # ^ keyword.operator.other.powershell 809 | # ^ punctuation.definition.comment.powershell 810 | # ^ ^ comment.line.powershell 811 | } 812 | # <- punctuation.section.braces.end.powershell 813 | 814 | function Verb-Noun 815 | # <- meta.function storage.type 816 | # ^ meta.function entity.name.function.powershell 817 | { 818 | # <- punctuation.section.braces.begin.powershell 819 | 820 | Param 821 | # <- keyword.control.powershell 822 | ( 823 | # <- punctuation.section.group.begin.powershell 824 | # Param1 help description 825 | # <- comment.line.powershell punctuation.definition.comment.powershell 826 | # ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell 827 | [Parameter(Mandatory=$true, 828 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 829 | # ^ meta.attribute.powershell support.function.attribute.powershell 830 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 831 | # ^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 832 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 833 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 834 | # ^^^^ meta.attribute.powershell constant.language.powershell 835 | # ^ meta.attribute.powershell keyword.operator.other.powershell 836 | ValueFromPipeline=$true, 837 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 838 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 839 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 840 | # ^^^^ meta.attribute.powershell constant.language.powershell 841 | # ^ meta.attribute.powershell keyword.operator.other.powershell 842 | ValueFromPipelineByPropertyName = $true, 843 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 844 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 845 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 846 | # ^^^^ meta.attribute.powershell constant.language.powershell 847 | # ^ meta.attribute.powershell keyword.operator.other.powershell 848 | ValueFromRemainingArguments=$false, 849 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 850 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 851 | # ^ meta.attribute.powershell punctuation.definition.variable.powershell 852 | # ^^^^^ meta.attribute.powershell constant.language.powershell 853 | # ^ meta.attribute.powershell keyword.operator.other.powershell 854 | Position=0, 855 | # ^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 856 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 857 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 858 | # ^ meta.attribute.powershell keyword.operator.other.powershell 859 | SupportsPaging, 860 | # ^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 861 | # ^ meta.attribute.powershell keyword.operator.other.powershell 862 | ParameterSetName = 'Parameter Set 1')] 863 | # ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell 864 | # ^ meta.attribute.powershell keyword.operator.assignment.powershell 865 | # ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell 866 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 867 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 868 | [ValidateNotNullOrEmpty()] 869 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 870 | # ^ meta.attribute.powershell support.function.attribute.powershell 871 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 872 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 873 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 874 | [ValidateNotNull()] 875 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 876 | # ^ meta.attribute.powershell support.function.attribute.powershell 877 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 878 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 879 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 880 | [ValidateNotNullOrEmpty()] 881 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 882 | # ^ meta.attribute.powershell support.function.attribute.powershell 883 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 884 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 885 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 886 | [ValidateCount(0,5)] 887 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 888 | # ^ meta.attribute.powershell support.function.attribute.powershell 889 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 890 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 891 | # ^ meta.attribute.powershell keyword.operator.other.powershell 892 | # ^ meta.attribute.powershell constant.numeric.integer.powershell 893 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 894 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 895 | [ValidateSet("sun", "moon", "earth")] 896 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 897 | # ^ meta.attribute.powershell support.function.attribute.powershell 898 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 899 | # ^^^^ meta.attribute.powershell string.quoted.double.powershell 900 | # ^ meta.attribute.powershell keyword.operator.other.powershell 901 | # ^^^^^^ meta.attribute.powershell string.quoted.double.powershell 902 | # ^ meta.attribute.powershell keyword.operator.other.powershell 903 | # ^^^^^^^ meta.attribute.powershell string.quoted.double.powershell 904 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 905 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 906 | [Alias("p1")] 907 | # <- meta.attribute.powershell punctuation.section.bracket.begin.powershell 908 | # ^ meta.attribute.powershell support.function.attribute.powershell 909 | # ^ meta.attribute.powershell punctuation.section.group.begin.powershell 910 | # ^^^^ meta.attribute.powershell string.quoted.double.powershell 911 | # ^ meta.attribute.powershell punctuation.section.group.end.powershell 912 | # ^ meta.attribute.powershell punctuation.section.bracket.end.powershell 913 | $Param1 914 | # <- punctuation.definition.variable.powershell 915 | # ^ variable.other.readwrite.powershell 916 | ) 917 | # <- punctuation.section.group.end.powershell 918 | 919 | # Do Something.... 920 | 921 | } 922 | # <- punctuation.section.braces.end.powershell 923 | 924 | # Class 925 | class Vehicle { 926 | # <- storage.type.powershell 927 | # ^ entity.name.function.powershell 928 | # ^ punctuation.section.braces.begin.powershell 929 | Vehicle() {} 930 | # ^ punctuation.section.group.begin.powershell 931 | # ^ punctuation.section.group.end.powershell 932 | # ^ punctuation.section.braces.begin.powershell 933 | # ^ punctuation.section.braces.end.powershell 934 | Vehicle([string]$Owner) { 935 | # ^ storage.type.powershell 936 | # ^ punctuation.definition.variable.powershell 937 | # ^ variable.other.readwrite.powershell 938 | # ^ punctuation.section.braces.begin.powershell 939 | $this.Owner = $Owner 940 | } 941 | 942 | [int]$Mileage 943 | # ^ storage.type.powershell 944 | # ^ punctuation.definition.variable.powershell 945 | # ^ variable.other.readwrite.powershell 946 | [int]$Age 947 | # ^ storage.type.powershell 948 | # ^ punctuation.definition.variable.powershell 949 | # ^ variable.other.readwrite.powershell 950 | [string]$Owner 951 | # ^ storage.type.powershell 952 | # ^ punctuation.definition.variable.powershell 953 | # ^ variable.other.readwrite.powershell 954 | 955 | [void]Drive([int]$NumberOfMiles) { 956 | # ^ ^ storage.type.powershell 957 | # ^ punctuation.definition.variable.powershell 958 | # ^ variable.other.readwrite.powershell 959 | $this.Mileage += $NumberOfMiles 960 | # ^ punctuation.definition.variable.powershell 961 | # ^^^^ support.variable.automatic.powershell 962 | # ^ variable.other.member.powershell 963 | # ^^ keyword.operator.assignment.powershell 964 | 965 | } 966 | # <- punctuation.section.braces.end.powershell 967 | } 968 | # <- punctuation.section.braces.end.powershell 969 | 970 | # Control words 971 | foreach ($item in $collection) { 972 | # <- keyword.control.powershell 973 | # ^ punctuation.section.group.begin.powershell 974 | # ^^ keyword.control.powershell 975 | # ^ punctuation.section.group.end.powershell 976 | # ^ punctuation.section.braces.begin.powershell 977 | # ^ ^ punctuation.definition.variable.powershell 978 | } 979 | # <- punctuation.section.braces.end.powershell 980 | 981 | try { } 982 | # <- keyword.control.powershell 983 | # ^ punctuation.section.braces.begin.powershell 984 | # ^ punctuation.section.braces.end.powershell 985 | catch { } 986 | # <- keyword.control.powershell 987 | # ^ punctuation.section.braces.begin.powershell 988 | # ^ punctuation.section.braces.end.powershell 989 | 990 | # Reserved words 991 | Configuration Crazyness { 992 | # <- storage.type.powershell 993 | # ^ entity.name.function.powershell 994 | # ^ punctuation.section.braces.begin.powershell 995 | Node Whatever { 996 | # ^ punctuation.section.braces.begin.powershell 997 | } 998 | # <- punctuation.section.braces.end.powershell 999 | } 1000 | # <- punctuation.section.braces.end.powershell 1001 | 1002 | # Redirection 1003 | notepad.exe > log.txt 1004 | # <- support.function.powershell 1005 | # ^ keyword.operator.redirection.powershell 1006 | notepad.exe 1> log.txt 1007 | # <- support.function.powershell 1008 | # ^^ keyword.operator.redirection.powershell 1009 | notepad.exe 2>&1 1010 | # <- support.function.powershell 1011 | # ^^^^ keyword.operator.redirection.powershell 1012 | notepad.exe 3>&1 1013 | # <- support.function.powershell 1014 | # ^^^^ keyword.operator.redirection.powershell 1015 | notepad.exe 4>&1 1016 | # <- support.function.powershell 1017 | # ^^^^ keyword.operator.redirection.powershell 1018 | notepad.exe 5>&1 1019 | # <- support.function.powershell 1020 | # ^^^^ keyword.operator.redirection.powershell 1021 | notepad.exe 6>&1 1022 | # <- support.function.powershell 1023 | # ^^^^ keyword.operator.redirection.powershell 1024 | notepad.exe 2>&1> log.txt 1025 | # <- support.function.powershell 1026 | # ^^^^^ keyword.operator.redirection.powershell 1027 | 1028 | # Operators 1029 | if (10 -cgt 100) { } 1030 | # <- keyword.control.powershell 1031 | # ^ punctuation.section.group.begin.powershell 1032 | # ^^ ^^^ constant.numeric.integer.powershell 1033 | # ^^^^ keyword.operator.comparison.powershell 1034 | # ^ punctuation.section.group.end.powershell 1035 | # ^ punctuation.section.braces.begin.powershell 1036 | # ^ punctuation.section.braces.end.powershell 1037 | $a -is $b 1038 | # ^ keyword.operator.comparison.powershell 1039 | $b -contains $c 1040 | # ^ keyword.operator.comparison.powershell 1041 | $x -notcontains $c 1042 | # ^ keyword.operator.comparison.powershell 1043 | $c -in $b 1044 | # ^ keyword.operator.comparison.powershell 1045 | $c -notin $x 1046 | # ^ keyword.operator.comparison.powershell 1047 | $a -match $b 1048 | # ^ keyword.operator.comparison.powershell 1049 | $a -notmatch $b 1050 | # ^ keyword.operator.comparison.powershell 1051 | $x -like $c 1052 | # ^ keyword.operator.comparison.powershell 1053 | 100 -and 0 1054 | # ^ keyword.operator.logical.powershell 1055 | # ^ constant.numeric.integer.powershell 1056 | $a -ceq 4 -and $a -ine $d -or 1057 | # ^ ^ keyword.operator.comparison.powershell 1058 | # ^ ^ keyword.operator.logical.powershell 1059 | # ^ constant.numeric.integer.powershell 1060 | # ^ punctuation.definition.variable.powershell 1061 | $c -is [Type] 1062 | # ^ keyword.operator.comparison.powershell 1063 | # ^ storage.type.powershell 1064 | $c -isnot [Type] 1065 | # ^ keyword.operator.comparison.powershell 1066 | # ^ storage.type.powershell 1067 | $c -as [Type] 1068 | # ^ keyword.operator.comparison.powershell 1069 | # ^ storage.type.powershell 1070 | $k = $y -bor $k 1071 | # ^ keyword.operator.assignment.powershell 1072 | # ^ keyword.operator.bitwise.powershell 1073 | $x = $y -band $x 1074 | # ^ keyword.operator.assignment.powershell 1075 | # ^ keyword.operator.bitwise.powershell 1076 | $z = -bnot $x 1077 | # ^ keyword.operator.assignment.powershell 1078 | # ^ keyword.operator.bitwise.powershell 1079 | $l = 1 -shl 10 1080 | # ^ keyword.operator.assignment.powershell 1081 | # ^ ^^ constant.numeric.integer.powershell 1082 | # ^ keyword.operator.bitwise.powershell 1083 | $r = 10 -shr 1 1084 | # ^ keyword.operator.assignment.powershell 1085 | # ^^ ^ constant.numeric.integer.powershell 1086 | # ^ keyword.operator.bitwise.powershell 1087 | $k = $y -xor $b 1088 | # ^ keyword.operator.assignment.powershell 1089 | # ^ keyword.operator.logical.powershell 1090 | $k = $y -bxor $b 1091 | # ^ keyword.operator.assignment.powershell 1092 | # ^ keyword.operator.bitwise.powershell 1093 | $a -icontains $c 1094 | # ^ keyword.operator.comparison.powershell 1095 | $a -ccontains $c 1096 | # ^ keyword.operator.comparison.powershell 1097 | $a -iNotContains $c 1098 | # ^ keyword.operator.comparison.powershell 1099 | $a -cNotContains $c 1100 | # ^ keyword.operator.comparison.powershell 1101 | $a -cmatch $c 1102 | # ^ keyword.operator.comparison.powershell 1103 | $x -iMatch $c 1104 | # ^ keyword.operator.comparison.powershell 1105 | $x -iNotMatch $c 1106 | # ^ keyword.operator.comparison.powershell 1107 | $a -iLike $b 1108 | # ^ keyword.operator.comparison.powershell 1109 | $b -cLike $c 1110 | # ^ keyword.operator.comparison.powershell 1111 | "hey" -cgt "Hey" 1112 | # ^ keyword.operator.comparison.powershell 1113 | "Hey" -igt "hey" 1114 | # ^ keyword.operator.comparison.powershell 1115 | "hey" -cge "Hey" 1116 | # ^ keyword.operator.comparison.powershell 1117 | "Hey" -ige "hey" 1118 | # ^ keyword.operator.comparison.powershell 1119 | "HEY" -clt "hey" 1120 | # ^ keyword.operator.comparison.powershell 1121 | "HEY" -ilt "hey" 1122 | # ^ keyword.operator.comparison.powershell 1123 | "HEY" -cle "hey" 1124 | # ^ keyword.operator.comparison.powershell 1125 | "HEY" -ile "hey" 1126 | # ^ keyword.operator.comparison.powershell 1127 | 1128 | # format 1129 | "{0:N2}" -f $a 1130 | # ^^^^^^^^ string.quoted.double.powershell 1131 | # ^ keyword.operator.string-format.powershell 1132 | "{0:D8}" -f $a 1133 | # ^^^^^^^^ string.quoted.double.powershell 1134 | # ^ keyword.operator.string-format.powershell 1135 | "{0:C2}" -f $a 1136 | # ^^^^^^^^ string.quoted.double.powershell 1137 | # ^ keyword.operator.string-format.powershell 1138 | "{0:P0}" -f $a 1139 | # ^^^^^^^^ string.quoted.double.powershell 1140 | # ^ keyword.operator.string-format.powershell 1141 | "{0:X0}" -f $a 1142 | # ^^^^^^^^ string.quoted.double.powershell 1143 | # ^ keyword.operator.string-format.powershell 1144 | (1.11).ToString("#.#") 1145 | # ^ ^ punctuation.section.group.begin.powershell 1146 | # ^^^^ constant.numeric.integer.powershell 1147 | # ^ string.quoted.double.powershell 1148 | "{1,10} {0,10} {2,10:x}" -f "First", "Second", 255 1149 | # ^ ^ ^ string.quoted.double.powershell 1150 | # ^ keyword.operator.string-format.powershell 1151 | # ^^^ constant.numeric.integer.powershell 1152 | ("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9) 1153 | # ^ string.quoted.double.powershell 1154 | # ^ ^ keyword.operator.string-format.powershell 1155 | "{0:R}" -f (1mb/2.0) 1156 | # ^^ keyword.other.powershell 1157 | # ^ keyword.operator.string-format.powershell 1158 | "{0:00.0}" -f 4.12341234 1159 | # ^ keyword.operator.string-format.powershell 1160 | "{0:##.#}" -f 4.12341234 1161 | # ^ string.quoted.double.powershell 1162 | # ^ keyword.operator.string-format.powershell 1163 | "{0:#,#.#}" -f 1234.121234 1164 | # ^ string.quoted.double.powershell 1165 | # ^ keyword.operator.string-format.powershell 1166 | "{0:##,,.000}" -f 1048576 1167 | # ^ string.quoted.double.powershell 1168 | # ^ keyword.operator.string-format.powershell 1169 | "{this is not a #comment}" 1170 | # ^ not:comment 1171 | "{0:##.#E000}" -f 2.71828 1172 | # ^ string.quoted.double.powershell 1173 | # ^ keyword.operator.string-format.powershell 1174 | "{0:#.00'##'}" -f 2.71828 1175 | # ^ string.quoted.double.powershell 1176 | # ^ keyword.operator.string-format.powershell 1177 | "{0:POS;NEG;ZERO}" -f -14 1178 | # ^ string.quoted.double.powershell 1179 | # ^ keyword.operator.string-format.powershell 1180 | "{0:$## Please}" -f 14 1181 | # ^ string.quoted.double.powershell 1182 | # ^ keyword.operator.string-format.powershell 1183 | "{0,-8:P1}" -f 1.75 1184 | # ^ string.quoted.double.powershell 1185 | # ^ keyword.operator.string-format.powershell 1186 | "{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91 1187 | # ^ keyword.operator.string-format.powershell 1188 | '{0:00000.000}' -f 7.125 1189 | # ^ string.quoted.single.powershell 1190 | # ^ keyword.operator.string-format.powershell 1191 | 1192 | # Misc test cases 1193 | Test-Function -Class ClassName 1194 | # ^ not:storage.type.powershell 1195 | New-Object -TypeName System.Diagnostics.Process 1196 | # ^ not:keyword.control.powershell 1197 | New-Object -TypeName System.Data 1198 | # ^ not:keyword.control.powershell 1199 | @("any","array","has").foreach({ $_ }) 1200 | # <- keyword.other.array.begin.powershell 1201 | # ^ meta.group.array-expression.powershell 1202 | # ^ keyword.control.powershell 1203 | # ^ meta.scriptblock.powershell 1204 | @('any','array','has').foreach{ $_ } 1205 | # <- keyword.other.array.begin.powershell 1206 | # ^ meta.group.array-expression.powershell 1207 | # ^ keyword.control.powershell 1208 | # ^ meta.scriptblock.powershell 1209 | @("any","array","has").where({ $_.Length -gt 3 }) 1210 | # <- keyword.other.array.begin.powershell 1211 | # ^ meta.group.array-expression.powershell 1212 | # ^ keyword.control.powershell 1213 | # ^ meta.scriptblock.powershell 1214 | @("any","array","has").where{ $_.Length -gt 3 } 1215 | # <- keyword.other.array.begin.powershell 1216 | # ^ meta.group.array-expression.powershell 1217 | # ^ keyword.control.powershell 1218 | # ^ meta.scriptblock.powershell 1219 | $file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1" 1220 | # <- punctuation.definition.variable.powershell 1221 | # ^ support.function.powershell 1222 | # ^ support.variable.drive.powershell 1223 | # ^ variable.other.readwrite.powershell 1224 | # ^ string.quoted.double.powershell punctuation.definition.substatement.powershell punctuation.section.embedded.substatement.begin.powershell 1225 | # ^ storage.type.powershell 1226 | $ScriptBlock | Out-File $file -Force 1227 | # <- punctuation.definition.variable.powershell 1228 | # ^ keyword.operator.other.powershell 1229 | # ^ punctuation.definition.variable.powershell 1230 | # ^ keyword.operator.assignment.powershell 1231 | workflow w1 {} 1232 | # <- storage.type.powershell 1233 | # ^ entity.name.function.powershell 1234 | # ^ punctuation.section.braces.begin.powershell 1235 | # ^ punctuation.section.braces.end.powershell 1236 | Workflow work { sequence {} } 1237 | # <- storage.type.powershell 1238 | # ^ entity.name.function.powershell 1239 | # ^ punctuation.section.braces.begin.powershell 1240 | # ^^^^^^^^ keyword.control.powershell 1241 | # ^ punctuation.section.braces.begin.powershell 1242 | # ^ punctuation.section.braces.end.powershell 1243 | # ^ punctuation.section.braces.end.powershell 1244 | get-thing | Out-WithYou > $null # destroy 1245 | # ^ ^ support.function.powershell 1246 | # ^ keyword.operator.other.powershell 1247 | # ^ keyword.operator.redirection.powershell 1248 | # ^ punctuation.definition.variable.powershell 1249 | # ^ constant.language.powershell 1250 | # ^ punctuation.definition.comment.powershell 1251 | "Escaped chars: `", `n, `$, `b, `t, `e, `u{10ffff}, `"" 1252 | # <- string.quoted.double.powershell 1253 | # ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ ^^ string.quoted.double.powershell constant.character.escape.powershell 1254 | 'But here they''re not escape chars: `", `n, `$, `b, `"' 1255 | # ^^ constant.character.escape.powershell 1256 | # ^^ ^^ ^^ ^^ ^^ not:constant.character.escape.powershell 1257 | "When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )" 1258 | # ^ string.quoted.double.powershell punctuation.definition.substatement.powershell punctuation.section.embedded.substatement.begin.powershell 1259 | # ^ punctuation.definition.variable.powershell 1260 | # ^ keyword.operator.other.powershell 1261 | # ^ ^ meta.group.complex.subexpression.powershell punctuation.section.group.begin.powershell 1262 | # ^ storage.type.powershell 1263 | # ^ ^ meta.group.complex.subexpression.powershell punctuation.section.group.end.powershell 1264 | "This is the Debugreference variable: $DebugPreference" 1265 | # <- string.quoted.double.powershell 1266 | # ^ variable.language.powershell 1267 | 1268 | $ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName $PSSessionConfigurationName $PSSessionOption $ProgressPreference $VerbosePreference $WarningPreference $WhatIfPreference 1269 | # <- variable.language.powershell 1270 | # ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell 1271 | # ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell 1272 | # ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell 1273 | -------------------------------------------------------------------------------- /tools/banners.ps1: -------------------------------------------------------------------------------- 1 | function SyntaxBanner { 2 | Write-Host ' ______ _ _ _ _____ _ ' -ForegroundColor Green 3 | Write-Host '| ____| | (_) | / ____| | | ' -ForegroundColor Green 4 | Write-Host '| |__ __| |_| |_ ___ _ _| (___ _ _ _ __ | |_ __ ___ __' -ForegroundColor Green 5 | Write-Host '| __| / _` | | __/ _ \| ''__\___ \| | | | ''_ \| __/ _` \ \/ /' -ForegroundColor Green 6 | Write-Host '| |___| (_| | | || (_) | | ____) | |_| | | | | || (_| |> < ' -ForegroundColor Green 7 | Write-Host '|______\__,_|_|\__\___/|_| |_____/ \__, |_| |_|\__\__,_/_/\_\' -ForegroundColor Green 8 | Write-Host ' __/ | ' -ForegroundColor Green 9 | Write-Host ' |___/ ' -ForegroundColor Green 10 | } 11 | 12 | function BuildBanner { 13 | Write-Host '#############################################################' -ForegroundColor Green 14 | Write-Host '# BUILD GRAMMAR #' -ForegroundColor Green 15 | Write-Host '#############################################################' -ForegroundColor Green 16 | } 17 | 18 | function TestBanner { 19 | Write-Host '#############################################################' -ForegroundColor Green 20 | Write-Host '# RUN TESTS #' -ForegroundColor Green 21 | Write-Host '#############################################################' -ForegroundColor Green 22 | } 23 | 24 | function EndBanner { 25 | Write-Host '#############################################################' -ForegroundColor Green 26 | } 27 | -------------------------------------------------------------------------------- /tools/build-grammar.js: -------------------------------------------------------------------------------- 1 | /*--------------------------------------------------------------------------------------------- 2 | * Licensed under the MIT License. See License.txt in the project root for license information. 3 | * 4 | * Modified for PowerShell\EditorSyntax from Microsoft\vscode (update-grammar.js) 5 | * This script generates the JSON file using the same tools as vscode's build. 6 | *--------------------------------------------------------------------------------------------*/ 7 | 8 | 'use strict'; 9 | 10 | var path = require('path'); 11 | var fs = require('fs'); 12 | var plist = require('fast-plist'); 13 | 14 | exports.update = function (tmlPath, dest) { 15 | console.log('... Reading source file.'); 16 | var content = fs.readFileSync(tmlPath).toString(); 17 | 18 | console.log('... Parsing content.'); 19 | var grammar; 20 | grammar = plist.parse(content); 21 | 22 | console.log('... Building contents.'); 23 | let result = { 24 | information_for_contributors: [ 25 | 'This file has been converted from source and may not be in line with the official build.', 26 | 'The current master branch for this syntax can be found here: https://github.com/PowerShell/EditorSyntax', 27 | 'If you want to provide a fix or improvement, please create a pull request against the original repository.' 28 | ] 29 | }; 30 | 31 | result.version = require('child_process') 32 | .execSync('git rev-parse HEAD') 33 | .toString().trim() 34 | 35 | let keys = ['name', 'scopeName', 'comment', 'injections', 'patterns', 'repository']; 36 | for (let key of keys) { 37 | if (grammar.hasOwnProperty(key)) { 38 | result[key] = grammar[key]; 39 | } 40 | } 41 | 42 | var dirname = path.dirname(dest); 43 | if (!fs.existsSync(dirname)) { 44 | console.log('... Creating directory: ' + dirname); 45 | fs.mkdirSync(dirname); 46 | } 47 | 48 | fs.writeFileSync(dest, JSON.stringify(result, null, '\t')); 49 | console.log('[Finished] File written to: ' + dest); 50 | }; 51 | 52 | if (path.basename(process.argv[1]) === 'build-grammar.js') { 53 | console.log('[Starting] Converting ' + process.argv[2] + ' to json.'); 54 | exports.update(process.argv[2], process.argv[3]); 55 | } 56 | -------------------------------------------------------------------------------- /tools/build-helpers.ps1: -------------------------------------------------------------------------------- 1 | function DownloadAtom { 2 | Write-Host "Downloading latest Atom release..." 3 | 4 | $Source = "https://atom.io/download/windows_zip?channel=stable" 5 | $Destination = Join-Path . '\atom.zip' 6 | 7 | try { 8 | Invoke-WebRequest $Source -OutFile $Destination -ErrorAction Stop 9 | } 10 | catch { 11 | $PSCmdlet.ThrowTerminatingError($PSItem) 12 | } 13 | 14 | Write-Host "Atom download finished..." 15 | 16 | ExtractAtom 17 | } 18 | 19 | function ExtractAtom { 20 | Write-Host "Extracting Atom.zip" 21 | 22 | $ZipFile = Join-Path (Split-Path $PSScriptRoot -Parent) '\atom.zip' 23 | $OutPath = Resolve-Path . 24 | 25 | try { 26 | Add-Type -AssemblyName System.IO.Compression.FileSystem 27 | [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile, $OutPath) 28 | } 29 | catch { 30 | $PSCmdlet.ThrowTerminatingError($PSItem) 31 | } 32 | 33 | Write-Host "Atom extracted..." 34 | 35 | Remove-Item $ZipFile -Force 36 | 37 | Write-Host "Atom.zip deleted..." 38 | } 39 | 40 | filter ParseJasmine { 41 | switch -regex ($_) { 42 | ^\s+at { 43 | '' 44 | break 45 | } 46 | 47 | ^\s+it { 48 | $_ -replace '^(\s+)(it)', '$1[-] It' 49 | break 50 | } 51 | 52 | ^\s+Expected { 53 | $_ -replace '^(\s*)(Expected.*?)\s(instead found .*)', "`$1`$2`n`$1`$3" 54 | break 55 | } 56 | 57 | default { 58 | $_ 59 | } 60 | } 61 | } 62 | 63 | function ExitWithCode { 64 | param ( 65 | $ExitCode 66 | ) 67 | 68 | $Host.SetShouldExit($exitcode) 69 | exit 70 | } 71 | 72 | function RunSpecs { 73 | Write-Host "Running specs..." 74 | 75 | $specpath = Join-Path . '\spec' 76 | 77 | if (Test-Path $specpath) { 78 | & $script:ATOM_EXE_PATH --test $specpath *>&1 | ParseJasmine 79 | } 80 | else { 81 | throw '.\spec\ not found.' 82 | } 83 | 84 | if ($LASTEXITCODE -ne 0) { 85 | if ($Env:APPVEYOR) { 86 | ExitWithCode -exitcode $LASTEXITCODE 87 | } 88 | else { 89 | throw "One or more tests failed." 90 | } 91 | } 92 | } 93 | --------------------------------------------------------------------------------