Skip to content

Commit be90881

Browse files
committed
Stack function scopes over strings
1 parent a559d9a commit be90881

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

PowerShell.sublime-syntax

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,27 +318,50 @@ contexts:
318318

319319
commands-quoted:
320320
- match: (?={{single_quote}})
321-
push: [in-command, expect-single-quoted-command]
321+
push: [in-command, single-quoted-command-string]
322322
- match: (?={{double_quote}})
323-
push: [in-command, expect-double-quoted-command]
323+
push: [in-command, double-quoted-command-string]
324324

325-
expect-single-quoted-command:
326-
- meta_scope: meta.function-call.powershell variable.function.powershell
327-
- include: single-quoted-strings
325+
single-quoted-command-string:
326+
- match: '{{single_quote}}'
327+
scope: punctuation.definition.string.begin.powershell
328+
push: inside-single-quoted-command-string
328329
- include: immediately-pop
329330

330-
expect-double-quoted-command:
331-
- meta_scope: meta.function-call.powershell variable.function.powershell
332-
- include: double-quoted-strings
331+
inside-single-quoted-command-string:
332+
- meta_include_prototype: false
333+
- meta_scope: meta.string.powershell string.quoted.single.powershell meta.function-call.powershell variable.function.powershell
334+
- match: '{{single_quote}}{2}'
335+
scope: constant.character.escape.powershell
336+
- match: '{{single_quote}}'
337+
scope: punctuation.definition.string.end.powershell
338+
pop: 1
339+
- include: path-punctuation
340+
341+
double-quoted-command-string:
342+
- match: '{{double_quote}}'
343+
scope: punctuation.definition.string.begin.powershell
344+
push: inside-double-quoted-command-string
333345
- include: immediately-pop
334346

347+
inside-double-quoted-command-string:
348+
- meta_include_prototype: false
349+
- meta_scope: meta.string.interpolated.powershell string.quoted.double.powershell meta.function-call.powershell variable.function.powershell
350+
- match: '{{double_quote}}{2}'
351+
scope: constant.character.escape.powershell
352+
- include: escape-sequences
353+
- match: '{{double_quote}}'
354+
scope: punctuation.definition.string.end.powershell
355+
pop: 1
356+
- include: string-interpolations
357+
- include: path-punctuation
358+
335359
command-freeform:
336360
- match: '{{identifier_simple}}'
337361
scope: meta.function-call.powershell variable.function.powershell
338362
push: in-command
339363

340364
in-command:
341-
# - meta_scope: region.pinkish
342365
- include: redirection
343366
- include: command-ending-sequences
344367
- include: cli-parameters
@@ -349,8 +372,7 @@ contexts:
349372
- meta_scope: string.unquoted.powershell
350373
- match: (?=[\s#|>;,]|$)
351374
pop: 1
352-
- match: '[\\/:.]'
353-
scope: punctuation.separator.powershell
375+
- include: path-punctuation
354376
- include: escape-sequences
355377

356378
command-ending-sequences:
@@ -1212,6 +1234,10 @@ contexts:
12121234

12131235
###[ COMPONENTS ]##############################################################
12141236

1237+
path-punctuation:
1238+
- match: '[:/\\.]+'
1239+
scope: punctuation.separator.powershell
1240+
12151241
line-continuations:
12161242
- match: (`)\n
12171243
captures:

Tests/syntax_test_PowerShell.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,12 +922,23 @@ $a3[1..2]
922922
# ^^^^^^^^^^ meta.function-call.powershell variable.function.powershell
923923
# @@@@@@@@@@ reference
924924

925-
& ".\script name with spaces.ps1"
925+
& '.\script name with spaces.ps1'
926926
# ^ keyword.operator.call.powershell
927-
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.powershell variable.function.powershell meta.string.interpolated.powershell string.quoted.double.powershell
927+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell meta.function-call.powershell variable.function.powershell
928+
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ reference
928929
# ^ punctuation.definition.string.begin.powershell
930+
# ^^ punctuation.separator.powershell
931+
# ^ punctuation.separator.powershell
929932
# ^ punctuation.definition.string.end.powershell
933+
934+
& ".\script name with spaces.ps1"
935+
# ^ keyword.operator.call.powershell
936+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell meta.function-call.powershell variable.function.powershell
930937
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ reference
938+
# ^ punctuation.definition.string.begin.powershell
939+
# ^^ punctuation.separator.powershell
940+
# ^ punctuation.separator.powershell
941+
# ^ punctuation.definition.string.end.powershell
931942

932943
# switch
933944
switch ("fourteen") {}

0 commit comments

Comments
 (0)