Skip to content

Commit 46cfcfd

Browse files
committed
Group commands contexts
1 parent c35c6f0 commit 46cfcfd

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

PowerShell.sublime-syntax

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ contexts:
5050
- include: expressions
5151
- include: functions
5252

53-
# TODO: Continue into a command statement
5453
- match: \B\.(?= )
5554
scope: support.function.source.powershell
5655

@@ -118,8 +117,6 @@ contexts:
118117
- include: groups
119118
- include: arrays
120119
- include: subexpressions
121-
- match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b
122-
scope: variable.function.powershell
123120

124121
# Consume a string with a trailing dot
125122
# to prevent members with particular names from being recognized as keywords.
@@ -178,20 +175,6 @@ contexts:
178175
3: keyword.other.region.end.powershell
179176
4: meta.fold.end.powershell
180177

181-
commands:
182-
# The "Verb-Noun" pattern
183-
- match: |-
184-
(?x:
185-
(?:[\w\\:-]*\\)? # Path stuff
186-
{{command_verbs}} # Approved verbs
187-
\-\w+? # Any "noun"
188-
(?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff
189-
)
190-
scope: meta.function-call.powershell support.function.powershell
191-
# Builtin cmdlets with reserved verbs
192-
- match: \b(?i:(?:foreach|where|sort|tee)-object)\b
193-
scope: support.function.powershell
194-
195178
script-blocks:
196179
- match: (%)?(\{)
197180
captures:
@@ -215,6 +198,33 @@ contexts:
215198
# Back to normal stuff
216199
- include: statements
217200

201+
###[ COMMANDS ]################################################################
202+
203+
commands:
204+
- include: commands-verb-noun
205+
- include: commands-reserved
206+
- include: script-invocation
207+
208+
commands-verb-noun:
209+
# The "Verb-Noun" pattern
210+
- match: |-
211+
(?x:
212+
(?:[.\w\\/:-]*[\\/])? # Path stuff
213+
{{command_verbs}} # Approved verbs
214+
\-\w+? # Any "noun"
215+
(?:\.(?i:exe|cmd|bat|ps1))?\b # More path stuff
216+
)
217+
scope: meta.function-call.powershell support.function.powershell
218+
219+
commands-reserved:
220+
# Builtin cmdlets with reserved verbs
221+
- match: \b(?i:(?:foreach|where|sort|tee)-object)\b
222+
scope: support.function.powershell
223+
224+
script-invocation:
225+
- match: \b[\w.\\/-]+\.(?i:exe|com|cmd|bat|ps1)\b
226+
scope: variable.function.powershell
227+
218228
###[ USINGS ]##################################################################
219229

220230
using-directives:

Tests/syntax_test_PowerShell.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,11 +840,14 @@ ls *.ps1 -recurse
840840
# ^^^^^^^^ variable.parameter.option
841841

842842
# Commands (executable files)
843-
. .\scripts\myscript.ps1 -parameter 'value'
844-
# <- support.function.source.powershell
845-
# ^ punctuation.definition.parameter
846-
# ^^^^^^^^^^ variable.parameter.option
847-
# ^^^^^^^ string.quoted.single
843+
. .\scripts\Test-Foo.ps1 -parameter 'value'
844+
# ^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.powershell support.function.powershell
845+
# @@@@@@@@@@@@@@@@@@@@@@ reference
846+
# ^^^^^^^^^^ variable.parameter.option.powershell
847+
# ^ punctuation.definition.parameter.powershell
848+
# ^^^^^^^ meta.string.powershell string.quoted.single.powershell
849+
# ^ punctuation.definition.string.begin.powershell
850+
# ^ punctuation.definition.string.end.powershell
848851
& tool.exe
849852
# <- keyword.operator.background
850853
# ^^^^^^^^ variable.function

0 commit comments

Comments
 (0)