Skip to content

Commit aec13fa

Browse files
committed
Add dedicated contexts for workflows
1 parent 025c8f9 commit aec13fa

File tree

3 files changed

+190
-26
lines changed

3 files changed

+190
-26
lines changed

PowerShell.sublime-syntax

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ contexts:
5050
- include: classes
5151
- include: expressions
5252
- include: functions
53+
- include: workflows
5354
- include: desired-state-configurations
5455

5556
- match: \B\.(?= )
@@ -364,7 +365,7 @@ contexts:
364365
###[ FUNCTIONS ]###############################################################
365366

366367
functions:
367-
- match: ^\s*(?i)(function|filter|workflow)(?=\s)
368+
- match: ^\s*(?i)(function|filter)(?=\s)
368369
captures:
369370
1: keyword.declaration.function.powershell
370371
push: [function-body, function-inline-params, function-name]
@@ -419,6 +420,7 @@ contexts:
419420
- include: statements
420421

421422
expect-function-context:
423+
- meta_scope: meta.block.powershell
422424
- match: \{
423425
scope: punctuation.section.block.begin.powershell
424426
push: inside-function-context
@@ -427,7 +429,7 @@ contexts:
427429
inside-function-context:
428430
- match: \}
429431
scope: punctuation.section.block.end.powershell
430-
pop: 1
432+
pop: 2
431433
- include: workflow-execution-contexts
432434
- include: statements
433435

@@ -449,12 +451,6 @@ contexts:
449451
- match: '='
450452
scope: keyword.operator.assignment.powershell
451453

