Skip to content

Commit 025c8f9

Browse files
committed
Add dedicated contexts for DSC
Desired State Configuration
1 parent fa4de92 commit 025c8f9

File tree

3 files changed

+178
-19
lines changed

3 files changed

+178
-19
lines changed

PowerShell.sublime-syntax

Lines changed: 62 additions & 3 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: desired-state-configurations
5354

5455
- match: \B\.(?= )
5556
scope: support.function.source.powershell
@@ -363,13 +364,13 @@ contexts:
363364
###[ FUNCTIONS ]###############################################################
364365

365366
functions:
366-
- match: ^\s*(?i)(function|filter|configuration|workflow)(?=\s)
367+
- match: ^\s*(?i)(function|filter|workflow)(?=\s)
367368
captures:
368369
1: keyword.declaration.function.powershell
369370
push: [function-body, function-inline-params, function-name]
370371

371372
function-name:
372-
- match: (?:(global|local|script|private):)?({{identifier_function}}+)
373+
- match: (?:(global|local|script|private):)?({{identifier_function}})
373374
captures:
374375
1: storage.modifier.scope.powershell
375376
2: entity.name.function.powershell
@@ -442,8 +443,11 @@ contexts:
442443
pop: 1
443444
- include: comma-separators
444445
- include: attributes
445-
- include: types
446+
- include: types-without-members
446447
- include: variables-without-members
448+
- include: literals
449+
- match: '='
450+
scope: keyword.operator.assignment.powershell
447451

448452
workflow-execution-contexts:
449453
- match: \b(?i:inlinescript){{kebab_break}}
@@ -477,6 +481,61 @@ contexts:
477481
2: keyword.operator.assignment.powershell
478482
- include: expressions
479483

