diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index f2c81ef..e19ee66 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,17 +46,17 @@ contexts: - include: using-directives - include: else-pop + script-param-block: + - include: attributes + - include: param-block + - include: else-pop + statements: - include: classes - include: functions - include: workflows - include: desired-state-configurations - - include: exceptions - - include: loops - - include: flow - - include: conditionals - - match: \B\.(?= ) scope: keyword.operator.source.powershell push: @@ -68,6 +68,7 @@ contexts: - include: commands-quoted - include: else-pop + - include: flow - include: expressions expressions: @@ -81,6 +82,11 @@ contexts: - include: escape-sequences + # Statements that may return values + - include: exceptions + - include: loops + - include: conditionals + # Normal code - include: types - include: strings @@ -339,8 +345,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_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 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 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