Skip to content

Commit c53e5b4

Browse files
committed
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.
1 parent da9cdd7 commit c53e5b4

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

PowerShell.sublime-syntax

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,70 +76,72 @@ contexts:
7676
- match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b
7777
scope: variable.function.powershell
7878
# Exceptions
79-
- match: \b(?i:throw){{kebab_break}}
79+
- match: (?<![.])\b(?i:throw){{kebab_break}}
8080
scope: keyword.control.exception.raise.powershell
81-
- match: \b(?i:try){{kebab_break}}
81+
- match: (?<![.])\b(?i:try){{kebab_break}}
8282
scope: keyword.control.exception.try.powershell
83-
- match: \b(?i:catch|trap){{kebab_break}}
83+
- match: (?<![.])\b(?i:catch|trap){{kebab_break}}
8484
scope: keyword.control.exception.catch.powershell
85-
- match: \b(?i:finally){{kebab_break}}
85+
- match: (?<![.])\b(?i:finally){{kebab_break}}
8686
scope: keyword.control.exception.finally.powershell
8787
# Conditionals
88-
- match: \b(?i:if){{kebab_break}}
88+
- match: (?<![.])\b(?i:if){{kebab_break}}
8989
scope: keyword.control.conditional.if.powershell
90-
- match: \b(?i:elseif){{kebab_break}}
90+
- match: (?<![.])\b(?i:elseif){{kebab_break}}
9191
scope: keyword.control.conditional.elseif.powershell
92-
- match: \b(?i:else){{kebab_break}}
92+
- match: (?<![.])\b(?i:else){{kebab_break}}
9393
scope: keyword.control.conditional.else.powershell
94-
- match: \b(?i:switch){{kebab_break}}
94+
- match: (?<![.])\b(?i:switch){{kebab_break}}
9595
scope: keyword.control.conditional.switch.powershell
9696
- match: \?
9797
scope: keyword.control.conditional.select.powershell
9898
- match: \b(?i:where(?!-object)){{kebab_break}}
9999
scope: keyword.control.conditional.select.powershell
100100
# Begin/End
101-
- match: \b(?i:begin){{kebab_break}}
101+
- match: (?<![.])\b(?i:begin){{kebab_break}}
102102
scope: keyword.context.block.begin.powershell
103-
- match: \b(?i:end){{kebab_break}}
103+
- match: (?<![.])\b(?i:process){{kebab_break}}
104+
scope: keyword.context.block.process.powershell
105+
- match: (?<![.])\b(?i:end){{kebab_break}}
104106
scope: keyword.context.block.end.powershell
105-
- match: \b(?i:clean){{kebab_break}}
107+
- match: (?<![.])\b(?i:clean){{kebab_break}}
106108
scope: keyword.context.block.clean.powershell
107109
# Loops
108110
- match: \b(?i:for|foreach(?!-object)){{kebab_break}}
109111
scope: keyword.control.loop.for.powershell
110-
- match: \b(?i:do){{kebab_break}}
112+
- match: (?<![.])\b(?i:do){{kebab_break}}
111113
scope: keyword.control.loop.do-while.powershell
112-
- match: \b(?i:while){{kebab_break}}
114+
- match: (?<![.])\b(?i:while){{kebab_break}}
113115
scope: keyword.control.loop.while.powershell
114-
- match: \b(?i:until){{kebab_break}}
116+
- match: (?<![.])\b(?i:until){{kebab_break}}
115117
scope: keyword.control.loop.repeat-until.powershell
116118
# Flow
117-
- match: \b(?i:break){{kebab_break}}
119+
- match: (?<![.])\b(?i:break){{kebab_break}}
118120
scope: keyword.control.flow.break.powershell
119-
- match: \b(?i:continue){{kebab_break}}
121+
- match: (?<![.])\b(?i:continue){{kebab_break}}
120122
scope: keyword.control.flow.continue.powershell
121-
- match: \b(?i:exit){{kebab_break}}
123+
- match: (?<![.])\b(?i:exit){{kebab_break}}
122124
scope: keyword.control.flow.exit.powershell
123-
- match: \b(?i:return){{kebab_break}}
125+
- match: (?<![.])\b(?i:return){{kebab_break}}
124126
scope: keyword.control.flow.return.powershell
125127
# Declaration
126-
- match: \b(?i:var){{kebab_break}}
128+
- match: (?<![.])\b(?i:var){{kebab_break}}
127129
# scope: storage.type.variable.powershell
128130
scope: keyword.declaration.variable.powershell
129-
- match: \b(?i:(?:dynamic)?param){{kebab_break}}
131+
- match: (?<![.])\b(?i:(?:dynamic)?param){{kebab_break}}
130132
scope: keyword.declaration.parameter.powershell # This scope is not standard
131133
# Uncategorized keywords
132-
- match: \b(?i:data|default|define|from|in|inlinescript|parallel|process){{kebab_break}}
134+
- match: (?<![.])\b(?i:data|default|define|from|in|inlinescript|parallel){{kebab_break}}
133135
scope: keyword.control.powershell
134136
- match: \B--%\B
135137
scope: keyword.control.powershell
136138
push:
137139
- meta_content_scope: string.unquoted.powershell
138140
- include: pop-before-newline
139-
- match: \b(?i:hidden|static)\b
141+
- match: (?<![.])\b(?i:hidden|static)\b
140142
# This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix.
141143
scope: storage.modifier.powershell
142-
- match: \b((?i:class))\s+([\w-]+)\b
144+
- match: (?<![.])\b((?i:class))\s+([\w-]+)\b
143145
captures:
144146
1: storage.type.class.powershell
145147
2: meta.class.powershell entity.name.class.powershell

Tests/syntax_test_PowerShell.ps1

Lines changed: 6 additions & 0 deletions
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 System.if
1364+
# ^^ - keyword.control
1365+
New-Object -TypeName System.Clean
1366+
# ^^^^^ - keyword.control
1367+
New-Object -TypeName System.Throw
1368+
# ^^^^^ - keyword.control
13631369
echo `"test`"
13641370
# ^^^^^^^^^ - string.quoted
13651371
# ^^ constant.character.escape

0 commit comments

Comments
 (0)