From b9bce19487b0b041d19b12612af821f7d0b0b4be Mon Sep 17 00:00:00 2001 From: deathaxe <16542113+deathaxe@users.noreply.github.com> Date: Mon, 25 May 2026 16:47:34 +0000 Subject: [PATCH 1/5] Enable extending syntaxes to override indentation constrints (#224) This commit introduces `no_indent` variable, inspired by Bash, to enable extending syntaxes to override indentation constraints. Use cases: - embed powershell in indented fenced code blocks in Markdown - embed powershell in YAML files, such as GitHub Action workflows --- PowerShell.sublime-syntax | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index c210897..f2c81ef 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -1082,7 +1082,7 @@ contexts: - match: (?={{csharp_indicator}}) set: scope:source.cs.embedded.powershell with_prototype: - - match: (?=^{{single_quote}}@) + - match: (?={{no_indent}}{{single_quote}}@) pop: 1 - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell @@ -1091,8 +1091,9 @@ contexts: inside-single-quoted-heredoc-string: - meta_include_prototype: false - meta_scope: meta.string.powershell string.quoted.single.heredoc.powershell - - match: ^{{single_quote}}@ - scope: punctuation.definition.string.end.powershell + - match: '{{no_indent}}({{single_quote}}@)' + captures: + 1: punctuation.definition.string.end.powershell pop: 1 - match: '{{single_quote}}{2}' scope: constant.character.escape.powershell @@ -1108,8 +1109,9 @@ contexts: inside-double-quoted-heredoc-string: - meta_include_prototype: false - meta_scope: meta.string.interpolated.powershell string.quoted.double.heredoc.powershell - - match: ^{{double_quote}}@ - scope: punctuation.definition.string.end.powershell + - match: '{{no_indent}}({{double_quote}}@)' + captures: + 1: punctuation.definition.string.end.powershell pop: 1 - include: escape-sequences - include: string-interpolations @@ -1120,7 +1122,7 @@ contexts: - match: (?={{csharp_indicator}}) set: scope:source.cs.embedded.powershell with_prototype: - - match: (?=^{{double_quote}}@) + - match: (?={{no_indent}}{{double_quote}}@) pop: 1 - include: escape-sequences - include: else-pop @@ -1427,6 +1429,9 @@ variables: )\b shebang_language: \b(?:pwsh|powershell)\b + # Indentation and whitespace patterns + no_indent: ^ + # Attributes attributes: |- \b(?xi: From 88fc82a017dcfe3ba1f0fdc19184962e86eb34d1 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Wed, 24 Jun 2026 13:40:46 -0400 Subject: [PATCH 2/5] Clamp CI max ST version to 4203 on the appropriate maintenance branch --- .github/workflows/syntax.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/syntax.yml b/.github/workflows/syntax.yml index 7531ebe..6e0d1cf 100644 --- a/.github/workflows/syntax.yml +++ b/.github/workflows/syntax.yml @@ -32,14 +32,12 @@ jobs: strategy: matrix: include: - - build: latest - packages: master - - build: stable + - build: 4203 packages: binary - build: 4107 packages: binary steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v7 - uses: SublimeText/syntax-test-action@v2 with: build: ${{ matrix.build }} From d06bd3530f9360644ed6d1dfa2c25e74a981f5f3 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 3/5] 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 bcbe4c05f2de9a60df2d58aaa78f33cad98556a7 Mon Sep 17 00:00:00 2001 From: Michael Lyons Date: Fri, 19 Jun 2026 11:14:47 -0400 Subject: [PATCH 4/5] 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 45b7abf95ec46a371a244c6778c7b09fe195264a 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 5/5] 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