452-
workflow-execution-contexts:
453-
- match: \b(?i:inlinescript){{kebab_break}}
454-
scope: keyword.control.context.powershell
455-
- match: \b(?i:parallel|sequence){{kebab_break}}
456-
scope: keyword.control.flow.powershell
457-
458454
attributes:
459455
- match: (\[)\s*({{attributes}})
460456
captures:
@@ -481,6 +477,37 @@ contexts:
481477
2: keyword.operator.assignment.powershell
482478
- include: expressions
483479

480+
###[ WORKFLOWS ]###############################################################
481+
482+
workflows:
483+
- match: ^\s*(?i)(workflow)(?=\s)
484+
captures:
485+
1: keyword.declaration.function.powershell
486+
push: [function-body, function-name]
487+
488+
workflow-body:
489+
- meta_scope: meta.function.powershell
490+
- match: \{
491+
scope: punctuation.section.block.begin.powershell
492+
push: inside-workflow-body
493+
with_prototype:
494+
- include: workflow-execution-contexts
495+
- include: else-pop
496+
497+
inside-workflow-body:
498+
- match: \}
499+
scope: punctuation.section.block.end.powershell
500+
pop: 2
501+
- include: statements
502+
503+
workflow-execution-contexts:
504+
- match: \b(?i:inlinescript){{kebab_break}}
505+
scope: keyword.control.context.powershell
506+
push: expect-function-context
507+
- match: \b(?i:parallel|sequence){{kebab_break}}
508+
scope: keyword.control.flow.powershell
509+
push: expect-function-context
510+
484511
###[ DESIRED STATE CONFIGURATIONS ]############################################
485512

486513
desired-state-configurations:

Tests/syntax_test_PowerShell.ps1

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,24 +1619,6 @@ $ScriptBlock | Out-File $file -Force
16191619
# ^ punctuation.definition.variable
16201620
# ^ punctuation.definition.parameter
16211621
# ^^^^^^ variable.parameter.option
1622-
workflow w1 {}
1623-
#^^^^^^^^^^^^^ meta.function.powershell
1624-
#^^^^^^^ keyword.declaration.function.powershell
1625-
# ^^ entity.name.function.powershell
1626-
# @@ definition
1627-
# ^ punctuation.section.block.begin.powershell
1628-
# ^ punctuation.section.block.end.powershell
1629-
Workflow work { sequence {} }
1630-
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
1631-
#^^^^^^^ keyword.declaration.function.powershell
1632-
# ^^^^ entity.name.function.powershell
1633-
# @@@@ definition
1634-
# ^ punctuation.section.block.begin.powershell
1635-
# ^^^^^^^^ keyword.control.flow.powershell
1636-
# ^^ meta.block.powershell
1637-
# ^ punctuation.section.braces.begin.powershell
1638-
# ^ punctuation.section.braces.end.powershell
1639-
# ^ punctuation.section.block.end.powershell
16401622
function get-something {}
16411623
# @@@@@@@@@@@@@ definition
16421624
function Out-WithYou {}

Tests/syntax_test_Workflow.ps1

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax"
2+
3+
"<- Exit the imports context block"
4+
5+
workflow w1 {}
6+
#^^^^^^^^^^^^^^^^^ meta.function.powershell
7+
# ^^^^^^^^ keyword.declaration.function.powershell
8+
# ^^ entity.name.function.powershell
9+
# @@ definition
10+
# ^ punctuation.section.block.begin.powershell
11+
# ^ punctuation.section.block.end.powershell
12+
Workflow work { sequence {} }
13+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
14+
# ^^^^^^^^ keyword.declaration.function.powershell
15+
# ^^^^ entity.name.function.powershell
16+
# @@@@ definition
17+
# ^ punctuation.section.block.begin.powershell
18+
# ^^^^^^^^^^^ meta.block.powershell
19+
# ^^^^^^^^ keyword.control.flow.powershell
20+
# ^ punctuation.section.block.begin.powershell
21+
# ^ punctuation.section.block.end.powershell
22+
# ^ punctuation.section.block.end.powershell
23+
24+
workflow Test-Workflow {
25+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
26+
# ^^^^^^^^ keyword.declaration.function.powershell
27+
# ^^^^^^^^^^^^^ entity.name.function.powershell
28+
# @@@@@@@@@@@@@ definition
29+
# ^ punctuation.section.block.begin.powershell
30+
parallel {
31+
#^^^^^^^^^^^^^^^^^ meta.function.powershell
32+
# ^^^^^^^^ keyword.control.flow.powershell
33+
# ^ punctuation.section.block.begin.powershell
34+
Get-Process
35+
# @@@@@@@@@@@ reference
36+
Get-Service
37+
#^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
38+
# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell
39+
# @@@@@@@@@@@ reference
40+
}
41+
}
42+
43+
44+
workflow Test-Workflow {
45+
# @@@@@@@@@@@@@ definition
46+
$a = 3
47+
#^^^^^^^^^^^^^ meta.function.powershell
48+
# ^^ variable.other.readwrite.powershell
49+
# ^ punctuation.definition.variable.powershell
50+
# ^ keyword.operator.assignment.powershell
51+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
52+
53+
## Without $Using, the $a workflow variable isn't visible
54+
## in inline script.
55+
inlinescript {"Inline A0 = $a"}
56+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
57+
# ^^^^^^^^^^^^ keyword.control.context.powershell
58+
# ^ punctuation.section.block.begin.powershell
59+
# ^^^^^^^^^^^^^^^^ meta.string.interpolated.powershell
60+
# ^^^^^^^^^^^^^ string.quoted.double.powershell
61+
# ^ punctuation.definition.string.begin.powershell
62+
# ^^ meta.interpolation.powershell variable.other.readwrite.powershell
63+
# ^ punctuation.definition.variable.powershell
64+
# ^ string.quoted.double.powershell punctuation.definition.string.end.powershell
65+
# ^ punctuation.section.block.end.powershell
66+
67+
## $Using imports the variable and its current value.
68+
inlinescript {"Inline A1 = $Using:a"}
69+
}
70+
Test-Workflow
71+
# @@@@@@@@@@@@@ reference
72+
73+
74+
workflow Test-Workflow {
75+
# @@@@@@@@@@@@@ definition
76+
$a = 3
77+
78+
## Changes to the inlinescript variable value don't
79+
## change the workflow variable.
80+
inlinescript {
81+
$a = $Using:a+1;
82+
"Inline A = $a"
83+
}
84+
"Workflow A = $a"
85+
86+
## To change the variable in workflow scope, return the
87+
## new value.
88+
$a = inlinescript {$b = $Using:a+1; $b}
89+
"Workflow New A = $a"
90+
}
91+
Test-Workflow
92+
# @@@@@@@@@@@@@ reference
93+
94+
95+
workflow Test-Workflow {
96+
# @@@@@@@@@@@@@ definition
97+
$ie = inlinescript {
98+
$ie = New-Object -ComObject InternetExplorer.Application -Property @{navigate2="www.microsoft.com"}
99+
# @@@@@@@@@@ reference
100+
101+
$ie.Visible = $true
102+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
103+
# ^^^ variable.other.readwrite.powershell
104+
# ^ punctuation.definition.variable.powershell
105+
# ^ punctuation.accessor.dot.powershell
106+
# ^^^^^^^ variable.other.member.powershell
107+
# ^ keyword.operator.assignment.powershell
108+
# ^^^^^ constant.language.boolean.true.powershell
109+
# ^ punctuation.definition.variable.powershell
110+
}
111+
112+
$ie
113+
}
114+
Test-Workflow
115+
# @@@@@@@@@@@@@ reference
116+
117+
118+
workflow Test-Workflow {
119+
# @@@@@@@@@@@@@ definition
120+
parallel {
121+
Get-Process
122+
# @@@@@@@@@@@ reference
123+
Get-Service
124+
#^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
125+
# ^^^^^^^^^^^ meta.function-call.powershell support.function.powershell
126+
# @@@@@@@@@@@ reference
127+
128+
sequence {
129+
# ^ meta.function.powershell meta.block.powershell meta.block.powershell punctuation.section.block.begin.powershell
130+
$Hotfix = Get-Content 'D:\HotFixes\Required.txt'
131+
# @@@@@@@@@@@ reference
132+
foreach ($h in $Hotfix) {'D:\Scripts\Verify-Hotfix' -Hotfix $h}
133+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.block.powershell meta.block.powershell
134+
# ^^^^^^^ keyword.control.loop.for.powershell
135+
# ^^^^^^^^^^^^^^^ meta.group.powershell
136+
# ^ punctuation.section.group.begin.powershell
137+
# ^^ variable.other.readwrite.powershell
138+
# ^ punctuation.definition.variable.powershell
139+
# ^^ keyword.control.loop.in.powershell
140+
# ^^^^^^^ variable.other.readwrite.powershell
141+
# ^ punctuation.definition.variable.powershell
142+
# ^ punctuation.section.group.end.powershell
143+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.block.powershell
144+
# ^ punctuation.section.braces.begin.powershell
145+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
146+
# ^ punctuation.definition.string.begin.powershell
147+
# ^ punctuation.definition.string.end.powershell
148+
# ^^^^^^^ variable.parameter.option.powershell
149+
# ^ punctuation.definition.parameter.powershell
150+
# ^^ variable.other.readwrite.powershell
151+
# ^ punctuation.definition.variable.powershell
152+
# ^ punctuation.section.braces.end.powershell
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)