Skip to content
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

[WIP] Rewrite syntax definition in YAML #165

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c9b3123
Direct migration to .sublime-syntax
michaelblyons Feb 1, 2020
b701521
Start rearranging and changing scopes
michaelblyons Feb 1, 2020
134b809
Adapted tests from PowerShell/EditorSyntax
michaelblyons Feb 1, 2020
46adfad
Push a little further to scope rectification
michaelblyons Feb 1, 2020
a0a24e9
Overhaul numbers and option flags
michaelblyons Feb 1, 2020
07acf91
Replace silly non-cap groups with `\w`. Further tweak numbers
michaelblyons Feb 1, 2020
9571835
New Regex-Eng compatible. Most of the tests pass.
michaelblyons Feb 1, 2020
b9533ca
Rebuild `#Requires`
michaelblyons Feb 1, 2020
1aca5da
Fixup integers with MB
michaelblyons Feb 1, 2020
d83caa6
Tinker with support files
michaelblyons Feb 1, 2020
43a437b
Escape characters are valid without string quoting
michaelblyons Feb 1, 2020
1cddc0b
Break keyword.control into semantic scopes. Use kebab_break. Readability
michaelblyons Feb 4, 2020
5236ffd
Push a context for membership
michaelblyons Feb 4, 2020
300ebcf
Multiline regex formatting
michaelblyons Apr 10, 2021
f5b8461
Fix first_line_match NL chomp
michaelblyons Apr 11, 2021
60b2779
License dates
michaelblyons Apr 16, 2021
4462d17
Convert ISE Nostalgia to sublime-color-scheme
michaelblyons Apr 16, 2021
562711f
Syntax test workflow
michaelblyons Apr 16, 2021
8b530af
Syntax test references
michaelblyons Apr 17, 2021
7f9cb43
Add indentation rules and test
keith-hall May 13, 2021
bc47f5b
Clear string scope for subexpressions within strings
jwortmann May 2, 2022
abca63f
Tweak syntax tests
jwortmann May 10, 2022
3179654
Add source.powershell.embedded for subexpressions
jwortmann May 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 107 additions & 77 deletions PowerShell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ file_extensions:
- psd1

first_line_match: |
(?x)
(?x:
michaelblyons marked this conversation as resolved.
Show resolved Hide resolved
^\#!.*\b(?:pwsh|powershell)\b
| ^\# \s* -\*- [^*]* mode: \s* powershell [^*]* -\*-
)

