Skip to content

Commit bea280e

Browse files
matteocoderdeathaxe
and
deathaxe
authored
Don't match keywords if they are preceded by a dot and add the 'sequence' keyword (#186)
* Change keyword matching regex Keywords (with the exception of 'where' and 'foreach') should not be considered as such if they are preceded by a '.'. The tests relative to keywords used as members or methods now pass. 'process' is now considered a block keyword. * Add 'sequence' keyword Also make the relative syntax test pass. * Change test assertion in Function syntax test Now the test reflects the change of the 'process' keyword from uncategorised to block. * Change Parameter matching regex to match 'PositionalBinding' The relevant test in the function syntax test now passes. * Consume string with a trailing dot before checking for keywords This makes negative lookbehind assertions on keywords unnecessary. * Add scope to matched unquoted strings Co-authored-by: deathaxe <[email protected]> * Match word boundary to avoid highlighting invalid arguments Co-authored-by: deathaxe <[email protected]> --------- Co-authored-by: deathaxe <[email protected]>
1 parent da9cdd7 commit bea280e

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

PowerShell.sublime-syntax

+11-4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ contexts:
7575
- include: main
7676
- match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b
7777
scope: variable.function.powershell
78+
# Consume a string with a trailing dot
79+
# to prevent members with particular names from being recognized as keywords.
80+
- match: \b[\w-]+(?=\.)
81+
scope: variable.other.object.powershell
82+
push: members
7883
# Exceptions
7984
- match: \b(?i:throw){{kebab_break}}
8085
scope: keyword.control.exception.raise.powershell
@@ -100,6 +105,8 @@ contexts:
100105
# Begin/End
101106
- match: \b(?i:begin){{kebab_break}}
102107
scope: keyword.context.block.begin.powershell
108+
- match: \b(?i:process){{kebab_break}}
109+
scope: keyword.context.block.process.powershell
103110
- match: \b(?i:end){{kebab_break}}
104111
scope: keyword.context.block.end.powershell
105112
- match: \b(?i:clean){{kebab_break}}
@@ -129,7 +136,7 @@ contexts:
129136
- match: \b(?i:(?:dynamic)?param){{kebab_break}}
130137
scope: keyword.declaration.parameter.powershell # This scope is not standard
131138
# Uncategorized keywords
132-
- match: \b(?i:data|default|define|from|in|inlinescript|parallel|process){{kebab_break}}
139+
- match: \b(?i:data|default|define|from|in|inlinescript|parallel|sequence){{kebab_break}}
133140
scope: keyword.control.powershell
134141
- match: \B--%\B
135142
scope: keyword.control.powershell
@@ -292,10 +299,10 @@ contexts:
292299
(?xi:
293300
\b(
294301
Mandatory | ValueFromPipeline(?:ByPropertyName)?
295-
| ValueFromRemainingArguments | Position
302+
| ValueFromRemainingArguments | Position(?:alBinding)?
296303
| (?:Default)?ParameterSetName | SupportsShouldProcess | SupportsPaging
297-
| PositionalBinding | HelpUri | ConfirmImpact | HelpMessage
298-
)
304+
| HelpUri | ConfirmImpact | HelpMessage
305+
)\b
299306
\s*(=)?
300307
)
301308
captures:

Tests/syntax_test_Function.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function Verb-Noun {
376376
{
377377
}
378378
Process {
379-
# <- keyword.control
379+
# <- keyword.context.block.process
380380
if ($pscmdlet.ShouldProcess("Target", "Operation")) {
381381
# <- keyword.control
382382
# ^ punctuation.section.group.begin

Tests/syntax_test_PowerShell.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,12 @@ New-Object -TypeName System.Diagnostics.Process
13601360
# ^^^^^^^ - keyword.control
13611361
New-Object -TypeName System.Data
13621362
# ^^^^ - keyword.control
1363+
New-Object -TypeName Sy-stem.if
1364+
# ^^ - keyword.control
1365+
New-Object -TypeName S_ystem.Clean
1366+
# ^^^^^ - keyword.control
1367+
New-Object -TypeName Sy_stem-.Throw
1368+
# ^^^^^ - keyword.control
13631369
echo `"test`"
13641370
# ^^^^^^^^^ - string.quoted
13651371
# ^^ constant.character.escape

0 commit comments

Comments
 (0)