484+
###[ DESIRED STATE CONFIGURATIONS ]############################################
485+
486+
desired-state-configurations:
487+
- match: ^\s*(?i)(configuration)(?=\s)
488+
captures:
489+
1: keyword.declaration.function.powershell
490+
push:
491+
- desired-state-configuration-body
492+
- desired-state-configuration-name
493+
494+
desired-state-configuration-name:
495+
- match: '{{identifier_function}}'
496+
scope: entity.name.function.powershell
497+
- match: (?=[{(])
498+
pop: 1
499+
500+
desired-state-configuration-body:
501+
- meta_scope: meta.function.powershell
502+
- match: \{
503+
scope: punctuation.section.block.begin.powershell
504+
push: inside-desired-state-configuration-body
505+
- include: else-pop
506+
507+
inside-desired-state-configuration-body:
508+
- match: \}
509+
scope: punctuation.section.block.end.powershell
510+
pop: 2
511+
512+
- match: \b(?i:Param){{kebab_break}}
513+
scope: keyword.declaration.parameter.powershell # This scope is not standard
514+
push: expect-param-context
515+
516+
- match: \b(?i:Node){{kebab_break}}
517+
scope: keyword.context.block.powershell
518+
push: expect-node-context
519+
520+
- include: attributes
521+
522+
expect-node-context:
523+
- match: \{
524+
scope: punctuation.section.block.begin.powershell
525+
push: inside-node-context
526+
- include: expressions
527+
- include: else-pop
528+
529+
inside-node-context:
530+
- match: \}
531+
scope: punctuation.section.block.end.powershell
532+
pop: 2
533+
- match: \b((?i:WindowsFeature))\s+({{identifier_csharp}})
534+
captures:
535+
1: keyword.other.powershell
536+
2: entity.name.label.powershell
537+
- include: expressions
538+
480539
###[ VARIABLES ]###############################################################
481540

482541
variables:

Tests/syntax_test_DSC.ps1

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax"
2+
3+
"<- Exit the imports context block"
4+
5+
Configuration MyDscConfiguration {
6+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
7+
# ^^^^^^^^^^^^^ keyword.declaration.function.powershell
8+
# ^^^^^^^^^^^^^^^^^^ entity.name.function.powershell
9+
# ^ punctuation.section.block.begin.powershell
10+
Node "TEST-PC1" {
11+
#^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
12+
# ^^^^ keyword.context.block.powershell
13+
# ^^^^^^^^^^ meta.string.interpolated.powershell string.quoted.double.powershell
14+
# ^ punctuation.definition.string.begin.powershell
15+
# ^ punctuation.definition.string.end.powershell
16+
# ^ punctuation.section.block.begin.powershell
17+
WindowsFeature MyFeatureInstance {
18+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
19+
# ^^^^^^^^^^^^^^ keyword.other.powershell
20+
# ^^^^^^^^^^^^^^^^^ entity.name.label.powershell
21+
# ^ meta.block.powershell punctuation.section.braces.begin.powershell
22+
Ensure = 'Present'
23+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell meta.block.powershell
24+
# ^ keyword.operator.assignment.powershell
25+
# ^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
26+
# ^ punctuation.definition.string.begin.powershell
27+
# ^ punctuation.definition.string.end.powershell
28+
Name = 'RSAT'
29+
}
30+
WindowsFeature My2ndFeatureInstance {
31+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
32+
# ^^^^^^^^^^^^^^ keyword.other.powershell
33+
# ^^^^^^^^^^^^^^^^^^^^ entity.name.label.powershell
34+
# ^ meta.block.powershell punctuation.section.braces.begin.powershell
35+
Ensure = 'Present'
36+
Name = 'Bitlocker'
37+
}
38+
#^^^^^^^^^^^^ meta.function.powershell meta.block.powershell
39+
# ^ punctuation.section.braces.end.powershell
40+
}
41+
}
42+
MyDscConfiguration
43+
44+
45+
Configuration MyDscConfiguration
46+
{
47+
param
48+
#^^^^^^^^^^^^ meta.function.powershell
49+
# ^^^^^ keyword.declaration.parameter.powershell
50+
(
51+
[string[]]$ComputerName='localhost'
52+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
53+
# ^ punctuation.section.brackets.begin.powershell
54+
# ^^^^^^ storage.type.powershell
55+
# ^ punctuation.section.brackets.begin.powershell
56+
# ^^ punctuation.section.brackets.end.powershell
57+
# ^^^^^^^^^^^^^ variable.other.readwrite.powershell
58+
# ^ punctuation.definition.variable.powershell
59+
# ^ keyword.operator.assignment.powershell
60+
# ^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
61+
# ^ punctuation.definition.string.begin.powershell
62+
# ^ punctuation.definition.string.end.powershell
63+
)
64+
65+
Node $ComputerName
66+
{
67+
WindowsFeature MyFeatureInstance
68+
{
69+
Ensure = 'Present'
70+
Name = 'RSAT'
71+
}
72+
73+
WindowsFeature My2ndFeatureInstance
74+
{
75+
Ensure = 'Present'
76+
Name = 'Bitlocker'
77+
}
78+
}
79+
}
80+
MyDscConfiguration
81+
82+
83+
Configuration MyDscConfiguration
84+
{
85+
Node @('localhost', 'Server01')
86+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
87+
# ^^^^ keyword.context.block.powershell
88+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.array-expression.powershell
89+
# ^ keyword.other.array.begin.powershell
90+
# ^ punctuation.section.group.begin.powershell
91+
# ^^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
92+
# ^ punctuation.definition.string.begin.powershell
93+
# ^ punctuation.definition.string.end.powershell
94+
# ^ punctuation.separator.sequence.powershell
95+
# ^^^^^^^^^^ meta.string.powershell string.quoted.single.powershell
96+
# ^ punctuation.definition.string.begin.powershell
97+
# ^ punctuation.definition.string.end.powershell
98+
# ^ punctuation.section.group.end.powershell
99+
{
100+
WindowsFeature MyFeatureInstance
101+
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
102+
# ^^^^^^^^^^^^^^ keyword.other.powershell
103+
# ^^^^^^^^^^^^^^^^^ entity.name.label.powershell
104+
{
105+
Ensure = 'Present'
106+
Name = 'RSAT'
107+
}
108+
109+
WindowsFeature My2ndFeatureInstance
110+
{
111+
Ensure = 'Present'
112+
Name = 'Bitlocker'
113+
}
114+
}
115+
}
116+
MyDscConfiguration

Tests/syntax_test_PowerShell.ps1

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,22 +1382,6 @@ catch { }
13821382
# ^ punctuation.section.braces.begin
13831383
# ^ punctuation.section.braces.end
13841384

1385-
# Reserved words
1386-
Configuration Crazyness {
1387-
#^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.powershell
1388-
#^^^^^^^^^^^^ keyword.declaration.function.powershell
1389-
# ^^^^^^^^^ entity.name.function.powershell
1390-
# @@@@@@@@@ definition
1391-
# ^ punctuation.section.block.begin.powershell
1392-
Node Whatever {
1393-
# ^ punctuation.section.braces.begin
1394-
}
1395-
#^^^^ meta.function.powershell meta.block.powershell
1396-
# ^ punctuation.section.braces.end.powershell
1397-
}
1398-
#^^^^ meta.function.powershell
1399-
# ^ punctuation.section.block.end.powershell
1400-
14011385
# Redirection
14021386
notepad.exe > log.txt
14031387
#^^^^^^^^^^ variable.function

0 commit comments

Comments
 (0)