-
Notifications
You must be signed in to change notification settings - Fork 81
New syntax def #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
New syntax def #127
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
feb9da6
delete file
guillermooo a1b07ce
new syntax def format
guillermooo 9bb7633
fix test
guillermooo 61b5637
start adding block comments
guillermooo 2db228b
match embedded docs titles
guillermooo 270a6e9
refine scopes for embedded docs
guillermooo 2c6854f
add embedded docs items
guillermooo 1be6e8c
start adding script blocks
guillermooo b6d8a7b
fixes
guillermooo d8c495f
add variables
guillermooo bc17877
start implementing double quoted strings
guillermooo 11bcc1b
wip: more strings
guillermooo 203df89
highlight more stuff
guillermooo 57f4e58
add operators
guillermooo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
%YAML 1.2 | ||
--- | ||
|
||
name: PowerShell | ||
file_extensions: [ps1, psm1, psd1] | ||
scope: source.powershell | ||
|
||
contexts: | ||
main: | ||
- match: \b(if|else|for|while)\b | ||
scope: keyword.control.powershell | ||
- include: requires-statement | ||
- include: comment-line | ||
- match: "<#" | ||
scope: start.definition.comment.block.powershell | ||
push: comment-block | ||
- match: \{ | ||
scope: start.definition.script-block.powershell | ||
push: script-block | ||
- include: operators-all | ||
- include: variables | ||
- include: strings | ||
|
||
comment-block: | ||
- meta_scope: comment.block.powershell | ||
- match: "#>" | ||
scope: end.definition.comment.block.powershell | ||
pop: true | ||
- match: (?i)^\s*(\.)(synopsis|description|example|inputs|outputs|notes|link|component|functionality) | ||
scope: embedded.documentation.title.powershell | ||
captures: | ||
1: keyword.embedded.documentation.title.start.powershell | ||
2: constant.numeric.embedded.documentation.title.name.powershell | ||
- match: (?i)^\s*(\.)(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+([a-z0-9-_]+) | ||
scope: embedded.documentation.title.powershell | ||
captures: | ||
1: keyword.embedded.documentation.title.start.powershell | ||
2: constant.numeric.embedded.documentation.title.name.powershell | ||
3: keyword.embedded.documentation.title.argument.powershell | ||
|
||
script-block: | ||
- include: main | ||
- meta_scope: script-block.powershell | ||
- match: \} | ||
scope: end.definition.script-block.powershell | ||
pop: true | ||
|
||
variables: | ||
- match: (?i)(\$)\b(true|false)\b | ||
scope: variable.powershell | ||
captures: | ||
1: keyword.start.variable.name.powershell | ||
2: constant.numeric.variable.name.powershell | ||
- match: (?i)(\$)(?:(script|global):)?([\w_]+) | ||
scope: variable.powershell | ||
captures: | ||
1: keyword.start.variable.name.powershell | ||
2: support.function.variable.scope.powershell | ||
3: variable.name.powershell | ||
- match: \$\{ | ||
scope: keyword.start.variable.name.powershell | ||
push: variable-name-long | ||
|
||
variable-name-long: | ||
- meta_scope: variable.powershell | ||
- match: "(?i)(script|global):" | ||
captures: | ||
1: support.function.variable.scope.powershell | ||
- match: "[^}]+" | ||
scope: variable.name.powershell | ||
- match: \} | ||
scope: keyword.end.variable.name.powershell | ||
pop: true | ||
|
||
strings: | ||
- match: "@'" | ||
push: string-heredoc-single-quoted | ||
- match: '@"' | ||
push: string-heredoc-double-quoted | ||
- match: '"' | ||
push: string-double-quoted | ||
- match: "'" | ||
push: string-single-quoted | ||
|
||
string-double-quoted: | ||
- meta_scope: string.quoted.double.powershell | ||
- match: '"' | ||
pop: true | ||
- include: string-interpolation | ||
- include: variables | ||
- include: string-double-quoted-escape-sequences | ||
|
||
string-single-quoted: | ||
- meta_scope: string.quoted.single.powershell | ||
- match: "'" | ||
pop: true | ||
- include: string-double-quoted-escape-sequences | ||
- include: variables | ||
|
||
string-heredoc-single-quoted: | ||
- meta_scope: string.heredoc.single.quoted.powershell | ||
- include: variables | ||
- match: "''" | ||
scope: constant.character.escape.powershell | ||
- match: "'@" | ||
pop: true | ||
|
||
string-heredoc-double-quoted: | ||
- meta_scope: string.heredoc.double.quoted.powershell | ||
- include: variables | ||
- match: "`." | ||
- match: '"@' | ||
pop: true | ||
|
||
string-double-quoted-escape-sequences: | ||
- match: "`[0abnfrvt\"'$`]" | ||
scope: constant.character.escape.powershell | ||
|
||
string-interpolation: | ||
- match: \$\( | ||
scope: keyword.start.interpolated.subexpression.powershell | ||
push: string-interpolation-subexpression | ||
|
||
string-interpolation-subexpression: | ||
- meta_scope: string.interpolated.content.powershell | ||
- include: main | ||
- match: \) | ||
scope: keyword.end.interpolated.subexpression.powershell | ||
pop: true | ||
|
||
operators-logical: | ||
- match: (?<!\w)-([ci]?[lg][te]|eq|ne) | ||
scope: keyword.operator.logical.powershell | ||
|
||
comment-line: | ||
- match: (?<![\\-])#.*$ | ||
scope: comment.line.number-sign.powershell | ||
|
||
requires-statement: | ||
- match: (?i)^\s*(#)(requires)\s+-(Version\s+\d(.\d+)?|Assembly\s+(.*)|Module\s+(.*)|PsSnapIn\s+(.*)|ShellId\s+(.*)) | ||
scope: comment.requires.statement.powershell | ||
captures: | ||
1: comment.start.requires.statement.powershell | ||
2: keyword.requires.powershell | ||
|
||
operators-all: | ||
- include: operators-comparison | ||
- include: operators-comparison-more | ||
- include: operators-unary | ||
- include: operators-logical | ||
|
||
operators-comparison: | ||
- match: (?i)(?<!\w)-(?i:is(?:not)?|as)\b | ||
scope: keyword.operator.comparison.powershell | ||
|
||
operators-comparison-more: | ||
- match: (?i)(?<!\w)-[ic]?(?:eq|ne|[gl][te]|(?:not)?(?:like|match|contains|in)|replace)(?!\p{L}) | ||
scope: keyword.operator.comparison.powershell | ||
|
||
operators-unary: | ||
- match: (?i)(?<!\w)-(?:join|split)(?!\p{L})|! | ||
scope: keyword.operator.unary.powershell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SYNTAX TEST "Packages/PowerShell/Support/PowerShell.sublime-syntax" | ||
|
||
// <- source.powershell | ||
|
||
if ($True) { "huzza!" } | ||
// <- keyword.control.powershell | ||
|
||
// Tests for variables ======================================= | ||
|
||
$foo | ||
// <- keyword.start.variable.name.powershell | ||
// <- variable.powershell variable.name.powershell | ||
|
||
${ I'm a variable name } | ||
// <- keyword.start.variable.name.powershell | ||
// <- variable.powershell variable.name.powershell | ||
|
||
$script:foo | ||
// <- support.function.variable.scope.powershell | ||
|
||
${global: I'm a variable name } | ||
// <- support.function.variable.scope.powershell | ||
|
||
// Tests for script blocks ======================================= | ||
|
||
{ } | ||
// <- start.definition.script-block.powershell | ||
//^ script-block.powershell | ||
|
||
{ { } } | ||
// ^ script-block.powershell script-block.powershell | ||
|
||
// Tests for block comments ======================================= | ||
|
||
<# | ||
// <- source.powershell start.definition.comment.block.powershell | ||
// <- source.powershell comment.block.powershell | ||
foo | ||
// <- source.powershell comment.block.powershell | ||
#> | ||
// <- source.powershell end.definition.comment.block.powershell | ||
// <- source.powershell | ||
|
||
<# | ||
.HELLO | ||
// <- source.powershell comment.block.powershell | ||
|
||
.SYNOPSIS | ||
// <- keyword.embedded.documentation.title.start.powershell | ||
|
||
.description | ||
// ^ constant.numeric.embedded.documentation.title.name.powershell | ||
|
||
.parameter foo | ||
// ^ keyword.embedded.documentation.title.argument.powershell | ||
#> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filter belongs here, I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've messed this up. This change wasn't supposed to end up here. I'll try to fix it later.