From c53e5b4925a8494e905c908130bf4e2a9c2b8fd6 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:30:03 +0100 Subject: [PATCH 1/7] Change keyword matching regex Keywords (with the exception of 'where' and 'foreach') should not be considered as such if they are preceded by a '.'. The tests relative to keywords used as members or methods now pass. 'process' is now considered a block keyword. --- PowerShell.sublime-syntax | 48 +++++++++++++++++--------------- Tests/syntax_test_PowerShell.ps1 | 6 ++++ 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 8d1941b..9601eb1 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -76,70 +76,72 @@ contexts: - match: \b[\w.-]+\.(?i:exe|com|cmd|bat)\b scope: variable.function.powershell # Exceptions - - match: \b(?i:throw){{kebab_break}} + - match: (? Date: Wed, 8 Jan 2025 08:47:20 +0100 Subject: [PATCH 2/7] Add 'sequence' keyword Also make the relative syntax test pass. --- PowerShell.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 9601eb1..ff6ad8a 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -131,7 +131,7 @@ contexts: - match: (? Date: Wed, 8 Jan 2025 09:08:16 +0100 Subject: [PATCH 3/7] Change test assertion in Function syntax test Now the test reflects the change of the 'process' keyword from uncategorised to block. --- Tests/syntax_test_Function.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/syntax_test_Function.ps1 b/Tests/syntax_test_Function.ps1 index 3c16339..6688d66 100644 --- a/Tests/syntax_test_Function.ps1 +++ b/Tests/syntax_test_Function.ps1 @@ -376,7 +376,7 @@ function Verb-Noun { { } Process { - # <- keyword.control + # <- keyword.context.block.process if ($pscmdlet.ShouldProcess("Target", "Operation")) { # <- keyword.control # ^ punctuation.section.group.begin From 11aecf61f3a4c66baf7b4ac1672acd730b5621b2 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:12:20 +0100 Subject: [PATCH 4/7] Change Parameter matching regex to match 'PositionalBinding' The relevant test in the function syntax test now passes. --- PowerShell.sublime-syntax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index ff6ad8a..1668c59 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -294,9 +294,9 @@ contexts: (?xi: \b( Mandatory | ValueFromPipeline(?:ByPropertyName)? - | ValueFromRemainingArguments | Position + | ValueFromRemainingArguments | Position(?:alBinding)? | (?:Default)?ParameterSetName | SupportsShouldProcess | SupportsPaging - | PositionalBinding | HelpUri | ConfirmImpact | HelpMessage + | HelpUri | ConfirmImpact | HelpMessage ) \s*(=)? ) From e180d24b49acf8cf1f93dc498b823ddf1272b157 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:28:39 +0100 Subject: [PATCH 5/7] Consume string with a trailing dot before checking for keywords This makes negative lookbehind assertions on keywords unnecessary. --- PowerShell.sublime-syntax | 52 +++++++++++++++++--------------- Tests/syntax_test_PowerShell.ps1 | 12 ++++---- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 1668c59..ed6041c 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -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: (? Date: Fri, 10 Jan 2025 14:01:57 +0200 Subject: [PATCH 6/7] Add scope to matched unquoted strings Co-authored-by: deathaxe --- PowerShell.sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index ed6041c..2ba24e7 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -78,6 +78,7 @@ contexts: # Consume a string with a trailing dot # to prevent members with particular names from being recognized as keywords. - match: \b[\w-]+(?=\.) + scope: variable.other.object.powershell push: members # Exceptions - match: \b(?i:throw){{kebab_break}} From 808aa94420e1d35d7b6b7d58ccb31d0b1c91e0a9 Mon Sep 17 00:00:00 2001 From: matteocoder <22897138+matteocoder@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:32:33 +0200 Subject: [PATCH 7/7] Match word boundary to avoid highlighting invalid arguments Co-authored-by: deathaxe --- PowerShell.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerShell.sublime-syntax b/PowerShell.sublime-syntax index 2ba24e7..ad864df 100644 --- a/PowerShell.sublime-syntax +++ b/PowerShell.sublime-syntax @@ -302,7 +302,7 @@ contexts: | ValueFromRemainingArguments | Position(?:alBinding)? | (?:Default)?ParameterSetName | SupportsShouldProcess | SupportsPaging | HelpUri | ConfirmImpact | HelpMessage - ) + )\b \s*(=)? ) captures: