From 29729da455862125c5ab0d18ab77747d017eee99 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Fri, 31 Jan 2025 19:33:58 +0100 Subject: [PATCH 1/2] Add support for long options in syntax Tweak the regex which matches command options to correctly detect GNU-style long options. --- PowerShell.sublime-syntax | 2 +- Tests/syntax_test_PowerShell.ps1 | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 7d3e927..0712c40 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -186,7 +186,7 @@ contexts: captures: 1: punctuation.definition.keyword.powershell # Flags/Options/Parameters - - match: \B([-/])\p{L}(?:[\w-]*\w)? + - match: \B(-|--|/)\p{L}(?:[\w-]*\w)? scope: variable.parameter.option.powershell captures: 1: punctuation.definition.parameter.powershell diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index b67309c..f86c698 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -92,6 +92,15 @@ throw "Do not run this file!" # ^^^ keyword.control # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted - constant - variable - comment +& gnutool.exe -s 'short option' --long-option --very_long_option value +#<- keyword.operator.other +# ^^^^^^^^^^^ variable.function +# ^ variable.parameter.option punctuation.definition.parameter +# ^ variable.parameter.option +# ^^ variable.parameter.option punctuation.definition.parameter +# ^^ variable.parameter.option punctuation.definition.parameter +# ^^^^^^^^^^^^^^^^ variable.parameter.option + # Automatic variables $_, $$, $^, $? # <- punctuation.definition.variable From b4996501f0ab3fb6f94054695234ac14e7588635 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Fri, 31 Jan 2025 20:58:39 +0100 Subject: [PATCH 2/2] Add support for '+' options These options are used in programs like ImageMagick. --- PowerShell.sublime-syntax | 2 +- Tests/syntax_test_PowerShell.ps1 | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 0712c40..6372d33 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -186,7 +186,7 @@ contexts: captures: 1: punctuation.definition.keyword.powershell # Flags/Options/Parameters - - match: \B(-|--|/)\p{L}(?:[\w-]*\w)? + - match: \B(--?|[/+])\p{L}(?:[\w-]*\w)? scope: variable.parameter.option.powershell captures: 1: punctuation.definition.parameter.powershell diff --git a/Tests/syntax_test_PowerShell.ps1 b/Tests/syntax_test_PowerShell.ps1 index f86c698..bb9d932 100644 --- a/Tests/syntax_test_PowerShell.ps1 +++ b/Tests/syntax_test_PowerShell.ps1 @@ -92,7 +92,7 @@ throw "Do not run this file!" # ^^^ keyword.control # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.unquoted - constant - variable - comment -& gnutool.exe -s 'short option' --long-option --very_long_option value +& gnutool.exe -s 'short option' --long-option --very_long_option value +plus-option #<- keyword.operator.other # ^^^^^^^^^^^ variable.function # ^ variable.parameter.option punctuation.definition.parameter @@ -100,6 +100,8 @@ throw "Do not run this file!" # ^^ variable.parameter.option punctuation.definition.parameter # ^^ variable.parameter.option punctuation.definition.parameter # ^^^^^^^^^^^^^^^^ variable.parameter.option +# ^ variable.parameter.option punctuation.definition.parameter +# ^^^^^^^^^^^ variable.parameter.option # Automatic variables $_, $$, $^, $?