Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions PowerShell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -75,73 +75,77 @@ contexts:
- include: main
- match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b
scope: variable.function.powershell
# Consume a string with a trailing dot
# to prevent members with particular names from being recognized as keywords.
- match: \b[\w-]+(?=\.)
push: members
# Exceptions
- match: (?<![.])\b(?i:throw){{kebab_break}}
- match: \b(?i:throw){{kebab_break}}
scope: keyword.control.exception.raise.powershell
- match: (?<![.])\b(?i:try){{kebab_break}}
- match: \b(?i:try){{kebab_break}}
scope: keyword.control.exception.try.powershell
- match: (?<![.])\b(?i:catch|trap){{kebab_break}}
- match: \b(?i:catch|trap){{kebab_break}}
scope: keyword.control.exception.catch.powershell
- match: (?<![.])\b(?i:finally){{kebab_break}}
- match: \b(?i:finally){{kebab_break}}
scope: keyword.control.exception.finally.powershell
# Conditionals
- match: (?<![.])\b(?i:if){{kebab_break}}
- match: \b(?i:if){{kebab_break}}
scope: keyword.control.conditional.if.powershell
- match: (?<![.])\b(?i:elseif){{kebab_break}}
- match: \b(?i:elseif){{kebab_break}}
scope: keyword.control.conditional.elseif.powershell
- match: (?<![.])\b(?i:else){{kebab_break}}
- match: \b(?i:else){{kebab_break}}
scope: keyword.control.conditional.else.powershell
- match: (?<![.])\b(?i:switch){{kebab_break}}
- match: \b(?i:switch){{kebab_break}}
scope: keyword.control.conditional.switch.powershell
- match: \?
scope: keyword.control.conditional.select.powershell
- match: \b(?i:where(?!-object)){{kebab_break}}
scope: keyword.control.conditional.select.powershell
# Begin/End
- match: (?<![.])\b(?i:begin){{kebab_break}}
- match: \b(?i:begin){{kebab_break}}
scope: keyword.context.block.begin.powershell
- match: (?<![.])\b(?i:process){{kebab_break}}
- match: \b(?i:process){{kebab_break}}
scope: keyword.context.block.process.powershell
- match: (?<![.])\b(?i:end){{kebab_break}}
- match: \b(?i:end){{kebab_break}}
scope: keyword.context.block.end.powershell
- match: (?<![.])\b(?i:clean){{kebab_break}}
- match: \b(?i:clean){{kebab_break}}
scope: keyword.context.block.clean.powershell
# Loops
- match: \b(?i:for|foreach(?!-object)){{kebab_break}}
scope: keyword.control.loop.for.powershell
- match: (?<![.])\b(?i:do){{kebab_break}}
- match: \b(?i:do){{kebab_break}}
scope: keyword.control.loop.do-while.powershell
- match: (?<![.])\b(?i:while){{kebab_break}}
- match: \b(?i:while){{kebab_break}}
scope: keyword.control.loop.while.powershell
- match: (?<![.])\b(?i:until){{kebab_break}}
- match: \b(?i:until){{kebab_break}}
scope: keyword.control.loop.repeat-until.powershell
# Flow
- match: (?<![.])\b(?i:break){{kebab_break}}
- match: \b(?i:break){{kebab_break}}
scope: keyword.control.flow.break.powershell
- match: (?<![.])\b(?i:continue){{kebab_break}}
- match: \b(?i:continue){{kebab_break}}
scope: keyword.control.flow.continue.powershell
- match: (?<![.])\b(?i:exit){{kebab_break}}
- match: \b(?i:exit){{kebab_break}}
scope: keyword.control.flow.exit.powershell
- match: (?<![.])\b(?i:return){{kebab_break}}
- match: \b(?i:return){{kebab_break}}
scope: keyword.control.flow.return.powershell
# Declaration
- match: (?<![.])\b(?i:var){{kebab_break}}
- match: \b(?i:var){{kebab_break}}
# scope: storage.type.variable.powershell
scope: keyword.declaration.variable.powershell
- match: (?<![.])\b(?i:(?:dynamic)?param){{kebab_break}}
- match: \b(?i:(?:dynamic)?param){{kebab_break}}
scope: keyword.declaration.parameter.powershell # This scope is not standard
# Uncategorized keywords
- match: (?<![.])\b(?i:data|default|define|from|in|inlinescript|parallel|sequence){{kebab_break}}
- match: \b(?i:data|default|define|from|in|inlinescript|parallel|sequence){{kebab_break}}
scope: keyword.control.powershell
- match: \B--%\B
scope: keyword.control.powershell
push:
- meta_content_scope: string.unquoted.powershell
- include: pop-before-newline
- match: (?<![.])\b(?i:hidden|static)\b
- match: \b(?i:hidden|static)\b
# This should only be relevant inside a class but will require a rework of how classes are matched. This is a temp fix.
scope: storage.modifier.powershell
- match: (?<![.])\b((?i:class))\s+([\w-]+)\b
- match: \b((?i:class))\s+([\w-]+)\b
captures:
1: storage.type.class.powershell
2: meta.class.powershell entity.name.class.powershell
Expand Down
12 changes: 6 additions & 6 deletions Tests/syntax_test_PowerShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@
# ^^ constant.numeric.float
1.d
# ^^^ constant.numeric.float
1.lGB

Check failure on line 478 in Tests/syntax_test_PowerShell.ps1

View workflow job for this annotation

GitHub Actions / Syntax Tests (4102)

[constant.numeric.float - unclear whether float or int] does not match scope [source.powershell]

Check failure on line 478 in Tests/syntax_test_PowerShell.ps1

View workflow job for this annotation

GitHub Actions / Syntax Tests (4102)

[keyword.other.unit] does not match scope [source.powershell]

Check failure on line 478 in Tests/syntax_test_PowerShell.ps1

View workflow job for this annotation

GitHub Actions / Syntax Tests (4102)

[keyword.other.unit] does not match scope [source.powershell]
# ^^^ constant.numeric.float - unclear whether float or int
# ^^ keyword.other.unit
1.dGB
Expand Down Expand Up @@ -522,7 +522,7 @@
# ^^ constant.numeric.integer
# ^^^ constant.numeric.float
# ^ keyword.operator
-10.002L

Check failure on line 525 in Tests/syntax_test_PowerShell.ps1

View workflow job for this annotation

GitHub Actions / Syntax Tests (4102)

[constant.numeric.float - unclear whether float or int] does not match scope [source.powershell]
# ^ keyword.operator.unary
# ^^^^^^^ constant.numeric.float - unclear whether float or int
$x..5.40D
Expand Down Expand Up @@ -1360,12 +1360,12 @@
# ^^^^^^^ - keyword.control
New-Object -TypeName System.Data
# ^^^^ - keyword.control
New-Object -TypeName System.if
# ^^ - keyword.control
New-Object -TypeName System.Clean
# ^^^^^ - keyword.control
New-Object -TypeName System.Throw
# ^^^^^ - keyword.control
New-Object -TypeName Sy-stem.if
# ^^ - keyword.control
New-Object -TypeName S_ystem.Clean
# ^^^^^ - keyword.control
New-Object -TypeName Sy_stem-.Throw
# ^^^^^ - keyword.control
echo `"test`"
# ^^^^^^^^^ - string.quoted
# ^^ constant.character.escape
Expand Down
Loading