variables:
dec_digits: (?:[\d_]*\d)
Expand Down Expand Up @@ -252,9 +253,13 @@ contexts:
- match: |-
(?xi:
(\[)\s*
(CmdletBinding|Alias|OutputType|Parameter
|Validate(?:Count|NotNull(?:OrEmpty)?|Range|Pattern|Length|Set|Script)
|Allow(?:Null|Empty(?:Collection|String))
(
CmdletBinding | Alias | OutputType | Parameter
| Validate
(?:
Count | NotNull(?:OrEmpty)? | Range | Pattern | Length | Set
| Script)
| Allow(?: Null | Empty(?: Collection | String ))
)\b
)
captures:
Expand Down Expand Up @@ -282,10 +287,12 @@ contexts:
- include: main
- match: |-
(?xi:
\b(Mandatory|ValueFromPipeline(?:ByPropertyName)?
|ValueFromRemainingArguments|Position
|(?:Default)?ParameterSetName|SupportsShouldProcess
|PositionalBinding|HelpUri|ConfirmImpact|HelpMessage)
\b(
Mandatory | ValueFromPipeline(?:ByPropertyName)?
| ValueFromRemainingArguments | Position
| (?:Default)?ParameterSetName | SupportsShouldProcess
| PositionalBinding | HelpUri | ConfirmImpact | HelpMessage
)
\s*(=)
)
captures:
Expand All @@ -306,17 +313,21 @@ contexts:
- match: |-
(?x:
(?:[\w\\:-]*\\)? # Path stuff
\b(?i:Add|Approve|Assert|Backup|Block|Build|Checkpoint|Clear|Close # "Official" Verbs
|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
\b(?i:
Add | Approve | Assert | Backup | Block | Build | Checkpoint # "Official" Verbs
| Clear | Close | Compare | Complete | Compress | Confirm | Connect
| Convert | ConvertFrom | ConvertTo | Copy | Debug | Deny | Deploy
| Disable | Disconnect | Dismount | Edit | Enable | Enter | Exit
| Expand | Export | Find | Format | Get | Grant | Group | Hide
| Import | Initialize | Install | Invoke | Join | Limit | Lock
| Measure | Merge | Mount | Move | New | Open | Optimize | Out | Ping
| Pop | Protect | Publish | Push | Read | Receive | Redo | Register
| Remove | Rename | Repair | Request | Reset | Resize | Resolve
| Restart | Restore | Resume | Revoke | Save | Search | Select | Send
| Set | Show | Skip | Split | Start | Step | Stop | Submit | Suspend
| Switch | Sync | Test | Trace | Unblock | Undo | Uninstall | Unlock
| Unprotect | Unpublish | Unregister | Update | Use | Wait | Watch
| Write
)
\-\w+? # Any "noun"
(?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff
Expand All @@ -342,8 +353,11 @@ contexts:
- match: |-
(?xi:
^\s*(\.)
(Component|Description|Example|ForwardHelpTargetName|Functionality
|Inputs|Notes|Outputs|RemoteHelpRunSpace|Role|Synopsis)
(
Component | Description | Example | ForwardHelpTargetName
| Functionality | Inputs | Notes | Outputs | RemoteHelpRunSpace
| Role | Synopsis
)
)
scope: comment.documentation.embedded.powershell
captures:
Expand Down Expand Up @@ -542,14 +556,14 @@ contexts:
(?:
(?:
(?:(\.(?!\.))\d*) # No `_` after the `.`
{{dec_exponent}}?
|{{dec_exponent}}
{{dec_exponent}}?
| {{dec_exponent}}
)
({{float_suffix}})?
|({{float_suffix}})
| ({{float_suffix}})
)
|\b{{dec_digits}}\.(?!\.)
|(\.)\d+
| \b{{dec_digits}}\.(?!\.)
| (\.)\d+
)
({{bytes_unit}}\b)?
)
Expand Down Expand Up @@ -599,50 +613,57 @@ contexts:
captures:
1: punctuation.definition.variable.powershell
- match: |-
(?x:(
(\$)
(?i:ExecutionContext|Host|Home|Is(?:CoreCLR|Linux|Windows|MacOS)
|PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable)
|ShellID)
(?xi:
(\$)
(?:
ExecutionContext | Host | Home | IsCoreCLR | IsLinux | IsWindows
| IsMacOS | PID | Profile | PsCommandPath | PsHome | PsScriptRoot
| PsUiCulture | PsVersionTable | ShellID
)
)
scope: support.constant.variable.powershell
captures:
1: support.constant.variable.powershell
2: punctuation.definition.variable.powershell
1: punctuation.definition.variable.powershell
push: members
- match: |-
(?x:(
(\$)
(?:
[$^?_]
|(?i:Args|ConsoleFileName|Error|Event|EventArgs|EventSubscriber
|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel
|Ps(?:BoundParameters|Cmdlet|Culture|DebugContext|Item)|Pwd
|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b
)
(?xi:
(\$)
(?:
[$^?_]
| (?:
Args | ConsoleFileName | Error | Event | EventArgs
| EventSubscriber | ForEach | Input | LastExitCode | Matches
| MyInvocation | NestedPromptLevel | PsBoundParameters | PsCmdlet
| PsCulture | PsDebugContext | PsItem | Pwd | Sender | SourceArgs
| SourceEventArgs | StackTrace | Switch | This
)\b
)
)
scope: variable.language.powershell
captures:
1: variable.language.powershell
2: punctuation.definition.variable.powershell
1: punctuation.definition.variable.powershell
push: members
- match: |-
(?x:(
(?xi:
(\$)
(?i:
(?:Confirm|Debug|ErrorAction|Information|Progress|Verbose|Warning # *Preference
|WhatIf)Preference
|Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count
|Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event
|Ps(?:DebugContext|DefaultParameterValues|EmailServer # Ps*
|ModuleAutoloadingPreference|SenderInfo|SessionApplicationName
|SessionConfigurationName|SessionOption)
|ErrorView|FormatEnumerationLimit|OFS|OutputEncoding)
(?:
(?:
Confirm | Debug | ErrorAction | Information | Progress | Verbose # *Preference
| Warning | WhatIf
)
Preference
| Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count
| Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event
| PsDebugContext | PsDefaultParameterValues | PsEmailServer
| PsModuleAutoloadingPreference | PsSenderInfo
| PsSessionApplicationName | PsSessionConfigurationName
| PsSessionOption | ErrorView | FormatEnumerationLimit | OFS
| OutputEncoding
)
)
scope: variable.language.powershell
captures:
1: variable.language.powershell
2: punctuation.definition.variable.powershell
1: punctuation.definition.variable.powershell
push: members
- match: ((\$|@)(?i:(global|local|private|script|using|workflow):\w+))
captures:
Expand Down Expand Up @@ -680,43 +701,52 @@ contexts:
captures:
1: punctuation.definition.variable.powershell
- match: |-
(?x:
(?xi:
(\$)
(?i:ExecutionContext|Host|Home|Is(?:CoreCLR|Linux|Windows|MacOS)
|PID|Profile|Ps(?:CommandPath|Home|ScriptRoot|UiCulture|VersionTable)
|ShellID
)\b
(?:
ExecutionContext | Host | Home | IsCoreCLR | IsLinux | IsWindows
| IsMacOS | PID | Profile | PsCommandPath | PsHome | PsScriptRoot
| PsUiCulture | PsVersionTable | ShellID
)
)
scope: support.constant.variable.powershell
captures:
1: punctuation.definition.variable.powershell
- match: |-
(?x:
(?xi:
(\$)
(?:
[$^?_]
|(?i:Args|ConsoleFileName|Error|Event|EventArgs|EventSubscriber
|ForEach|Input|LastExitCode|Matches|MyInvocation|NestedPromptLevel
|Ps(?:BoundParameters|Cmdlet|Culture|DebugContext|Item)|Pwd
|Sender|SourceArgs|SourceEventArgs|StackTrace|Switch|This)\b
| (?:
Args | ConsoleFileName | Error | Event | EventArgs
| EventSubscriber | ForEach | Input | LastExitCode | Matches
| MyInvocation | NestedPromptLevel | PsBoundParameters | PsCmdlet
| PsCulture | PsDebugContext | PsItem | Pwd | Sender | SourceArgs
| SourceEventArgs | StackTrace | Switch | This
)\b
)
)
scope: variable.language.powershell
captures:
1: punctuation.definition.variable.powershell
- match: |-
(?x:
(?xi:
(\$)
(?i:
(?:Confirm|Debug|ErrorAction|Information|Progress|Verbose|Warning # *Preference
|WhatIf)Preference
|Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count
|Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event
|Ps(?:DebugContext|DefaultParameterValues|EmailServer # Ps*
|ModuleAutoloadingPreference|SenderInfo|SessionApplicationName
|SessionConfigurationName|SessionOption)
|ErrorView|FormatEnumerationLimit|OFS|OutputEncoding)
)\b
(?:
(?:
Confirm | Debug | ErrorAction | Information | Progress | Verbose # *Preference
| Warning | WhatIf
)
Preference
| Maximum(?:Alias|Drive|Error|Function|History|Variable)Count # Maximum*Count
| Log(?:Command|Engine|Provider)(?:Health|Lifecycle)Event # Log*Event
| PsDebugContext | PsDefaultParameterValues | PsEmailServer
| PsModuleAutoloadingPreference | PsSenderInfo
| PsSessionApplicationName | PsSessionConfigurationName
| PsSessionOption | ErrorView | FormatEnumerationLimit | OFS
| OutputEncoding
)
)
scope: variable.language.powershell
captures:
1: punctuation.definition.variable.powershell
Expand Down
2 changes: 1 addition & 1 deletion Tests/syntax_test_PowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ $variable.Name.Method( )
# ^^^^^^^^^^^^ variable.other.readwrite
# ^ punctuation.definition.string.end

# @splat references only work in argument mode, should not highlight in strings
# The @splat references only work in argument mode, should not highlight in strings
"This is a @double quoted string."
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double
# ^ - punctuation.definition.variable
Expand Down