Repository: PowerShell/EditorSyntax
Branch: main
Commit: 23eed76d483c
Files: 23
Total size: 196.2 KB
Directory structure:
gitextract_m3_u_wem/
├── .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.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
================================================
FILE CONTENTS
================================================
================================================
FILE: .github/CODE_OF_CONDUCT.md
================================================
# Microsoft Open Source Code of Conduct
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
Resources:
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support)
================================================
FILE: .github/SECURITY.md
================================================
## Security
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).
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.
## Reporting Security Issues
**Please do not report security vulnerabilities through public GitHub issues.**
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).
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).
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).
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:
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue
This information will help us triage your report more quickly.
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.
## Preferred Languages
We prefer all communications to be in English.
## Policy
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
================================================
FILE: .gitignore
================================================
syntaxes/
grammars/
node_modules/
atom/
atom.zip
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing
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.
## Get started
There are a number of ways you can get your feet wet and help us out.
* [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!
* [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.
### Open an issue
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!
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/)
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.
### Fix an issue
Ready to go deeper and fix an existing issue?
1. Leave a comment to tell us that you are working on it so work isn't duplicated by multiple contributors.
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").
1. [Fix the issue](https://knowyourmeme.com/memes/how-to-draw-an-owl) in your fork.
1. Include a [test spec](spec/testfiles) to prevent regressions in the future.
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.
1. If prompted to sign the CLA, please follow the steps provided.
See the [Contributing Guide](#contributing-guide) for a detailed step-by-step guide.
#### Helpful tools/links
* [TextMate Language Grammars Documentation](https://macromates.com/manual/en/language_grammars)
* [Regular Expressions 101](https://regex101.com/) - Online regex tester, debugger with highlighting for PHP, PCRE, Python, Golang and JavaScript.
* [RegExr](https://regexr.com/) - Regular expression tester with syntax highlighting, PHP / PCRE & JS Support, contextual help, cheat sheet, reference, and searchable community patterns.
* [Understanding XML Property Lists](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/PropertyLists/UnderstandXMLPlist/UnderstandXMLPlist.html#//apple_ref/doc/uid/10000048i-CH6-SW1)
## Reviews
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.
* Changes to the grammar file or continuous integration process should have the approval of two people before being merged.
# Contributing Guide
Below is a step by step guide for making changes to the grammar file.
## On scopes
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.
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:
* `comment.line.powershell`
* `comment.block.powershell`
* `comment.documentation.powershell`
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`.)
See: [Introduction to scopes](https://macromates.com/blog/2005/introduction-to-scopes/) for more details.
### Scope selection
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:
* **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.)
* **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.
* **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.
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)
## Fork the repository and create a branch
Once you're ready to contribute changes to the project you will want to create your own copy to work from.
1. Open the [EditorSyntax](https://github.com/PowerShell/EditorSyntax/) project in a browser.
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.
1. Clone your fork to your computer using the Git command line: `git clone https://github.com/YOUR-USER-NAME/EditorSyntax.git`
1. Navigate into your clone: `cd EditorSyntax`
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.)
## Edit the grammar file
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.
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.
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:
```XML
match
(?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w)
name
keyword.control.powershell
```
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.)
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.
## Test locally
In order to test your changes you will need a JSON version of the grammar file.
1. From the command line run `.\build.ps1` without parameters to generate the JSON from the .tmLanguage file in `.\grammars\powershell.tmLanguage.json`.
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/):
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`.
1. Rename `powershell.tmLanguage.json` in the directory to `powershell.tmLanguage.json_official` or similar.
1. Copy the JSON file you generated from `.\grammars` in the EditorSyntax folder to the `.\syntaxes` folder above.
1. Reload VS Code using the `Reload Windows` command from the command palette.
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.
## Run the automated tests
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.
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.)
1. Run the build.ps1 script with the `-Test` switch: `.\build.ps1 -Test` and you should get an output like this:
```
Running specs...
.................................................................................
Finished in 24.42 seconds
367 tests, 3524 assertions, 0 failures, 0 skipped
```
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.
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.
## Create tests and/or modify existing tests
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.
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)
This example spec:
```PowerShell
'This is a string'
# <- punctuation.definition.string.begin.powershell string.quoted.single.powershell
# ^^^^^^^^^^^^^^^ string.quoted.single.powershell
# ^ punctuation.definition.string.end.powershell
```
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.
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:
```PowerShell
'This is a string'
# <- punctuation.definition.string.begin.powershell string.quoted.single.powershell
# ^ string.quoted.single.powershell
# ^ punctuation.definition.string.end.powershell
```
is just as valid.
**Note:** your can also use `not:scope.name` to make sure something doesn't inherit a scope in a spec.
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.
## Submit your changes
When you're ready and all the tests are passing it's time to submit a pull request!
1. Commit your changes to your branch if you haven't already: `git commit -am ""`
1. Push your changes to GitHub: `git push --set-upstream origin `
1. Open the official [EditorSyntax](https://github.com/PowerShell/EditorSyntax) page in a browser.
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.
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".
1. Submit the pull request and complete the CLA if prompted.
## Updating software that uses the grammar
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.
### GitHub Linguist
* Project link: https://github.com/github/linguist
**Steps**
*Linguist is updated automatically every time they release.*
### Visual Studio Code
* Project link: https://github.com/Microsoft/vscode/
**Steps**
-Coming Soon-
### Atom
* Project link: https://github.com/atom/atom
**Steps**
-Coming Soon-
================================================
FILE: ISSUE_TEMPLATE.md
================================================
### Environment
- Editor and Version (VS Code, Atom, Sublime):
- Your primary theme:
### Issue Description
#### Screenshots
### Expected Behavior
### Code Samples
```PowerShell
```
================================================
FILE: LICENSE
================================================
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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.
================================================
FILE: PowerShellSyntax.tmLanguage
================================================
fileTypes
ps1
psm1
psd1
name
PowerShell
patterns
begin
<#
beginCaptures
0
name
punctuation.definition.comment.block.begin.powershell
end
#>
endCaptures
0
name
punctuation.definition.comment.block.end.powershell
name
comment.block.powershell
patterns
include
#commentEmbeddedDocs
match
[2-6]>&1|>>|>|<<|<|>|>\||[1-6]>|[1-6]>>
name
keyword.operator.redirection.powershell
include
#commands
include
#commentLine
include
#variable
include
#subexpression
include
#function
include
#attribute
include
#UsingDirective
include
#type
include
#hashtable
include
#doubleQuotedString
include
#scriptblock
comment
Needed to parse stuff correctly in 'argument mode'. (See about_parsing.)
include
#doubleQuotedStringEscapes
begin
['\x{2018}-\x{201B}]
beginCaptures
0
name
punctuation.definition.string.begin.powershell
end
['\x{2018}-\x{201B}]
applyEndPatternLast
endCaptures
0
name
punctuation.definition.string.end.powershell
name
string.quoted.single.powershell
patterns
match
['\x{2018}-\x{201B}]{2}
name
constant.character.escape.powershell
begin
(@["\x{201C}-\x{201E}])\s*$
beginCaptures
1
name
punctuation.definition.string.begin.powershell
end
^["\x{201C}-\x{201E}]@
endCaptures
0
name
punctuation.definition.string.end.powershell
name
string.quoted.double.heredoc.powershell
patterns
include
#variableNoProperty
include
#doubleQuotedStringEscapes
include
#interpolation
begin
(@['\x{2018}-\x{201B}])\s*$
beginCaptures
1
name
punctuation.definition.string.begin.powershell
end
^['\x{2018}-\x{201B}]@
endCaptures
0
name
punctuation.definition.string.end.powershell
name
string.quoted.single.heredoc.powershell
include
#numericConstant
begin
(@)(\()
beginCaptures
1
name
keyword.other.array.begin.powershell
2
name
punctuation.section.group.begin.powershell
end
\)
endCaptures
0
name
punctuation.section.group.end.powershell
name
meta.group.array-expression.powershell
patterns
include
$self
begin
((\$))(\()
beginCaptures
1
name
keyword.other.substatement.powershell
2
name
punctuation.definition.subexpression.powershell
3
name
punctuation.section.group.begin.powershell
comment
TODO: move to repo; make recursive.
end
\)
endCaptures
0
name
punctuation.section.group.end.powershell
name
meta.group.complex.subexpression.powershell
patterns
include
$self
match
(\b(([A-Za-z0-9\-_\.]+)\.(?i:exe|com|cmd|bat))\b)
name
support.function.powershell
match
(?<!\w|-|\.)((?i:begin|break|catch|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)
name
keyword.control.powershell
match
(?<!\w|-|[^\)]\.)((?i:(foreach|where)(?!-object))|%|\?)(?!\w)
name
keyword.control.powershell
begin
(?<!\w)(--%)(?!\w)
beginCaptures
1
name
keyword.control.powershell
end
$
patterns
match
.+
name
string.unquoted.powershell
comment
This should be moved to the repository at some point.
comment
This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix.
match
(?<!\w)((?i:hidden|static))(?!\w)
name
storage.modifier.powershell
captures
1
name
storage.type.powershell
2
name
entity.name.function
comment
capture should be entity.name.type, but it doesn't provide a good color in the default schema.
match
(?<!\w|-)((?i:class)|%|\?)(?:\s)+((?:\p{L}|\d|_|-|)+)\b
match
(?<!\w)-(?i:is(?:not)?|as)\b
name
keyword.operator.comparison.powershell
match
(?<!\w)-(?i:[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace))(?!\p{L})
name
keyword.operator.comparison.powershell
match
(?<!\w)-(?i:join|split)(?!\p{L})|!
name
keyword.operator.unary.powershell
match
(?<!\w)-(?i:and|or|not|xor)(?!\p{L})|!
name
keyword.operator.logical.powershell
match
(?<!\w)-(?i:band|bor|bnot|bxor|shl|shr)(?!\p{L})
name
keyword.operator.bitwise.powershell
match
(?<!\w)-(?i:f)(?!\p{L})
name
keyword.operator.string-format.powershell
match
[+%*/-]?=|[+/*%-]
name
keyword.operator.assignment.powershell
match
\|{2}|&{2}|;
name
punctuation.terminator.statement.powershell
match
&|(?<!\w)\.(?= )|`|,|\|
name
keyword.operator.other.powershell
comment
This is very imprecise, is there a syntax for 'must come after...'
match
(?<!\s|^)\.\.(?=\-?\d|\(|\$)
name
keyword.operator.range.powershell
repository
commentLine
begin
(?<![`\\-])(#)#*
captures
1
name
punctuation.definition.comment.powershell
end
$\n?
name
comment.line.powershell
patterns
include
#commentEmbeddedDocs
include
#RequiresDirective
attribute
begin
(\[)\s*\b(?i)(cmdletbinding|alias|outputtype|parameter|validatenotnull|validatenotnullorempty|validatecount|validateset|allownull|allowemptycollection|allowemptystring|validatescript|validaterange|validatepattern|validatelength|supportswildcards)\b
beginCaptures
1
name
punctuation.section.bracket.begin.powershell
2
name
support.function.attribute.powershell
end
(\])
endCaptures
1
name
punctuation.section.bracket.end.powershell
name
meta.attribute.powershell
patterns
begin
\(
beginCaptures
0
name
punctuation.section.group.begin.powershell
end
\)
endCaptures
0
name
punctuation.section.group.end.powershell
patterns
include
$self
match
(?i)\b(mandatory|valuefrompipeline|valuefrompipelinebypropertyname|valuefromremainingarguments|position|parametersetname|defaultparametersetname|supportsshouldprocess|supportspaging|positionalbinding|helpuri|confirmimpact|helpmessage)\b(?:\s+)?(=)?
captures
1
name
variable.parameter.attribute.powershell
2
name
keyword.operator.assignment.powershell
commands
patterns
comment
Verb-Noun pattern:
match
(?:(\p{L}|\d|_|-|\\|\:)*\\)?\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Deploy|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Mount|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Write)\-.+?(?:\.(?i:exe|cmd|bat|ps1))?\b
name
support.function.powershell
comment
Builtin cmdlets with reserved verbs
match
(?<!\w)(?i:foreach-object)(?!\w)
name
support.function.powershell
comment
Builtin cmdlets with reserved verbs
match
(?<!\w)(?i:where-object)(?!\w)
name
support.function.powershell
comment
Builtin cmdlets with reserved verbs
match
(?<!\w)(?i:sort-object)(?!\w)
name
support.function.powershell
comment
Builtin cmdlets with reserved verbs
match
(?<!\w)(?i:tee-object)(?!\w)
name
support.function.powershell
commentEmbeddedDocs
patterns
captures
1
name
constant.string.documentation.powershell
2
name
keyword.operator.documentation.powershell
comment
these embedded doc keywords do not support arguments, must be the only thing on the line
match
(?:^|\G)(?i:\s*(\.)(COMPONENT|DESCRIPTION|EXAMPLE|FUNCTIONALITY|INPUTS|LINK|NOTES|OUTPUTS|ROLE|SYNOPSIS))\s*$
name
comment.documentation.embedded.powershell
captures
1
name
constant.string.documentation.powershell
2
name
keyword.operator.documentation.powershell
3
name
keyword.operator.documentation.powershell
comment
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
match
(?:^|\G)(?i:\s*(\.)(EXTERNALHELP|FORWARDHELP(?:CATEGORY|TARGETNAME)|PARAMETER|REMOTEHELPRUNSPACE))\s+(.+?)\s*$
name
comment.documentation.embedded.powershell
doubleQuotedStringEscapes
patterns
match
`[`0abefnrtv'"\x{2018}-\x{201E}$]
name
constant.character.escape.powershell
include
#unicodeEscape
unicodeEscape
comment
`u{xxxx} added in PowerShell 6.0
patterns
match
`u\{(?:(?:10)?([0-9a-fA-F]){1,4}|0?\g<1>{1,5})}
name
constant.character.escape.powershell
match
`u(?:\{[0-9a-fA-F]{,6}.)?
name
invalid.character.escape.powershell
function
begin
^(?:\s*+)(?i)(function|filter|configuration|workflow)\s+(?:(global|local|script|private):)?((?:\p{L}|\d|_|-|\.)+)
beginCaptures
0
name
meta.function.powershell
1
name
storage.type.powershell
2
name
storage.modifier.scope.powershell
3
name
entity.name.function.powershell
end
(?=\{|\()
patterns
include
#commentLine
subexpression
begin
\(
beginCaptures
0
name
punctuation.section.group.begin.powershell
end
\)
endCaptures
0
name
punctuation.section.group.end.powershell
name
meta.group.simple.subexpression.powershell
patterns
include
$self
interpolation
begin
(((\$)))((\())
beginCaptures
1
name
keyword.other.substatement.powershell
2
name
punctuation.definition.substatement.powershell
3
name
punctuation.section.embedded.substatement.begin.powershell
4
name
punctuation.section.group.begin.powershell
5
name
punctuation.section.embedded.substatement.begin.powershell
contentName
interpolated.complex.source.powershell
end
(\))
endCaptures
0
name
punctuation.section.group.end.powershell
1
name
punctuation.section.embedded.substatement.end.powershell
name
meta.embedded.substatement.powershell
patterns
include
$self
numericConstant
patterns
captures
1
name
constant.numeric.hex.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?0(?:x|X)[0-9a-fA-F_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.integer.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?(?:[0-9_]+)?\.[0-9_]+(?:(?:e|E)[0-9]+)?(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.octal.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?0(?:b|B)[01_]+(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.integer.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?[0-9_]+(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.integer.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?[0-9_]+\.(?:e|E)(?:[0-9_])?+(?:F|f|D|d|M|m)?)((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.integer.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?[0-9_]+[\.]?(?:F|f|D|d|M|m))((?i:[kmgtp]b)?)\b
captures
1
name
constant.numeric.integer.powershell
2
name
keyword.other.powershell
match
(?<!\w)([-+]?[0-9_]+[\.]?(?:U|u|L|l|UL|Ul|uL|ul|LU|Lu|lU|lu)?)((?i:[kmgtp]b)?)\b
scriptblock
begin
\{
beginCaptures
0
name
punctuation.section.braces.begin.powershell
end
\}
endCaptures
0
name
punctuation.section.braces.end.powershell
name
meta.scriptblock.powershell
patterns
include
$self
type
begin
\[
beginCaptures
0
name
punctuation.section.bracket.begin.powershell
end
\]
endCaptures
0
name
punctuation.section.bracket.end.powershell
patterns
match
(?!\d+|\.)(?:\p{L}|\p{N}|\.)+
name
storage.type.powershell
include
$self
variable
patterns
captures
0
name
constant.language.powershell
1
name
punctuation.definition.variable.powershell
comment
These are special constants.
match
(\$)(?i:(False|Null|True))\b
captures
0
name
variable.other.constant.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
These are the other built-in constants.
match
(\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))((?:\.(?:\p{L}|\d|_)+)*\b)?\b
captures
0
name
support.variable.automatic.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
Automatic variables are not constants, but they are read-only. In monokai (default) color schema support.variable doesn't have color, so we use constant.
match
(\$)((?:[$^?])|(?i:_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b)((?:\.(?:\p{L}|\d|_)+)*\b)?
captures
0
name
variable.language.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
Style preference variables as language variables so that they stand out.
match
(\$)(?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
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
storage.modifier.scope.powershell
4
name
variable.other.member.powershell
match
(?i:(\$|@)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
punctuation.section.braces.begin.powershell
3
name
storage.modifier.scope.powershell
5
name
punctuation.section.braces.end.powershell
6
name
variable.other.member.powershell
match
(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
support.variable.drive.powershell
4
name
variable.other.member.powershell
match
(?i:(\$|@)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))((?:\.(?:\p{L}|\d|_)+)*\b)?
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
punctuation.section.braces.begin.powershell
3
name
support.variable.drive.powershell
5
name
punctuation.section.braces.end.powershell
6
name
variable.other.member.powershell
match
(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))((?:\.(?:\p{L}|\d|_)+)*\b)?
UsingDirective
match
(?<!\w)(?i:(using))\s+(?i:(namespace|module))\s+(?i:((?:\w+(?:\.)?)+))
captures
1
name
keyword.control.using.powershell
2
name
keyword.other.powershell
3
name
variable.parameter.powershell
RequiresDirective
begin
(?<=#)(?i:(requires))\s
beginCaptures
0
name
keyword.control.requires.powershell
end
$
name
meta.requires.powershell
patterns
match
\-(?i:Modules|PSSnapin|RunAsAdministrator|ShellId|Version|Assembly|PSEdition)
name
keyword.other.powershell
match
(?<!-)\b\p{L}+|\d+(?:\.\d+)*
name
variable.parameter.powershell
include
#hashtable
variableNoProperty
patterns
captures
0
name
constant.language.powershell
1
name
punctuation.definition.variable.powershell
comment
These are special constants.
match
(\$)(?i:(False|Null|True))\b
captures
0
name
variable.other.constant.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
These are the other built-in constants.
match
(\$)(?i:(Error|ExecutionContext|Host|Home|PID|PsHome|PsVersionTable|ShellID))\b
captures
0
name
support.variable.automatic.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
Automatic variables are not constants, but they are read-only...
match
(\$)((?:[$^?])|(?i:_|Args|ConsoleFileName|Event|EventArgs|EventSubscriber|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel|Profile|PSBoundParameters|PsCmdlet|PsCulture|PSDebugContext|PSItem|PSCommandPath|PSScriptRoot|PsUICulture|Pwd|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b)
captures
0
name
variable.language.powershell
1
name
punctuation.definition.variable.powershell
3
name
variable.other.member.powershell
comment
Style preference variables as language variables so that they stand out.
match
(\$)(?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
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
storage.modifier.scope.powershell
4
name
variable.other.member.powershell
match
(?i:(\$)(global|local|private|script|using|workflow):((?:\p{L}|\d|_)+))
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
storage.modifier.scope.powershell
4
name
keyword.other.powershell
5
name
variable.other.member.powershell
match
(?i:(\$)(\{)(global|local|private|script|using|workflow):([^}]*[^}`])(\}))
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
support.variable.drive.powershell
4
name
variable.other.member.powershell
match
(?i:(\$)((?:\p{L}|\d|_)+:)?((?:\p{L}|\d|_)+))
captures
0
name
variable.other.readwrite.powershell
1
name
punctuation.definition.variable.powershell
2
name
punctuation.section.braces.begin
3
name
support.variable.drive.powershell
5
name
punctuation.section.braces.end
match
(?i:(\$)(\{)((?:\p{L}|\d|_)+:)?([^}]*[^}`])(\}))
hashtable
begin
(@)(\{)
beginCaptures
1
name
keyword.other.hashtable.begin.powershell
2
name
punctuation.section.braces.begin.powershell
end
(\})
endCaptures
1
name
punctuation.section.braces.end.powershell
name
meta.hashtable.powershell
patterns
captures
1
name
punctuation.definition.string.begin.powershell
2
name
variable.other.readwrite.powershell
3
name
punctuation.definition.string.end.powershell
4
name
keyword.operator.assignment.powershell
match
\b((?:\'|\")?)(\w+)((?:\'|\")?)(?:\s+)?(=)(?:\s+)?
name
meta.hashtable.assignment.powershell
include
#scriptblock
include
$self
doubleQuotedString
begin
["\x{201C}-\x{201E}]
beginCaptures
0
name
punctuation.definition.string.begin.powershell
end
["\x{201C}-\x{201E}]
applyEndPatternLast
endCaptures
0
name
punctuation.definition.string.end.powershell
name
string.quoted.double.powershell
patterns
match
(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,64}\b
include
#variableNoProperty
include
#doubleQuotedStringEscapes
match
["\x{201C}-\x{201E}]{2}
name
constant.character.escape.powershell
include
#interpolation
match
`\s*$
name
keyword.other.powershell
scopeName
source.powershell
uuid
f8f5ffb0-503e-11df-9879-0800200c9a66
================================================
FILE: README.md
================================================
# PowerShell Syntax Definition for Editors
This project establishes the central development and maintenance of syntax definition
files for the PowerShell language used by editors that leverage the XML version of the
[TextMate language grammar format](http://manual.macromates.com/en/language_grammars).
Currently this syntax definition is used in the following editors and extensions:
- [Visual Studio Code](https://github.com/Microsoft/vscode) by Microsoft
- [PowerShell Package for Sublime Text](https://github.com/SublimeText/PowerShell) by [Guillermo López-Anglada](https://github.com/guillermooo)
- [language-powershell for Atom](https://github.com/jugglingnutcase/language-powershell) by [James Sconfitto](https://github.com/jugglingnutcase/)
In the future we may find a more common syntax that allows us to generate syntax
definitions for editors that don't leverage the TextMate format.
## Status
We are starting with the current state of the TextMate grammar that is being used in
both VS Code and Sublime Text. There are a number of existing issues with the grammar
that we need to track down and fix. Please see [issue #1](https://github.com/PowerShell/EditorSyntax/issues/1)
for more details.
### Prerequisites
- Node.JS, >= 8.9.1
- Atom text editor (tests)
### Build (build.ps1)
1. Run `build.ps1` to generate the grammar.
```
PS> .\build.ps1
```
2. The .json file will be generated in `./grammars/` at the root of the project.
### Test (build.ps1)
> Requires the Atom text editor be installed.
1. Run `.\build.ps1` with `-Test`. Which will build the grammar file and run all of the specs.
```
PS> .\build.ps1 -Test
```
### Build (npm)
1. Use `npm` to install dependencies:
```
npm install
```
2. Run the `build-grammar` script to generate the json file.
```
npm run build-grammar
```
3. The .json file will be generated in `./grammars/` at the root of the project.
### Test (Atom cli)
1. Build the grammar file using the above steps.
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.
```
atom --test spec
```
## Contributing
We would love to have community contributions to this project to make PowerShell syntax
highlighting great in as many editors as we can. Please feel free to file issues or
send pull requests if you'd like to contribute.
## Maintainers
- [Andy Jordan](https://github.com/andyleejordan)
- [Nick James](https://github.com/omniomi)
## License
This extension is [licensed under the MIT License](LICENSE). Please see the
[third-party notices](Third%20Party%20Notices.txt) file for details on the original
source of the TextMate definition that we use.
## Code of Conduct
Please see our [Code of Conduct](.github/CODE_OF_CONDUCT.md) before participating in this project.
## Security Policy
For any security issues, please see our [Security Policy](.github/SECURITY.md).
================================================
FILE: Third Party Notices.txt
================================================
Third Party Notices for PowerShell Editor Syntax
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.
Copyright (c) 2011 Guillermo López-Anglada
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:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
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.
================================================
FILE: appveyor.yml
================================================
version: 1.0.{build}
image: Visual Studio 2017
skip_tags: true
branches:
only:
- master
- development
- appveyor
pull_requests:
do_not_increment_build_number: true
skip_commits:
message: /skip\-build/
files:
- .vscode/
- README.md
- .gitattributes
- .gitignore
install:
- ps: . .\tools\banners.ps1
- ps: . .\tools\build-helpers.ps1
- ps: SyntaxBanner
- ps: Install-Product node '8.9.1'
- ps: Set-Location $env:APPVEYOR_BUILD_FOLDER
- ps: npm install
- ps: DownloadAtom
build_script:
- ps: BuildBanner
- ps: npm run build-grammar
test_script:
- ps: TestBanner
- ps: Set-Location $env:APPVEYOR_BUILD_FOLDER
- ps: $script:ATOM_EXE_PATH = Join-Path $pwd 'Atom\Atom.exe'
- ps: RunSpecs
on_finish:
- ps: EndBanner
- ps: Push-AppveyorArtifact (Join-Path $env:APPVEYOR_BUILD_FOLDER '\grammars\powershell.tmLanguage.json')
================================================
FILE: build.ps1
================================================
<#
.Synopsis
Convert the grammar file to json and/or run tests.
.DESCRIPTION
Build: Converts the .tmLanguage file to .json for use in VSCode or Atom.
Test: Uses Atom and atom-grammar-test to run tests against specs and sample files to guard against regression.
.EXAMPLE
PS C:\EditorSyntax> .\build.ps1
[Starting] Converting ../PowerShellSyntax.tmLanguage to json.
... Reading source file.
... Parsing content.
... Building contents.
... Creating directory: ./grammars
[Finished] File written to: ../grammars/powershell.tmLanguage.json
.EXAMPLE
PS C:\EditorSyntax> .\build.ps1 Test
Running specs...
.....
Finished in 0.281 seconds
2 tests, 5 assertions, 0 failures, 0 skipped
#>
param(
[switch]
$Test
)
# Load Helpers
. .\tools\build-helpers.ps1
. .\tools\banners.ps1
SyntaxBanner
if (-not (npm -v)) {
throw 'Requires Node.js - Could not find npm.'
}
npm install
# helper tasks
function RunBuild() {
BuildBanner
try {
Write-Host "Building grammar file(s)..."
npm run build-grammar
}
catch {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
}
function RunTests() {
$script:ATOM_EXE_PATH = (Get-Command atom).Path
if (-not $script:ATOM_EXE_PATH) {
throw "Atom not found. Install it from https://atom.io/"
}
}
RunBuild
if ($Test) {
RunTests
TestBanner
RunSpecs
}
EndBanner
================================================
FILE: examples/TheBigTestFile.ps1
================================================
using namespace System.Management.Automation
#Requires -PSSnapin DiskSnapin -Version 1.2
#Requires -PSSnapin DiskSnapin
#Requires -Version 3
#Requires -Version 3.0
#Requires -Version 3 -RunAsAdministrator
#Requires -RunAsAdministrator
#Requires -Modules PSWorkflow
#Requires -Modules PSWorkflow -ThisIsInvalid
#Requires -Modules PSWorkflow, ActiveDirectory
#Requires -Modules PSWorkflow,ActiveDirectory
#Requires -ShellId MyLocalShell
#Requires -PSEdition Core
#Requires -Assembly System
#Requires -Modules PSWorkflow @{
ModuleName="PSScheduledJob"
ModuleVersion="1.0.0.0"
}
throw "Do not run this file!"
<#
The big PowerShell syntax highlighting test file
#>
# Stop parsing
& tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment
# Automatic variables
$_
$args
$error
$home
$foreach
# Normal variables
$variable
$script:variable
$ENV:ComputerName
# This is not allowed
$ENV:
${variable}
${script:variable}
${#variableName}
${'variableName'}
${"$variableName"}
${variable name}
${script:this`{name`}is"valid"}
# Variable properties should be highlighted
$variable.Name
($variable).Name
# In double-quoted strings, only the variable should be highlighted, not the property
"This is my $variable.Name!"
# When used in a subexpression, both should be highlighted
"This is my $($variable.Name)!"
# $ENV:ComputerName should be highlighted
"This is the name of my computer: $ENV:ComputerName"
# Here as well
"This is the name of my computer: ${ENV:ComputerName}"
# This is still not allowed though
"This is the name of my computer $ENV: "
# This is an illegal variable name
$variable-name
# Hashtable
$properties = @{
Name = 'Name'
Something = $else
Number = 16
from = 'hello world'
hash = @{
hello = 'world'
}
}
# Spatting
Invoke-Something @properties
# ScriptBlock
{Invoke-Something @properties}
{
Invoke-Something @properties
}
$sb = {
Invoke-Something @properties
}
# Arrays
$a1 = @(1,2,3,4)
$a2 = ('one','two','three','four')
$a3 = $one, $two, $three, $four
$a1[0]
$a2[-1]
$a3[1..2]
@(@($a))
@(($i = 10); (++$j))
@($i = 10)
$i[($y - 1) + $x]
# Single quoted strings
'This is a single quoted string.'
'$This is a single ''quoted'' string.'
'This is a
single quoted string.'
'This #also'
'$(Invoke-Something)'
'This "string" is nice.'
# Single quoted here-string
@'
$This is a ''single quoted''
$('Here-String')
Isn't it "nice"??
'@
# Double quoted strings
"This is a double quoted string."
"$This is a double ""quoted"" string."
"This is a
double quoted string."
"This #also"
"$(Invoke-Something)"
"This 'string' is nice."
# Double quoted here-string
@"
$This is a 'double quoted'
$('Here-String')
Isn't it "nice"??
"@
# Numeric constants
-3
.5
+.5
1.
1.d
1.lGB
1.e+12d
1e+12d
1.5
-1.5
-3 + -2
-3+-2
3++2
+2
-3+-
10/-10
10/-10D
-10.002L
$x..5.40D
-500..-495
$true..3
-2..$null
-3..3
1 .. 3kb
1..3
6,10,-3
0x476
+0x20
-0x20
# Types
[string]
[string[]]
[int32]
[System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]]
[System.Array+SZArrayEnumerator]
[int]::MinValue
[System.DateTime]::Parse('2016/09/21')
# Commands (functions)
Invoke-Something -foobar
Invoke-Something -foobar value
Invoke-Something -foobar:$true
Invoke-Something -foobar: $true
Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose
Invoke-Something (1..20 | Invoke-Something) -p2 'value'
Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch
Invoke-Something -p1 {
Invoke-Something -foobar:$true
} | Invoke-Something
Invoke-Something -p1 value `
-p2 14.4 `
-p3 $value | Invoke-Something -verbose
# Commands (Built-in variables)
ls *.ps1 -recurse
# Commands (executable files)
. .\scripts\myscript.ps1 -parameter 'value'
& tool.exe
something.cmd
øyvind.com # this should also highlight - TODO!
# But this should not highlight anything
file.1
This.txt
Function.txt
Where.txt
ForEach-Object.txt
# switch
switch ("fourteen") {}
switch -CaseSensitive ("fourteen") {}
switch -Illegal ("fourteen") {} # Using illegal switch parameter
switch -Regex ("fourteen") {}
switch -Wildcard ($a) {}
switch -regex -file .\somefile.txt {}
switch (3) {}
switch (4, 2) {}
switch -Regex -File $filePath {
'.' {}
default {}
}
switch -Wildcard -CaseSensitive ($something) {
'.' {}
default {}
}
switch ('this') {
'this' {}
default {}
}
# Illegal backtick
Invoke-Command -arg1 $val1 `
-arg2 $val2 `
# Functions and filters
functioN MyFunction{}
function My-Function {}
Function My.Function{}
function My-Function.Other{}
function Some.other.function{}
FUNCTION MyFunction2 {}
function MyFunction3
{
}
function New-File { }
function New-File ($Name) { }
function NewFile($Name) { }
functionMyFunction{}
filter myfilter($param) {}
Filter my-Filter ($param){}
function foo
#comment
{
}
# This one will not highlight the function name,
# because of the comments after 'function'. TODO?
function
<# another comment #>
test
(
[string]
<# another comment #>
[parameter(mandatory)]
$s
)
{
"test $s"
}
# Note that the # in the path should highlight as a comment!
function Test-Drive([string]$roman) {
$roman | c:\users\Me\Documents\Programming\F#\test.exe $roman
}
function Get-EscapedPath
{
param(
[Parameter(
Position=0,
Mandatory=$true
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[string]$path
)
process {
if ($path.Contains(' '))
{
return '"' + $path + '"'
}
return $path
}
}
# Enum
enum test
{
listItem1
listItem2
listItem3
}
# Illegal enum name
enum my-Enum {
}
# Class
class Vehicle {
Vehicle() {}
Vehicle([string]$Owner) {
$this.Owner = $Owner
}
[int]$Mileage
[int]$Age
[string]$Owner
[void]Drive([int]$NumberOfMiles) {
$this.Mileage += $NumberOfMiles
}
}
class Car: Vehicle {
Car() {}
Car([int]$Age) {
$this.Age = $Age
}
Car([int]$Age, [string]$Owner) : base([string]$Owner) {
$this.Age = $Age
$this.Owner = $Owner
}
hidden [int]$Length
static [int]$Width
SetLength([int]$Length) {
$this.Length = $Length
}
}
# Illegal class name
class my-class {}
# Control words
foreach ($item in $collection) {
try {
if ($item -gt 100) {
continue
}
}
catch {
break
}
}
# Reserved words
Configuration Crazyness {
Node Whatever {
}
}
param ()
# Redirection
notepad.exe > log.txt
notepad.exe 1> log.txt
notepad.exe 2>&1
notepad.exe 3>&1
notepad.exe 4>&1
notepad.exe 5>&1
notepad.exe 6>&1
notepad.exe 2>&1> log.txt
# Note: 7 isn't a valid stream
notepad.exe 7>&1
# Operators
if (10 -cgt 100) { }
$a -is $b
$b -contains $c
$x -notcontains $c
$c -in $b
$c -notin $x
$a -match $b
$a -notmatch $b
$x -like $c
100 -and 0
$a -ceq 4 -and $a -ine $d -or
$c -is [Type]
$c -isnot [Type]
$c -as [Type]
$k = $y -bor $k
$x = $y -band $x
$z = -bnot $x
$k = $y -xor $b
$k = $y -bxor $b
$a -icontains $c
$a -ccontains $c
$a -iNotContains $c
$a -cNotContains $c
$a -cmatch $c
$x -iMatch $c
$x -iNotMatch $c
$a -iLike $b
$b -cLike $c
"hey" -cgt "Hey"
"Hey" -igt "hey"
"hey" -cge "Hey"
"Hey" -ige "hey"
"HEY" -clt "hey"
"HEY" -ilt "hey"
"HEY" -cle "hey"
"HEY" -ile "hey"
# this isn't a valid operator:
$x -foobar $y
# Negative: these are cmdlets with unapproved verbs
# we should not highlight keywords in them
Foo-Is
Foo-Not
Foo-Join
Foo-Bxor
Foo-f
Foo-eq
Foo-match
# format
"{0:N2}" -f $a
"{0:D8}" -f $a
"{0:C2}" -f $a
"{0:P0}" -f $a
"{0:X0}" -f $a
(1.11).tostring("#.#")
"{1,10} {0,10} {2,10:x}" -f "First", "Second", 255
("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9)
"{0:R}" -f (1mb/2.0)
"{0:00.0}" -f 4.12341234
"{0:##.#}" -f 4.12341234
"{0:#,#.#}" -f 1234.121234
"{0:##,,.000}" -f 1048576
"{this is not a #comment}"
"{0:##.#E000}" -f 2.71828
"{0:#.00'##'}" -f 2.71828
"{0:POS;NEG;ZERO}" -f -14
"{0:$## Please}" -f 14
"{0,-8:P1}" -f 1.75
"{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91
'{0:00000.000}' -f 7.125
# Help Directives (Comment based help)
# Should also be able to use with line comments
# .DESCRIPTION
# .EXAMPLE sdkl
#
# .EXTERNALHELP some
# .REMOTEHELPRUNSPACE some
# .ExternalHelp some
<#
.DESCRIPTION
This is a description.
.REMOTEHELPRUNSPACE some
.example
.EXAMPLE
Get-Power 3 4
81
.ExternalHelp C:\MyScripts\Update-Month-Help.xml
.FORWARDHELPCATEGORY Cmdlet
.FORWARDHELPTARGETNAME Get-Help
.INPUTS
None.
.LINK
Online version: http://www.acmecorp.com/widget.html
.LINK
Set-ProcedureName
.NOTES
Something.
.OUTPUTS
None unless the -PassThru switch parameter is used.
.PARAMETER ParameterName
.SYNOPSIS
Something.
#>
# Misc test cases
@("any","array","has").foreach({ $_ })
@('any','array','has').foreach{ $_ }
@("any","array","has").where({ $_.Length -gt 3 })
@("any","array","has").where{ $_.Length -gt 3 }
foo "$(x).exe"
$file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1"
$ScriptBlock | Out-File $file -Force
workflow w1 {}
Workflow work {}
get-thing | Out-WithYou > $null # destroy
"Escaped chars: `", `n, `$, `b, `t, `""
'But here they''re not escape chars: `", `n, `$, `b, `"'
"When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )"
foo
$a = $("Guess what, happens ""here, hey""" | "Hm... $("this, is" strange.) you can't really pipe to a string, but nevermind for now.")
this-isnot.ps1
a_mistake.here.ps1
"anothermistake.ps1"
$users.Split(',').Trim()
TestConfiguration -OutputPath $workingDirectory
"blablabla $(invoke-foo baz $a.bar) blablabla"
invoke-foo baz $a.bar
var
-var
_var
jvar
varj
[ValidatePattern('^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')]
$foo.bar
($foo).bar
(Invoke-Something).bar
#comment
some#comment # we need a space before the # for it to become a comment
================================================
FILE: examples/advancedFunction.ps1
================================================
using module Microsoft.PowerShell.Management
<#
.Synopsis
Short description
.DESCRIPTION
Long description
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
.INPUTS
Inputs to this cmdlet (if any)
.OUTPUTS
Output from this cmdlet (if any)
.NOTES
General notes
.COMPONENT
The component this cmdlet belongs to
.ROLE
The role this cmdlet belongs to
.FUNCTIONALITY
The functionality that best describes this cmdlet
#>
function Verb-Noun
{
[CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',
SupportsShouldProcess = $true,
PositionalBinding = $false,
HelpUri = 'http://www.microsoft.com/',
ConfirmImpact = 'Medium')]
[Alias()]
[OutputType([String])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName = $true,
ValueFromRemainingArguments=$false,
Position=0,
ParameterSetName = 'Parameter Set 1')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[ValidateCount(0,5)]
[ValidateSet("sun", "moon", "earth")]
[Alias("p1")]
$Param1,
# Param2 help description
[Parameter(ParameterSetName='Parameter Set 1')]
[AllowNull()]
[AllowEmptyCollection()]
[AllowEmptyString()]
[ValidateScript({$true})]
[ValidateRange(0,5)]
[int32]
$Param2,
# Param3 help description
[Parameter(ParameterSetName='Another Parameter Set')]
[ValidatePattern("[a-z]*")]
[ValidateLength(0,15)]
[String]
$Param3,
# Param4 help description
[Parameter(ParameterSetName='Parameter Set 1')]
[ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting
[string]
$Param4,
# Param4 help description
[Parameter(ParameterSetName='Parameter Set 1')]
[ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting
[string]
$Param5
)
Begin
{
}
Process
{
if ($pscmdlet.ShouldProcess("Target", "Operation"))
{
}
}
End
{
}
Clean
{
}
}
================================================
FILE: examples/class.ps1
================================================
using namespace system.management.automation
# Define a class
class TypeName
{
# Property with validate set
[ValidateSet("val1", "Val2")]
[string] $P1
# Static property
static [hashtable] $P2
# Hidden property does not show as result of Get-Member
hidden [int] $P3
# Constructor
TypeName ([string] $s)
{
$this.P1 = $s
}
# Static method
static [void] MemberMethod1([hashtable] $h)
{
[TypeName]::P2 = $h
}
# Instance method
[int] MemberMethod2([int] $i)
{
$this.P3 = $i
return $this.P3
}
}
================================================
FILE: examples/test.ps1
================================================
# Testing PowerShell syntax highlighting rules.
## Strings ##
### Single quoted strings
'Single quoted string.'
'Single "quoted" string.'
'Single ''quoted'' string.'
'Single quoted #string.'
'Single $quoted string.'
### Double quoted strings
"Double quoted string."
"Double 'quoted' string."
"Double ""quoted"" string."
"Double `"quoted`" string."
"Double quoted #string."
"Double $quoted string."
### Single quoted here-string
@'
Single quoted here-string.
Single 'quoted' here-string.
Single "quoted" here-string.
Single quoted #here-string.
Single $quoted here-string.
'@
### Double quoted here-string
@"
Double quoted here-string.
Double "quoted" here-string.
Double 'quoted' here-string.
Double quoted #here-string.
Double $quoted here-string.
"@
### Complex strings
'^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)'
# This one currently fails. It's the exact same string as the one above. Uncomment to check.
#[ValidatePattern('^(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')]
# Stop Parsing
# Synatx highlighting should stop after --%, with the exception of the comment.
command.exe -parameter 1 --% -parameter 2 /switch /par1:value # comment
# Variables
$name = 'value'
"variable in a $string"
"variable in a $($subExpression)"
$global:name = 'value'
$script:name = 'value'
$local:name = 'value'
$private:name = 'value'
$using:name = 'value'
${name} = 'value'
${variable-name} = 'value'
${#name} = 'value'
${123} = 'value'
${'name'} = 'value'
${variable name} = 'value'
${global: variable name} = 'value'
${script:this`{value`}is} = 'valid' # don't currently work correctly
$_ = $null
$123 = 'value'
$variable_name = 'value'
$variable-name = 'value' # - in variable name is not allowed
$$
# Syntax highlighting not consistent in these cases!
$foo.bar
($foo).bar
(Invoke-Something).bar
# Sub Expression
# Syntax highlighting not consistent in these two cases!
"blablabla $(invoke-foo baz $a.bar) blablabla"
invoke-foo baz $a.bar
# Arrays
@('One', 2, $three)
('One', 2, $three)
$p = @(Get-Process Notepad)
$a[0]
$a[-3..-1]
$a[0,2+4..6]
,(1,2,3)
,$a
$t = $a[0,1 + 3..($a.length - 1)]
# Hash Table
@{
Key = 'Value'
Key = 123
Key = $value
}
$ht = @{
Key = 'Value'
Key = 123
Key = $value
}
$hash = [ordered]@{ Number = 1; Shape = "Square"; Color = "Blue"}
# Splatting
Invoke-Something @parameters
# Script Block
{
'String'
Invoke-Something -p1 'value' -p2 $value
}
$sb = {
'String'
Invoke-Something -p1 'value' -p2 $value
}
# Types and .NET classes
[string]$var = 'string'
[system.string]$var = 'string'
[int]$var = 100
[uint64]$var = 100
[System.String]::Empty
[System.DateTime]::Parse('2016/09/21')
[int32[]]$ia = 1500,2230,3350,4000
# Numeric constants
1
9,9
9.9
10gb
2/5kb
# Numeric formatting
# {index[,alignment][:formatString]}
$a = 348
"{0:N2}" -f $a
"{0:D8}" -f $a
"{0:C2}" -f $a
"{0:P0}" -f $a
"{0:X0}" -f $a
(1.11).tostring("#.#")
"{1,10} {0,10} {2,10:x}" -f "First", "Second", 255
("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9)
"{0:R}" -f (1mb/2.0)
"{0:00.0}" -f 4.12341234
"{0:##.#}" -f 4.12341234
"{0:#,#.#}" -f 1234.121234
"{0:##,,.000}" -f 1048576
"{this is not a #comment}"
"{0:##.#E000}" -f 2.71828
"{0:#.00'##'}" -f 2.71828
"{0:POS;NEG;ZERO}" -f -14
"{0:$## Please}" -f 14
"{0,-8:P1}" -f 1.75
"{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91
'{0:00000.000}' -f 7.125
# Operators
$i = 0
$i++
$i += 10
$a -band $b
$x -gt $y
$string -not $null
$int -as [double]
if (! $variable) {}
if (-not $variable) {}
$a -band $b
$a -shr $b
$a -eq $b
$a -le $b
$a -less $b # -less is not a valid operator and shouldn't be tagged and highlighted as such.
# Parameters
Write-Host -Message 'This is a message'
Write-Host 'This is a message'
Write-Host something something
Get-WmiObject -Class Win32_OperatingSystem -ComputerName localhost | Select-Object -Property CSName,LastBootupTime
# Functions and filters
functioN MyFunction{}
function My-Function {}
Function My.Function{}
function My-Function.Other{}
function Some.other.function{}
FUNCTION MyFunction2 {}
function MyFunction3
{
}
function New-File { }
function New-File ($Name) { }
function NewFile($Name) { }
functionMyFunction{}
filter myfilter($param) {}
Filter my-Filter ($param){}
function global:Invoke-Something {}
# This variant don't work properly
function
#comment
<# another comment #>
test
(
[string]
<# another comment #>
[parameter(mandatory)]
$s
)
{
"test $s"
}
# Enum
enum myEnum
{
listItem1
listItem2
listItem3
}
# - in enum name is not allowed
enum my-Enum {
listItem1
listItem2
listItem3
}
# Class
class myClass {}
# - in class name is not allowed
class my-Class {}
# DSC
configuration myConfiguration {
node web01, web02, web03 {
}
}
# Switch
# switch [-regex|-wildcard|-exact][-casesensitive] ()
# switch [-regex|-wildcard|-exact][-casesensitive] -file filename
switch ($variable)
{
'Value' {
return $false
}
2 {}
{$value -le 100} {}
default {
return $true
}
}
switch ("fourteen") {}
switch -CaseSensitive ("fourteen") {}
switch -Illegal ("fourteen") {}
switch -Regex ("fourteen") {}
switch -Wildcard ($a) {}
switch -regex -file .\somefile.txt {}
switch (3) {}
switch (4, 2) {}
# Executable files
. .\otherScript.ps1
& cmd.exe
c:\windows\system32\command.com
c:\file.txt
file.txt
command.cmd
co.cmd
a.bat
aa.bat
aaa.bat
aaaa.bat
øyvind.ps1
my file.exe
# Comment based help and keywords
# .ExternalHelp psake.psm1-help.xml
#Requires -Version 2.0 # <-- should #Requires statements be highlighted differently?
<#
.PARAMETER
Something
.SYNOPSISIS
Something
.SYNOPSIS
.INPUTS
#>
# Methods
# Only the first method name is highlighted correctly.
$users.Split(',').Trim()
# Redirection
# Examples from https://technet.microsoft.com/en-us/library/hh847746.aspx
Get-Process > Process.txt
dir *.ps1 >> Scripts.txt
Get-Process none 2> Errors.txt
Get-Process none 2>> Save-Errors.txt
Get-Process none, Powershell 2>&1
Write-Warning "Test!" 3> Warnings.txt
Write-Warning "Test!" 3>> Save-Warnings.txt
Test-Warning 3>&1
Import-Module * -Verbose 4> Verbose.txt
Import-Module * -Verbose 4>> Save-Verbose.txt
Import-Module * -Verbose 4>&1
Write-Debug "Starting" 5> Debug.txt
Write-Debug "Saving" 5>> Save-Debug.txt
Test-Debug 5>&1
Test-Output *> Test-Output.txt
Test-Output *>> Test-Output.txt
Test-Output *>&1
# Special characters
# Should these be highlighted differently?
"`0"
for ($i = 0; $i -le 1; $i++){"`a"}
"backup`b`b out"
"There are two line breaks`n`nhere."
Write-Host "Let's not move`rDelete everything before this point."
"Column1`t`tColumn2`t`tColumn3"
# Range
Get-ChildItem c:\techdocs\[a-l]*.txt
# Other - strange cases
[string]
[string('string')]
[string("string")]
[string(Something = $true)]
[Parameter(Something = $true)]
string('string')
'string'
================================================
FILE: package.json
================================================
{
"name": "EditorSyntax",
"license": "MIT",
"description": "PowerShell language syntax",
"repository": {
"type": "git",
"url": "https://github.com/PowerShell/EditorSyntax.git"
},
"version": "1.0.0",
"engines": {
"atom": "*",
"node": "*"
},
"dependencies": {
"fast-plist": "0.1.2",
"atom-grammar-test": "^0.6.3"
},
"scripts": {
"build-grammar": "node ./tools/build-grammar.js ./PowerShellSyntax.tmLanguage ./grammars/powershell.tmLanguage.json"
}
}
================================================
FILE: spec/powershell-spec.coffee
================================================
grammarTest = require 'atom-grammar-test'
path = require 'path'
#######################################################################
# Scopes
#######################################################################
#
# When modifying or adding scopes do so using the variables below. Tests
# should use the variables and not strings to avoid duplication of work and errors.
#
# If a symbol or construct has different scopes under different conditions make
# sure it makes sense like @ defining a splat and @ defining a hashtable. Otherwise
# aim for consistency as much as possible.
#
# - Scope naming: https://www.sublimetext.com/docs/3/scope_naming.html
# - Language specific: All scopes should end with '.powershell'.
# - Exceptions: when an exception is made for cosmetic or consistency reasons
# leave a comment above the scope with the reasoning.
#
# This file should be used as a reference when working on the 'examples\'. When you
# change a scope make sure you check the example files for any occurances.
# ------------------------------- Setup -------------------------------
atomPackage = 'EditorSyntax'
docScope = 'source.powershell'
# -------------------------- Tokens / Symbols -------------------------
# Comments
singleLineCommentOpen = 'punctuation.definition.comment.powershell' # #
commentBlockOpen = 'punctuation.definition.comment.block.begin.powershell' # <#
commentBlockClose = 'punctuation.definition.comment.block.end.powershell' # #>
# ------------------------------- Basic -------------------------------
# Comments
singleLineComment = 'comment.line.powershell'
commentDocSection = 'comment.block.documentation.powershell'
commentDocKeyword = 'keyword.operator.documentation.powershell'
# ---------------------------- Meta Scopes ----------------------------
# Comments
metaCommentBlock = 'comment.block.powershell'
#######################################################################
# Tests
#######################################################################
describe 'PowerShell Grammar', ->
grammar = null
beforeEach ->
waitsForPromise ->
atom.packages.activatePackage atomPackage,
runs ->
grammar = atom.grammars.grammarForScopeName(docScope)
it 'parses the grammar', ->
expect(grammar).toBeTruthy()
expect(grammar.scopeName).toBe docScope
# Directly test comments as comment tokens are used for atom-grammar-test
describe 'Comments', ->
it 'tokenizes single line comments correctly.', ->
{tokens} = grammar.tokenizeLine '# This is a comment.'
expect(tokens[0]).toEqual value: '#', scopes: [docScope, singleLineComment, singleLineCommentOpen]
expect(tokens[1]).toEqual value: ' This is a comment.', scopes: [docScope, singleLineComment]
it 'tokenizes comment blocks correctly.', ->
lines = grammar.tokenizeLines '''
<#
This is a comment block
#>
<#
# This is still a comment block
#>
'''
expect(lines[0][0]).toEqual value: '<#', scopes: [docScope, metaCommentBlock, commentBlockOpen]
expect(lines[1][0]).toEqual value: ' This is a comment block', scopes: [docScope, metaCommentBlock]
expect(lines[2][0]).toEqual value: '#>', scopes: [docScope, metaCommentBlock, commentBlockClose]
expect(lines[3][0]).toEqual value: '<#', scopes: [docScope, metaCommentBlock, commentBlockOpen]
expect(lines[4][0]).toEqual value: '# This is still a comment block', scopes: [docScope, metaCommentBlock]
expect(lines[5][0]).toEqual value: '#>', scopes: [docScope, metaCommentBlock, commentBlockClose]
describe 'Automated tests', ->
describe 'syntax_test_Function.ps1', ->
grammarTest path.join(__dirname, 'testfiles/syntax_test_Function.ps1')
describe 'syntax_test_Class.ps1', ->
grammarTest path.join(__dirname, 'testfiles/syntax_test_Class.ps1')
describe 'syntax_test_TheBigTestFile.ps1', ->
grammarTest path.join(__dirname, 'testfiles/syntax_test_TheBigTestFile.ps1')
================================================
FILE: spec/testfiles/syntax_test_Class.ps1
================================================
# SYNTAX TEST "source.powershell"
using namespace system.management.automation
# <- keyword.control.using.powershell
# ^ keyword.other.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.powershell
# Define a class
class TypeName
# <- storage.type.powershell
# ^ entity.name.function
{
# Property with validate set
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[ValidateSet("val1", "Val2")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[string] $P1
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^^ variable.other.readwrite.powershell
# Static property
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^ comment.line.powershell
static [hashtable] $P2
# <- storage.modifier.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^^ variable.other.readwrite.powershell
# Hidden property does not show as result of Get-Member
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
hidden [int] $P3
# <- storage.modifier.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^^ variable.other.readwrite.powershell
# Constructor
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^ comment.line.powershell
TypeName ([string] $s) {
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
$this.P1 = $s
# <- punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
}
# Static method
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^ comment.line.powershell
static [void] MemberMethod1([hashtable] $h) {
# <- storage.modifier.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^^^^^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
[TypeName]::P2 = $h
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
}
# Instance method
# <- punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^ comment.line.powershell
[int] MemberMethod2([int] $i) {
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
$this.P3 = $i
# <- punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
return $this.P3
# <- keyword.control.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^ support.variable.automatic.powershell
# ^^ variable.other.member.powershell
}
}
================================================
FILE: spec/testfiles/syntax_test_Function.ps1
================================================
# SYNTAX TEST "source.powershell"
using module Microsoft.PowerShell.Management
# <- keyword.control.using.powershell
# ^ keyword.other.powershell
# ^ variable.parameter.powershell
<#
# <- punctuation.definition.comment.block.begin.powershell
.Synopsis
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Short description
.DESCRIPTION
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Long description
.EXAMPLE
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Example of how to use this cmdlet
.EXAMPLE
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Another example of how to use this cmdlet
.INPUTS
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Inputs to this cmdlet (if any)
.OUTPUTS
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
Output from this cmdlet (if any)
.NOTES
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
General notes
.COMPONENT
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
The component this cmdlet belongs to
.ROLE
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
The role this cmdlet belongs to
.FUNCTIONALITY
# <- constant.string.documentation.powershell
# ^ keyword.operator.documentation.powershell
The functionality that best describes this cmdlet
This should not be considered documentaton -> .role
# ^ not:keyword.operator.documentation.powershell
#>
# <- punctuation.definition.comment.block.end.powershell
function Verb-Noun {
# <- meta.function storage.type
# ^ meta.function entity.name.function.powershell
[CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell string.quoted.single.powershell
SupportsShouldProcess = $true,
# ^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
PositionalBinding = $false,
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^^ meta.attribute.powershell constant.language.powershell
HelpUri = 'http://www.microsoft.com/',
# ^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell string.quoted.single.powershell
ConfirmImpact = 'Medium')]
# ^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[Alias()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[OutputType([String])]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^^^^^^ meta.attribute.powershell storage.type.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
Param
# <- keyword.control.powershell
(
# <- punctuation.section.group.begin.powershell
# Param1 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(Mandatory=$true,
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromPipeline=$true,
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromPipelineByPropertyName = $true,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromRemainingArguments=$false,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
Position=0,
# ^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ParameterSetName = 'Parameter Set 1')]
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNullOrEmpty()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNull()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNullOrEmpty()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateCount(0,5)]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateSet("sun", "moon", "earth")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[Alias("p1")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
$Param1,
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.other.powershell
# Param2 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(ParameterSetName='Parameter Set 1')]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[AllowNull()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[AllowEmptyCollection()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[AllowEmptyString()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateScript({$true})]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.scriptblock.powershell meta.attribute.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.scriptblock.powershell constant.language.powershell
# ^ meta.scriptblock.powershell meta.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateRange(0,5)]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[int32]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
$Param2,
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.other.powershell
# Param3 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(ParameterSetName='Another Parameter Set')]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidatePattern("[a-z]*")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateLength(0,15)]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[String]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
$Param3,
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.other.powershell
# Param4 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(ParameterSetName='Parameter Set 1')]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateScript({Test-Path $_})] #Make sure cmdlets don't break highlighting
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell meta.scriptblock.powershell
# ^^^^^^^^^ meta.scriptblock.powershell support.function.powershell
# ^ meta.scriptblock.powershell punctuation.definition.variable.powershell
# ^ meta.scriptblock.powershell support.variable.automatic.powershell
# ^ meta.attribute.powershell meta.scriptblock.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[string]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
$Param4,
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.other.powershell
# Param5 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(ParameterSetName='Parameter Set 1')]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidatePattern('(?=^.{1,254}$)(^(?:(?!\d+\.)[a-zA-Z0-9_\-]{1,63}\.?)+(?:[a-zA-Z]{2,})$)')] # this regex shouldn't break highlighting
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
# ^ comment.line.powershell punctuation.definition.comment.powershell
# ^ comment.line.powershell
[string]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
$Param5
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
)
# <- punctuation.section.group.end.powershell
Begin
# <- keyword.control.powershell
{
}
Process {
# <- keyword.control.powershell
if ($pscmdlet.ShouldProcess("Target", "Operation")) {
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^^^^^ support.variable.automatic.powershell
# ^^^^^^^^^^^^^ variable.other.member.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.group.end.powershell
}
}
End {
# <- keyword.control.powershell
}
Clean {
# <- keyword.control.powershell
}
}
================================================
FILE: spec/testfiles/syntax_test_TheBigTestFile.ps1
================================================
# SYNTAX TEST "source.powershell"
using namespace System.Management.Automation
# <- keyword.control.using.powershell
# ^ keyword.other.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.parameter.powershell
#Requires -PSSnapin DiskSnapin -Version 1.2
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^ meta.requires.powershell variable.parameter.powershell
#Requires -PSSnapin DiskSnapin
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Version 3
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^ meta.requires.powershell variable.parameter.powershell
#Requires -Version 3.0
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Version 3 -RunAsAdministrator
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^^^^^^^^^^^^ meta.requires.powershell keyword.other.powershell
#Requires -RunAsAdministrator
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^^^^^^^^^^^^ meta.requires.powershell keyword.other.powershell
#Requires -Modules PSWorkflow
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Modules PSWorkflow -ThisIsInvalid
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^^^^^^^ meta.requires.powershell
#Requires -Modules PSWorkflow, ActiveDirectory
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Modules PSWorkflow,ActiveDirectory
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -ShellId MyLocalShell
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -PSEdition Core
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Assembly System
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^ meta.requires.powershell variable.parameter.powershell
#Requires -Modules PSWorkflow, @{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"}
# <- punctuation.definition.comment.powershell
# ^ meta.requires.powershell keyword.control.requires.powershell
# ^^^^^^^^ meta.requires.powershell keyword.other.powershell
# ^^^^^^^^^^ meta.requires.powershell variable.parameter.powershell
# ^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell variable.other.readwrite.powershell
# ^ meta.requires.powershell meta.hashtable.powershell
# ^^^^^^^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell string.quoted.double.powershell
# ^ meta.requires.powershell meta.hashtable.powershell punctuation.terminator.statement.powershell
# ^^^^^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell variable.other.readwrite.powershell
# ^ meta.requires.powershell meta.hashtable.powershell
# ^^^^^^^^^ meta.requires.powershell meta.hashtable.powershell string.quoted.double.powershell
throw "Do not run this file!"
# <- keyword.control.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
# Stop parsing
& tool.exe /arg1 'value' /arg2 $value --% /arg3 $value /arg4 "value" # Comment
# <- keyword.operator.other.powershell
# ^^^^^^^^ support.function.powershell
# ^ ^ keyword.operator.assignment.powershell
# ^^^ keyword.control.powershell
# ^^ ^^ ^^ ^^ ^ ^ string.unquoted.powershell
# Automatic variables
$_, $$, $^, $?
# <- punctuation.definition.variable.powershell
# <- support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# ^ punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
$args
# <- punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
$error
# <- punctuation.definition.variable.powershell
# ^ support.constant.variable.powershell
$home
# <- punctuation.definition.variable.powershell
# ^ support.constant.variable.powershell
$foreach
# <- punctuation.definition.variable.powershell
# ^ support.variable.automatic.powershell
# Normal variables
$variable
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
$script:variable
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ storage.modifier.scope.powershell
# ^ variable.other.readwrite.powershell
$ENV:ComputerName
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ support.variable.drive.powershell
# ^ variable.other.readwrite.powershell
${variable}
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# <- punctuation.section.braces.begin.powershell
# ^^^^^^^^ variable.other.readwrite.powershell
# ^ punctuation.section.braces.end.powershell
${script:variable}
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# <- punctuation.section.braces.begin.powershell
# ^ storage.modifier.scope.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.braces.end.powershell
# Variable properties should be highlighted
$variable.Name
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^^^^ variable.other.member.powershell
# In double-quoted strings, only the variable should be highlighted, not the property
"This is my $variable.Name!"
# <- punctuation.definition.string.begin.powershell string.quoted.double.powershell
# ^^^^^^^^^^ ^^^^^^^ string.quoted.double.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^^^^^ variable.other.readwrite.powershell
# ^ punctuation.definition.string.end.powershell
# When used in a subexpression, both should be highlighted
"This is my $($variable.Name)!"
# <- punctuation.definition.string.begin.powershell string.quoted.double.powershell
# ^^^^^^^^^^ ^^ string.quoted.double.powershell
# ^^ punctuation.section.embedded.substatement.begin.powershell
# ^ punctuation.section.embedded.substatement.end.powershell
# ^^^^^^^^^^^^^^^^^ meta.embedded.substatement.powershell
# ^ keyword.other.substatement.powershell
# ^ punctuation.definition.variable.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
# ^^^^^^^^ variable.other.readwrite.powershell
# ^^^^ variable.other.member.powershell
# ^ punctuation.definition.string.end.powershell
# $ENV:ComputerName should be highlighted
"This is the name of my computer: $ENV:ComputerName"
# <- punctuation.definition.string.begin.powershell string.quoted.double.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^ support.variable.drive.powershell
# ^^^^^^^^^^^^ variable.other.readwrite.powershell
# ^ punctuation.definition.string.end.powershell
# Here as well
"This is the name of my computer: ${ENV:ComputerName}"
# <- punctuation.definition.string.begin.powershell string.quoted.double.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ string.quoted.double.powershell
# ^ punctuation.definition.variable.powershell
# ^ punctuation.section.braces.begin.powershell
# ^^^^ support.variable.drive.powershell
# ^^^^^^^^^^^^ variable.other.readwrite.powershell
# ^ punctuation.definition.string.end.powershell
# @splat references only work in argument mode, should not highlight in strings
"This is a @double quoted string."
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell
# double check scopes for automatic variables in strings
"$_ $$ $Pwd"
# ^ support.variable.automatic.powershell
# ^ support.variable.automatic.powershell
# ^ support.variable.automatic.powershell
# Single quotes string
'This is a string'
# <- punctuation.definition.string.begin.powershell string.quoted.single.powershell
# ^^^^^^^^^^^^^^^ string.quoted.single.powershell
# ^ punctuation.definition.string.end.powershell
# Hashtable
$properties = @{
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^ keyword.other.hashtable.begin.powershell
# ^ punctuation.section.braces.begin.powershell
Name = 'Name'
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell
# ^ meta.hashtable.powershell string.quoted.single.powershell
Something = $else
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# Atom-grammar-test is not tokenizing this correctly... Need to test in Atom - TODO
Number = 16
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell
# ^^ meta.hashtable.powershell constant.numeric.integer.powershell
from = 'hello world'
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^ meta.hashtable.powershell string.quoted.single.powershell
hash = @{
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell
# ^ keyword.other.hashtable.begin.powershell
# ^ punctuation.section.braces.begin.powershell
hello = 'world'
# <- meta.hashtable.powershell meta.hashtable.assignment.powershell variable.other.readwrite.powershell
# ^ meta.hashtable.powershell meta.hashtable.assignment.powershell keyword.operator.assignment.powershell
# ^^^^^^^ meta.hashtable.powershell string.quoted.single.powershell
}
# <- punctuation.section.braces.end.powershell
}
# <- punctuation.section.braces.end.powershell
# Spatting
Invoke-Something @properties
# ^^^^^^^^^^^^^^^^ support.function.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ScriptBlock
{Invoke-Something @properties}
# ^ punctuation.section.braces.begin.powershell
# ^^^^^^^^^^^^^^^^ support.function.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.braces.end.powershell
{
# <- punctuation.section.braces.begin.powershell
Invoke-Something @properties
# ^^^^^^^^^^^^^^^^ support.function.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
}
# <- punctuation.section.braces.end.powershell
$sb = {
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.braces.begin.powershell
Invoke-Something @properties
# ^^^^^^^^^^^^^^^^ support.function.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
}
# <- punctuation.section.braces.end.powershell
# Arrays
$a1 = @(1,2,3,4)
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^ keyword.other.array.begin.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
# ^ ^ ^ ^ meta.group.array-expression.powershell constant.numeric.integer.powershell
# ^ ^ ^ meta.group.array-expression.powershell keyword.operator.other.powershell
$a2 = ('one','two','three','four')
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.group.begin.powershell
# ^^^^^ ^^^^^ ^^^^^^^ ^^^^^^ string.quoted.single.powershell
# ^ ^ ^ keyword.operator.other.powershell
# ^ punctuation.section.group.end.powershell
$a3 = $one, $two, $three, $four
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ ^ ^ ^ punctuation.definition.variable.powershell
# ^ ^ ^ ^ ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^ ^ ^ keyword.operator.other.powershell
$a1[0]
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^ constant.numeric.integer.powershell
# ^ punctuation.section.bracket.end.powershell
$a2[-1]
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^ constant.numeric.integer.powershell
# ^ punctuation.section.bracket.end.powershell
$a3[1..2]
# <- punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^ ^ constant.numeric.integer.powershell
# ^^ keyword.operator.range.powershell
# ^ punctuation.section.bracket.end.powershell
@(@($a))
# ^ ^ keyword.other.array.begin.powershell
# ^ ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^^ punctuation.section.group.end.powershell
@(($i = 10); (++$j))
# ^ keyword.other.array.begin.powershell
# ^^ ^ punctuation.section.group.begin.powershell
# ^ ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^^ constant.numeric.integer.powershell
# ^ punctuation.terminator.statement.powershell
# ^^ keyword.operator.assignment.powershell
# ^ ^^ punctuation.section.group.end.powershell
@($i = 10)
# ^ keyword.other.array.begin.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.assignment.powershell
# ^^ constant.numeric.integer.powershell
# ^ punctuation.section.group.end.powershell
$i[($y - 1) + $x]
# ^ ^ ^ punctuation.definition.variable.powershell variable.other.readwrite.powershell
# ^ ^ ^ variable.other.readwrite.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^ punctuation.section.group.begin.powershell
# ^ ^ keyword.operator.assignment.powershell
# ^ constant.numeric.integer.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.bracket.end.powershell
# Single quoted strings
'This is a single quoted string.'
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell
'$This is a single ''quoted'' string.'
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell
'This is a
single quoted string.'
# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell
'This #also'
# ^^^^^^^^^^^^ string.quoted.single.powershell
'$(Invoke-Something)'
# ^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell
'This "string" is nice.'
# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.single.powershell
# Double quoted strings
"This is a double quoted string."
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
"$This is a double ""quoted"" string."
# ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
# ^ punctuation.definition.variable.powershell support.variable.automatic.powershell
# ^^^^ support.variable.automatic.powershell
"This is a
double quoted string."
# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
"This #also"
# ^^^^^^^^^^^^ string.quoted.double.powershell
"$(Invoke-Something)"
# ^ ^ string.quoted.double.powershell
# ^^ punctuation.section.embedded.substatement.begin.powershell
# ^ punctuation.section.embedded.substatement.end.powershell
# ^^^^^^^^^^^^^^^^^^^ meta.embedded.substatement.powershell
# ^ keyword.other.substatement.powershell
# ^ punctuation.section.group.begin.powershell
# ^ interpolated.complex.source.powershell support.function.powershell
# ^ punctuation.section.group.end.powershell
"This 'string' is nice."
# ^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.powershell
# Double quoted here-string, white space at end of start token allowed
@"
# <- string.quoted.double.heredoc.powershell
# <- string.quoted.double.heredoc.powershell
$This is a 'double quoted'
# <- punctuation.definition.variable.powershell
# ^ string.quoted.double.heredoc.powershell support.variable.automatic.powershell
Isn't it ""nice""??
# ^^ not:constant.character.escape.powershell
There is no @platting here!
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell
"@
# <- string.quoted.double.heredoc.powershell
# <- string.quoted.double.heredoc.powershell
# Single quoted here-string, white space at end of start token allowed
@'
# <- string.quoted.single.heredoc.powershell
# <- string.quoted.single.heredoc.powershell
$This is a ''single quoted''
# ^^ not:constant.character.escape.powershell
# <- not:punctuation.definition.variable.powershell
# ^ string.quoted.single.heredoc.powershell not:support.variable.automatic.powershell
Isn't it "nice"??
There is no @platting here!
# ^ not:punctuation.definition.variable.powershell
# ^ not:variable.other.readwrite.powershell
'@
# <- string.quoted.single.heredoc.powershell
# <- string.quoted.single.heredoc.powershell
# Numeric constants
-3
# ^^ constant.numeric.integer.powershell
.5
# ^^ constant.numeric.integer.powershell
+.5
# ^^^ constant.numeric.integer.powershell
1.
# ^ constant.numeric.integer.powershell
# ^ source.powershell
1.d
# ^^^ constant.numeric.integer.powershell
1.lGB
# ^^^ constant.numeric.integer.powershell
# ^^ keyword.other.powershell
1.e+12d
# ^^^ ^^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
1e+12d
# ^^ ^^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
1.5
# ^^^ constant.numeric.integer.powershell
-1.5
# ^^^^ constant.numeric.integer.powershell
-3 + -2
# ^^ ^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
-3+-2
# ^^ ^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
3++2
# ^ ^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
+2
# ^^ constant.numeric.integer.powershell
-3+-
# ^^ constant.numeric.integer.powershell
# ^^ keyword.operator.assignment.powershell
10/-10
# ^^ ^^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
10/-10D
# ^^ ^^^^ constant.numeric.integer.powershell
# ^ keyword.operator.assignment.powershell
-10.002L
# ^^^^^^^^ constant.numeric.integer.powershell
$x..5.40D
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^^ keyword.operator.range.powershell
# ^^^^^ constant.numeric.integer.powershell
-500..-495
# ^^^^ ^^^^ constant.numeric.integer.powershell
# ^^ keyword.operator.range.powershell
$true..3
# ^ punctuation.definition.variable.powershell
# ^^^^ constant.language.powershell
# ^^ keyword.operator.range.powershell
# ^ constant.numeric.integer.powershell
-2..$null
# ^^ constant.numeric.integer.powershell
# ^^ keyword.operator.range.powershell
# ^ punctuation.definition.variable.powershell constant.language.powershell
# ^^^^ constant.language.powershell
-3..3
# ^^ ^ constant.numeric.integer.powershell
# ^^ keyword.operator.range.powershell
1..3
# ^ ^ constant.numeric.integer.powershell
# ^^ keyword.operator.range.powershell
6,10,-3
# ^ ^^ ^^ constant.numeric.integer.powershell
# ^ ^ keyword.operator.other.powershell
0x476
# ^^^^^ constant.numeric.hex.powershell
+0x20
# ^^^^^ constant.numeric.hex.powershell
-0x20
# ^^^^^ constant.numeric.hex.powershell
# Types
[string]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
[string[]]
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^ punctuation.section.bracket.end.powershell
[int32]
# <- punctuation.section.bracket.begin.powershell
# ^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
[System.Collections.Generic.Dictionary[[System.String, mscorlib],[System.Management.Automation.ParameterMetadata,System.Management.Automation]]]
# <- punctuation.section.bracket.begin.powershell
# ^ ^ ^ ^ ^ storage.type.powershell
# ^^ ^ punctuation.section.bracket.begin.powershell
# ^ ^^^ punctuation.section.bracket.end.powershell
[System.Array+SZArrayEnumerator]
# <- punctuation.section.bracket.begin.powershell
# ^ ^ storage.type.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.bracket.end.powershell
[int]::MinValue
# <- punctuation.section.bracket.begin.powershell
# ^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
[System.DateTime]::Parse('2016/09/21')
# <- punctuation.section.bracket.begin.powershell
# ^^^^^^^^^^^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
# Commands (functions)
Invoke-Something -foobar
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
Invoke-Something -foobar value
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
Invoke-Something -foobar:$true
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^ constant.language.powershell
Invoke-Something -foobar: $true
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
Invoke-Something -p1 v1 -p2 10 -p3 'value' -switch -verbose
# <- support.function.powershell
# ^ ^ ^ ^ ^ keyword.operator.assignment.powershell
# ^^ constant.numeric.integer.powershell
# ^ source.powershell
Invoke-Something (1..20 | Invoke-Something) -p2 'value'
# <- support.function.powershell
Invoke-Something -p1 v2 -p2 30 | Invoke-Something -switch
# <- support.function.powershell
# ^ ^ ^ keyword.operator.assignment.powershell
# ^^ constant.numeric.integer.powershell
# ^ keyword.operator.other.powershell
# ^ support.function.powershell
# ^ source.powershell
Invoke-Something -p1 {
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.braces.begin.powershell
Invoke-Something -foobar:$true
# ^ support.function.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^^^^ constant.language.powershell
} | Invoke-Something
# <- punctuation.section.braces.end.powershell
# ^ keyword.operator.other.powershell
# ^ support.function.powershell
Invoke-Something -p1 value `
# <- support.function.powershell
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.other.powershell
-p2 14.4 `
# ^ keyword.operator.assignment.powershell
# ^^^^ constant.numeric.integer.powershell
# ^ keyword.operator.other.powershell
-p3 $value | Invoke-Something -verbose
# ^ ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ keyword.operator.other.powershell
# ^^^^^^^^^^^^^^^^ support.function.powershell
# Commands (Built-in variables)
ls *.ps1 -recurse
# ^ ^ keyword.operator.assignment.powershell
# Commands (executable files)
. .\scripts\myscript.ps1 -parameter 'value'
# <- keyword.operator.other.powershell
# ^ keyword.operator.assignment.powershell
# ^^^^^^^ string.quoted.single.powershell
& tool.exe
# <- keyword.operator.other.powershell
# ^^^^^^^^ support.function.powershell
something.cmd
# <- support.function.powershell
øyvind.com # this should also highlight - TODO
# switch
switch ("fourteen") {}
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^ string.quoted.double.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -CaseSensitive ("fourteen") {}
# <- keyword.control.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.group.begin.powershell
# ^ string.quoted.double.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -Regex ("fourteen") {}
# <- keyword.control.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.group.begin.powershell
# ^ string.quoted.double.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -Wildcard ($a) {}
# <- keyword.control.powershell
# ^ keyword.operator.assignment.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -regex -file .\somefile.txt {}
# <- keyword.control.powershell
# ^ ^ keyword.operator.assignment.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch (3) {}
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^ constant.numeric.integer.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch (4, 2) {}
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^ ^ constant.numeric.integer.powershell
# ^ keyword.operator.other.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -Regex -File $filePath {
# <- keyword.control.powershell
# ^ ^ keyword.operator.assignment.powershell
# ^ punctuation.definition.variable.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
'.' {}
# ^^^ string.quoted.single.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
default {}
# ^^^^^^^ keyword.control.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
}
# <- meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch -Wildcard -CaseSensitive ($something) {
# <- keyword.control.powershell
# ^ ^ keyword.operator.assignment.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
'.' {}
# ^^^ string.quoted.single.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
default {}
# ^^^^^^^ keyword.control.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
}
# <- meta.scriptblock.powershell punctuation.section.braces.end.powershell
switch ('this') {
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^^^^^^ string.quoted.single.powershell
# ^ punctuation.section.group.end.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
'this' {}
# ^^^^^^ string.quoted.single.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
default {}
# ^^^^^^^ keyword.control.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.begin.powershell
# ^ meta.scriptblock.powershell punctuation.section.braces.end.powershell
}
# <- meta.scriptblock.powershell punctuation.section.braces.end.powershell
# Functions and filters
functioN MyFunction{}
# <- storage.type.powershell
# ^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function My-Function {}
# <- storage.type.powershell
# ^^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
Function My.Function{}
# <- storage.type.powershell
# ^^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function My-Function.Other{}
# <- storage.type.powershell
# ^^^^^^^^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function Some.other.function{}
# <- storage.type.powershell
# ^^^^^^^^^^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
FUNCTION MyFunction2 {}
# <- storage.type.powershell
# ^^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function New-File { }
# <- storage.type.powershell
# ^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function New-File ($Name) { }
# <- storage.type.powershell
# ^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
function NewFile($Name) { }
# <- storage.type.powershell
# ^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
filter myfilter($param) {}
# <- storage.type.powershell
# ^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
Filter my-Filter ($param){}
# <- storage.type.powershell
# ^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
# Note that the # in the path should highlight as a comment!
function Test-Drive([string]$roman) {
# <- storage.type.powershell
# ^^^^^^^^^^ entity.name.function.powershell
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.bracket.begin.powershell
# ^^^^^^ storage.type.powershell
# ^ punctuation.section.bracket.end.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
$roman | c:\users\Me\Documents\Programming\F#\test.exe $roman
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ keyword.operator.other.powershell
# ^ punctuation.definition.comment.powershell
# ^ ^ comment.line.powershell
}
# <- punctuation.section.braces.end.powershell
function Verb-Noun
# <- meta.function storage.type
# ^ meta.function entity.name.function.powershell
{
# <- punctuation.section.braces.begin.powershell
Param
# <- keyword.control.powershell
(
# <- punctuation.section.group.begin.powershell
# Param1 help description
# <- comment.line.powershell punctuation.definition.comment.powershell
# ^^^^^^^^^^^^^^^^^^^^^^^ comment.line.powershell
[Parameter(Mandatory=$true,
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromPipeline=$true,
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromPipelineByPropertyName = $true,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ValueFromRemainingArguments=$false,
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell punctuation.definition.variable.powershell
# ^^^^^ meta.attribute.powershell constant.language.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
Position=0,
# ^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
SupportsPaging,
# ^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
ParameterSetName = 'Parameter Set 1')]
# ^^^^^^^^^^^^^^^^ meta.attribute.powershell variable.parameter.attribute.powershell
# ^ meta.attribute.powershell keyword.operator.assignment.powershell
# ^^^^^^^^^^^^^^^^^ meta.attribute.powershell string.quoted.single.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNullOrEmpty()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNull()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateNotNullOrEmpty()]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateCount(0,5)]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^ meta.attribute.powershell constant.numeric.integer.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[ValidateSet("sun", "moon", "earth")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell keyword.operator.other.powershell
# ^^^^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
[Alias("p1")]
# <- meta.attribute.powershell punctuation.section.bracket.begin.powershell
# ^ meta.attribute.powershell support.function.attribute.powershell
# ^ meta.attribute.powershell punctuation.section.group.begin.powershell
# ^^^^ meta.attribute.powershell string.quoted.double.powershell
# ^ meta.attribute.powershell punctuation.section.group.end.powershell
# ^ meta.attribute.powershell punctuation.section.bracket.end.powershell
$Param1
# <- punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
)
# <- punctuation.section.group.end.powershell
# Do Something....
}
# <- punctuation.section.braces.end.powershell
# Class
class Vehicle {
# <- storage.type.powershell
# ^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
Vehicle() {}
# ^ punctuation.section.group.begin.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
Vehicle([string]$Owner) {
# ^ storage.type.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
# ^ punctuation.section.braces.begin.powershell
$this.Owner = $Owner
}
[int]$Mileage
# ^ storage.type.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
[int]$Age
# ^ storage.type.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
[string]$Owner
# ^ storage.type.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
[void]Drive([int]$NumberOfMiles) {
# ^ ^ storage.type.powershell
# ^ punctuation.definition.variable.powershell
# ^ variable.other.readwrite.powershell
$this.Mileage += $NumberOfMiles
# ^ punctuation.definition.variable.powershell
# ^^^^ support.variable.automatic.powershell
# ^ variable.other.member.powershell
# ^^ keyword.operator.assignment.powershell
}
# <- punctuation.section.braces.end.powershell
}
# <- punctuation.section.braces.end.powershell
# Control words
foreach ($item in $collection) {
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^^ keyword.control.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ ^ punctuation.definition.variable.powershell
}
# <- punctuation.section.braces.end.powershell
try { }
# <- keyword.control.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
catch { }
# <- keyword.control.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
# Reserved words
Configuration Crazyness {
# <- storage.type.powershell
# ^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
Node Whatever {
# ^ punctuation.section.braces.begin.powershell
}
# <- punctuation.section.braces.end.powershell
}
# <- punctuation.section.braces.end.powershell
# Redirection
notepad.exe > log.txt
# <- support.function.powershell
# ^ keyword.operator.redirection.powershell
notepad.exe 1> log.txt
# <- support.function.powershell
# ^^ keyword.operator.redirection.powershell
notepad.exe 2>&1
# <- support.function.powershell
# ^^^^ keyword.operator.redirection.powershell
notepad.exe 3>&1
# <- support.function.powershell
# ^^^^ keyword.operator.redirection.powershell
notepad.exe 4>&1
# <- support.function.powershell
# ^^^^ keyword.operator.redirection.powershell
notepad.exe 5>&1
# <- support.function.powershell
# ^^^^ keyword.operator.redirection.powershell
notepad.exe 6>&1
# <- support.function.powershell
# ^^^^ keyword.operator.redirection.powershell
notepad.exe 2>&1> log.txt
# <- support.function.powershell
# ^^^^^ keyword.operator.redirection.powershell
# Operators
if (10 -cgt 100) { }
# <- keyword.control.powershell
# ^ punctuation.section.group.begin.powershell
# ^^ ^^^ constant.numeric.integer.powershell
# ^^^^ keyword.operator.comparison.powershell
# ^ punctuation.section.group.end.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
$a -is $b
# ^ keyword.operator.comparison.powershell
$b -contains $c
# ^ keyword.operator.comparison.powershell
$x -notcontains $c
# ^ keyword.operator.comparison.powershell
$c -in $b
# ^ keyword.operator.comparison.powershell
$c -notin $x
# ^ keyword.operator.comparison.powershell
$a -match $b
# ^ keyword.operator.comparison.powershell
$a -notmatch $b
# ^ keyword.operator.comparison.powershell
$x -like $c
# ^ keyword.operator.comparison.powershell
100 -and 0
# ^ keyword.operator.logical.powershell
# ^ constant.numeric.integer.powershell
$a -ceq 4 -and $a -ine $d -or
# ^ ^ keyword.operator.comparison.powershell
# ^ ^ keyword.operator.logical.powershell
# ^ constant.numeric.integer.powershell
# ^ punctuation.definition.variable.powershell
$c -is [Type]
# ^ keyword.operator.comparison.powershell
# ^ storage.type.powershell
$c -isnot [Type]
# ^ keyword.operator.comparison.powershell
# ^ storage.type.powershell
$c -as [Type]
# ^ keyword.operator.comparison.powershell
# ^ storage.type.powershell
$k = $y -bor $k
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.bitwise.powershell
$x = $y -band $x
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.bitwise.powershell
$z = -bnot $x
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.bitwise.powershell
$l = 1 -shl 10
# ^ keyword.operator.assignment.powershell
# ^ ^^ constant.numeric.integer.powershell
# ^ keyword.operator.bitwise.powershell
$r = 10 -shr 1
# ^ keyword.operator.assignment.powershell
# ^^ ^ constant.numeric.integer.powershell
# ^ keyword.operator.bitwise.powershell
$k = $y -xor $b
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.logical.powershell
$k = $y -bxor $b
# ^ keyword.operator.assignment.powershell
# ^ keyword.operator.bitwise.powershell
$a -icontains $c
# ^ keyword.operator.comparison.powershell
$a -ccontains $c
# ^ keyword.operator.comparison.powershell
$a -iNotContains $c
# ^ keyword.operator.comparison.powershell
$a -cNotContains $c
# ^ keyword.operator.comparison.powershell
$a -cmatch $c
# ^ keyword.operator.comparison.powershell
$x -iMatch $c
# ^ keyword.operator.comparison.powershell
$x -iNotMatch $c
# ^ keyword.operator.comparison.powershell
$a -iLike $b
# ^ keyword.operator.comparison.powershell
$b -cLike $c
# ^ keyword.operator.comparison.powershell
"hey" -cgt "Hey"
# ^ keyword.operator.comparison.powershell
"Hey" -igt "hey"
# ^ keyword.operator.comparison.powershell
"hey" -cge "Hey"
# ^ keyword.operator.comparison.powershell
"Hey" -ige "hey"
# ^ keyword.operator.comparison.powershell
"HEY" -clt "hey"
# ^ keyword.operator.comparison.powershell
"HEY" -ilt "hey"
# ^ keyword.operator.comparison.powershell
"HEY" -cle "hey"
# ^ keyword.operator.comparison.powershell
"HEY" -ile "hey"
# ^ keyword.operator.comparison.powershell
# format
"{0:N2}" -f $a
# ^^^^^^^^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:D8}" -f $a
# ^^^^^^^^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:C2}" -f $a
# ^^^^^^^^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:P0}" -f $a
# ^^^^^^^^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:X0}" -f $a
# ^^^^^^^^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
(1.11).ToString("#.#")
# ^ ^ punctuation.section.group.begin.powershell
# ^^^^ constant.numeric.integer.powershell
# ^ string.quoted.double.powershell
"{1,10} {0,10} {2,10:x}" -f "First", "Second", 255
# ^ ^ ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
# ^^^ constant.numeric.integer.powershell
("{0,6}" -f 4.99), ("{0,6:##.00}" -f 15.9)
# ^ string.quoted.double.powershell
# ^ ^ keyword.operator.string-format.powershell
"{0:R}" -f (1mb/2.0)
# ^^ keyword.other.powershell
# ^ keyword.operator.string-format.powershell
"{0:00.0}" -f 4.12341234
# ^ keyword.operator.string-format.powershell
"{0:##.#}" -f 4.12341234
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:#,#.#}" -f 1234.121234
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:##,,.000}" -f 1048576
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{this is not a #comment}"
# ^ not:comment
"{0:##.#E000}" -f 2.71828
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:#.00'##'}" -f 2.71828
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:POS;NEG;ZERO}" -f -14
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0:$## Please}" -f 14
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0,-8:P1}" -f 1.75
# ^ string.quoted.double.powershell
# ^ keyword.operator.string-format.powershell
"{0,10:N3}{1,10:N3}{2,10:N3}{3,10:N3}" -f 0.2, 0.3, 0.45, 0.91
# ^ keyword.operator.string-format.powershell
'{0:00000.000}' -f 7.125
# ^ string.quoted.single.powershell
# ^ keyword.operator.string-format.powershell
# Misc test cases
Test-Function -Class ClassName
# ^ not:storage.type.powershell
New-Object -TypeName System.Diagnostics.Process
# ^ not:keyword.control.powershell
New-Object -TypeName System.Data
# ^ not:keyword.control.powershell
@("any","array","has").foreach({ $_ })
# <- keyword.other.array.begin.powershell
# ^ meta.group.array-expression.powershell
# ^ keyword.control.powershell
# ^ meta.scriptblock.powershell
@('any','array','has').foreach{ $_ }
# <- keyword.other.array.begin.powershell
# ^ meta.group.array-expression.powershell
# ^ keyword.control.powershell
# ^ meta.scriptblock.powershell
@("any","array","has").where({ $_.Length -gt 3 })
# <- keyword.other.array.begin.powershell
# ^ meta.group.array-expression.powershell
# ^ keyword.control.powershell
# ^ meta.scriptblock.powershell
@("any","array","has").where{ $_.Length -gt 3 }
# <- keyword.other.array.begin.powershell
# ^ meta.group.array-expression.powershell
# ^ keyword.control.powershell
# ^ meta.scriptblock.powershell
$file = join-path $env:SystemDrive "$([System.io.path]::GetRandomFileName()).ps1"
# <- punctuation.definition.variable.powershell
# ^ support.function.powershell
# ^ support.variable.drive.powershell
# ^ variable.other.readwrite.powershell
# ^ string.quoted.double.powershell punctuation.definition.substatement.powershell punctuation.section.embedded.substatement.begin.powershell
# ^ storage.type.powershell
$ScriptBlock | Out-File $file -Force
# <- punctuation.definition.variable.powershell
# ^ keyword.operator.other.powershell
# ^ punctuation.definition.variable.powershell
# ^ keyword.operator.assignment.powershell
workflow w1 {}
# <- storage.type.powershell
# ^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
Workflow work { sequence {} }
# <- storage.type.powershell
# ^ entity.name.function.powershell
# ^ punctuation.section.braces.begin.powershell
# ^^^^^^^^ keyword.control.powershell
# ^ punctuation.section.braces.begin.powershell
# ^ punctuation.section.braces.end.powershell
# ^ punctuation.section.braces.end.powershell
get-thing | Out-WithYou > $null # destroy
# ^ ^ support.function.powershell
# ^ keyword.operator.other.powershell
# ^ keyword.operator.redirection.powershell
# ^ punctuation.definition.variable.powershell
# ^ constant.language.powershell
# ^ punctuation.definition.comment.powershell
"Escaped chars: `", `n, `$, `b, `t, `e, `u{10ffff}, `""
# <- string.quoted.double.powershell
# ^^ ^^ ^^ ^^ ^^ ^^ ^^^^^^^^^^ ^^ string.quoted.double.powershell constant.character.escape.powershell
'But here they''re not escape chars: `", `n, `$, `b, `"'
# ^^ constant.character.escape.powershell
# ^^ ^^ ^^ ^^ ^^ not:constant.character.escape.powershell
"When you call a method: $( get-number | %{ invoke-command $( [string]::format("Like (this{0})","what?") ) $var } )"
# ^ string.quoted.double.powershell punctuation.definition.substatement.powershell punctuation.section.embedded.substatement.begin.powershell
# ^ punctuation.definition.variable.powershell
# ^ keyword.operator.other.powershell
# ^ ^ meta.group.complex.subexpression.powershell punctuation.section.group.begin.powershell
# ^ storage.type.powershell
# ^ ^ meta.group.complex.subexpression.powershell punctuation.section.group.end.powershell
"This is the Debugreference variable: $DebugPreference"
# <- string.quoted.double.powershell
# ^ variable.language.powershell
$ConfirmPreference $DebugPreference $ErrorActionPreference $ErrorView $FormatEnumerationLimit $InformationPreference $LogCommandHealthEvent $LogCommandLifecycleEvent $LogEngineHealthEvent $LogEngineLifecycleEvent $LogProviderHealthEvent $LogProviderLifecycleEvent $MaximumAliasCount $MaximumDriveCount $MaximumErrorCount $MaximumFunctionCount $MaximumHistoryCount $MaximumVariableCount $OFS $OutputEncoding $PSCulture $PSDebugContext $PSDefaultParameterValues $PSEmailServer $PSItem $PSModuleAutoLoadingPreference $PSModuleAutoloadingPreference $PSSenderInfo $PSSessionApplicationName $PSSessionConfigurationName $PSSessionOption $ProgressPreference $VerbosePreference $WarningPreference $WhatIfPreference
# <- variable.language.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 ^ 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 ^ variable.language.powershell ^ variable.language.powershell ^ variable.language.powershell
================================================
FILE: tools/banners.ps1
================================================
function SyntaxBanner {
Write-Host ' ______ _ _ _ _____ _ ' -ForegroundColor Green
Write-Host '| ____| | (_) | / ____| | | ' -ForegroundColor Green
Write-Host '| |__ __| |_| |_ ___ _ _| (___ _ _ _ __ | |_ __ ___ __' -ForegroundColor Green
Write-Host '| __| / _` | | __/ _ \| ''__\___ \| | | | ''_ \| __/ _` \ \/ /' -ForegroundColor Green
Write-Host '| |___| (_| | | || (_) | | ____) | |_| | | | | || (_| |> < ' -ForegroundColor Green
Write-Host '|______\__,_|_|\__\___/|_| |_____/ \__, |_| |_|\__\__,_/_/\_\' -ForegroundColor Green
Write-Host ' __/ | ' -ForegroundColor Green
Write-Host ' |___/ ' -ForegroundColor Green
}
function BuildBanner {
Write-Host '#############################################################' -ForegroundColor Green
Write-Host '# BUILD GRAMMAR #' -ForegroundColor Green
Write-Host '#############################################################' -ForegroundColor Green
}
function TestBanner {
Write-Host '#############################################################' -ForegroundColor Green
Write-Host '# RUN TESTS #' -ForegroundColor Green
Write-Host '#############################################################' -ForegroundColor Green
}
function EndBanner {
Write-Host '#############################################################' -ForegroundColor Green
}
================================================
FILE: tools/build-grammar.js
================================================
/*---------------------------------------------------------------------------------------------
* Licensed under the MIT License. See License.txt in the project root for license information.
*
* Modified for PowerShell\EditorSyntax from Microsoft\vscode (update-grammar.js)
* This script generates the JSON file using the same tools as vscode's build.
*--------------------------------------------------------------------------------------------*/
'use strict';
var path = require('path');
var fs = require('fs');
var plist = require('fast-plist');
exports.update = function (tmlPath, dest) {
console.log('... Reading source file.');
var content = fs.readFileSync(tmlPath).toString();
console.log('... Parsing content.');
var grammar;
grammar = plist.parse(content);
console.log('... Building contents.');
let result = {
information_for_contributors: [
'This file has been converted from source and may not be in line with the official build.',
'The current master branch for this syntax can be found here: https://github.com/PowerShell/EditorSyntax',
'If you want to provide a fix or improvement, please create a pull request against the original repository.'
]
};
result.version = require('child_process')
.execSync('git rev-parse HEAD')
.toString().trim()
let keys = ['name', 'scopeName', 'comment', 'injections', 'patterns', 'repository'];
for (let key of keys) {
if (grammar.hasOwnProperty(key)) {
result[key] = grammar[key];
}
}
var dirname = path.dirname(dest);
if (!fs.existsSync(dirname)) {
console.log('... Creating directory: ' + dirname);
fs.mkdirSync(dirname);
}
fs.writeFileSync(dest, JSON.stringify(result, null, '\t'));
console.log('[Finished] File written to: ' + dest);
};
if (path.basename(process.argv[1]) === 'build-grammar.js') {
console.log('[Starting] Converting ' + process.argv[2] + ' to json.');
exports.update(process.argv[2], process.argv[3]);
}
================================================
FILE: tools/build-helpers.ps1
================================================
function DownloadAtom {
Write-Host "Downloading latest Atom release..."
$Source = "https://atom.io/download/windows_zip?channel=stable"
$Destination = Join-Path . '\atom.zip'
try {
Invoke-WebRequest $Source -OutFile $Destination -ErrorAction Stop
}
catch {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
Write-Host "Atom download finished..."
ExtractAtom
}
function ExtractAtom {
Write-Host "Extracting Atom.zip"
$ZipFile = Join-Path (Split-Path $PSScriptRoot -Parent) '\atom.zip'
$OutPath = Resolve-Path .
try {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile, $OutPath)
}
catch {
$PSCmdlet.ThrowTerminatingError($PSItem)
}
Write-Host "Atom extracted..."
Remove-Item $ZipFile -Force
Write-Host "Atom.zip deleted..."
}
filter ParseJasmine {
switch -regex ($_) {
^\s+at {
''
break
}
^\s+it {
$_ -replace '^(\s+)(it)', '$1[-] It'
break
}
^\s+Expected {
$_ -replace '^(\s*)(Expected.*?)\s(instead found .*)', "`$1`$2`n`$1`$3"
break
}
default {
$_
}
}
}
function ExitWithCode {
param (
$ExitCode
)
$Host.SetShouldExit($exitcode)
exit
}
function RunSpecs {
Write-Host "Running specs..."
$specpath = Join-Path . '\spec'
if (Test-Path $specpath) {
& $script:ATOM_EXE_PATH --test $specpath *>&1 | ParseJasmine
}
else {
throw '.\spec\ not found.'
}
if ($LASTEXITCODE -ne 0) {
if ($Env:APPVEYOR) {
ExitWithCode -exitcode $LASTEXITCODE
}
else {
throw "One or more tests failed."
}
}
}