From 8400a7fd97bad6b54d2d13781457cd83ab14eab2 Mon Sep 17 00:00:00 2001 From: Michael <2701605+michaelblyons@users.noreply.github.com> Date: Thu, 18 Jun 2026 16:04:58 -0400 Subject: [PATCH 1/3] Fix unquoted strings leaking into quotes (#229) Fixes #228 --- PowerShell.sublime-syntax | 4 ++-- tests/syntax_test_strings.ps1 | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index f2c81ef..785bc3a 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -339,8 +339,8 @@ contexts: inside-unquoted-string: - meta_include_prototype: false - - meta_scope: string.unquoted.powershell - - match: $|(?=[\s#|>;,()}]) + - meta_scope: meta.string.powershell string.unquoted.powershell + - match: $|(?=[\s#|>;,()}"']) pop: 1 - match: \{ push: inside-unquoted-string-brace diff --git a/tests/syntax_test_strings.ps1 b/tests/syntax_test_strings.ps1 index 4bfcdbe..d00fd9b 100644 --- a/tests/syntax_test_strings.ps1 +++ b/tests/syntax_test_strings.ps1 @@ -796,3 +796,11 @@ # ^ punctuation.definition.keyword.powershell # ^^^^^ meta.number.float.decimal.powershell constant.numeric.value.powershell # ^ punctuation.separator.decimal.powershell + +###[ Real Samples ]############################################################ + + git -c http.extraheader="AUTHORIZATION: Basic $base64Pat" pull origin main-vs-deps +# @@@ reference +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string +# ^^^^^^^^^^^^^^^^^ string.unquoted +# ^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double From 1c38328ef2e084697cec1bccf8a0716f3d9397e0 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 19 Jun 2026 11:14:47 -0400 Subject: [PATCH 2/3] Support param blocks at BOF --- PowerShell.sublime-syntax | 7 ++++++- tests/syntax_test_script_params.ps1 | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/syntax_test_script_params.ps1 diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 785bc3a..549a04a 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -25,7 +25,7 @@ contexts: main: - meta_include_prototype: false - match: '' - push: [statements, imports, shebang] + push: [statements, script-param-block, imports, shebang] shebang: - meta_include_prototype: false @@ -46,6 +46,11 @@ contexts: - include: using-directives - include: else-pop + script-param-block: + - include: attributes + - include: param-block + - include: else-pop + statements: - include: classes - include: functions diff --git a/tests/syntax_test_script_params.ps1 b/tests/syntax_test_script_params.ps1 new file mode 100644 index 0000000..9f44550 --- /dev/null +++ b/tests/syntax_test_script_params.ps1 @@ -0,0 +1,29 @@ +# SYNTAX TEST "Packages/PowerShell/PowerShell.sublime-syntax" + + [CmdletBinding(PositionalBinding=$false)] +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute.powershell +# ^ punctuation.section.brackets.begin.powershell +# ^^^^^^^^^^^^^ support.function.attribute.powershell +# ^ punctuation.section.group.begin.powershell +# ^^^^^^^^^^^^^^^^^ variable.parameter.attribute.powershell +# ^ keyword.operator.assignment.powershell +# ^^^^^^ constant.language.boolean.false.powershell +# ^ punctuation.definition.variable.powershell +# ^ punctuation.section.group.end.powershell +# ^ punctuation.section.brackets.end.powershell + param( +# ^^^^^ keyword.declaration.parameter.powershell +# ^^ meta.block.parameters.powershell +# ^ punctuation.section.block.begin.powershell + [Parameter(Mandatory=$true)] + [string]$base, + + [Parameter(Mandatory=$true)] + [string]$head + ) + + Set-StrictMode -version 2.0 + $ErrorActionPreference="Stop" + + [CmdletBinding(PositionalBinding=$false)] +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - meta.attribute - meta.annotation From a31aeb89735285766947ce27c150cdcc5fedd2bf Mon Sep 17 00:00:00 2001 From: Michael <2701605+michaelblyons@users.noreply.github.com> Date: Wed, 24 Jun 2026 12:51:11 -0400 Subject: [PATCH 3/3] Support statement values (#233) See #231 --- PowerShell.sublime-syntax | 11 ++++++----- tests/syntax_test_PowerShell.ps1 | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 549a04a..e19ee66 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -57,11 +57,6 @@ contexts: - include: workflows - include: desired-state-configurations - - include: exceptions - - include: loops - - include: flow - - include: conditionals - - match: \B\.(?= ) scope: keyword.operator.source.powershell push: @@ -73,6 +68,7 @@ contexts: - include: commands-quoted - include: else-pop + - include: flow - include: expressions expressions: @@ -86,6 +82,11 @@ contexts: - include: escape-sequences + # Statements that may return values + - include: exceptions + - include: loops + - include: conditionals + # Normal code - include: types - include: strings diff --git a/tests/syntax_test_PowerShell.ps1 b/tests/syntax_test_PowerShell.ps1 index 469bfc6..1227350 100644 --- a/tests/syntax_test_PowerShell.ps1 +++ b/tests/syntax_test_PowerShell.ps1 @@ -281,6 +281,23 @@ using namespace System.Management.Automation # ^ punctuation.section.arguments.begin.powershell # ^ punctuation.section.arguments.end.powershell + # Statement value assignment + $x = if ($a) { 1 } else { 2 } +# ^^ keyword.control.conditional +# ^^^^ keyword.control.conditional + + $x = switch ($v) { 1 { 'one' } default { 'other' } } +# ^^^^^^ keyword.control.conditional.switch + + $x = foreach ($i in 1..3) { $i * 2 } +# ^^^^^^^ keyword.control.loop + + $x = try { Get-Thing } catch { $null } +# ^^^ keyword.control.exception +# @@@@@@@@@ reference +# ^^^^^ keyword.control.exception + + # Hashtable $properties = @{ # <- punctuation.definition.variable