@@ -363,7 +363,7 @@ contexts:
363363
364364 in-command :
365365 - meta_content_scope : meta.function-call.arguments.powershell
366- - include : command-ending-sequences
366+ - include : pop-end-of-command
367367 - include : redirection
368368 - include : cli-parameters
369369 - include : expressions-without-commands
@@ -377,22 +377,28 @@ contexts:
377377 - include : escape-sequences
378378 - include : string-wildcards
379379
380- command-ending-sequences :
380+ pop-end-of-command :
381381 - include : line-continuations
382382 - include : pop-eol
383383 - match : (?=[)}])
384384 pop : 1
385+ - include : pop-terminator
386+ - include : pop-pipe
387+
388+ pop-terminator :
385389 - match : ' ;'
386390 scope : punctuation.terminator.statement.powershell
387391 pop : 1
392+
393+ pop-pipe :
388394 - match : (\|)\s*\n
389395 captures :
390- 1 : keyword.operator.logical .pipe.powershell
396+ 1 : keyword.operator.assignment .pipe.powershell
391397 push :
392398 - match : ^
393399 pop : 2
394400 - match : \|
395- scope : keyword.operator.logical .pipe.powershell
401+ scope : keyword.operator.assignment .pipe.powershell
396402 pop : 1
397403
398404 cli-parameters :
@@ -841,7 +847,22 @@ contexts:
841847# ##[ OPERATORS ]###############################################################
842848
843849 operators :
844- # Word operators
850+ - include : operator-words
851+ - include : operator-symbols
852+
853+ operator-words :
854+ # RegExp context
855+ - match : \B(-)(?i:[ic]?(?:not)?(?:match)){{kebab_break}}
856+ scope : keyword.operator.logical.powershell
857+ captures :
858+ 1 : punctuation.definition.keyword.powershell
859+ push : expect-regex-string
860+ - match : \B(-)(?i:replace){{kebab_break}}
861+ scope : keyword.operator.string.powershell
862+ captures :
863+ 1 : punctuation.definition.keyword.powershell
864+ push : expect-regex-string
865+
845866 - match : \B(-)(?i:as){{kebab_break}}
846867 scope : keyword.operator.cast.powershell
847868 captures :
@@ -850,20 +871,10 @@ contexts:
850871 scope : keyword.operator.comparison.powershell
851872 captures :
852873 1 : punctuation.definition.keyword.powershell
853- - match : \B(-)(?i:[ic]?(?:not)?(?:match)){{kebab_break}}
854- scope : keyword.operator.logical.powershell
855- captures :
856- 1 : punctuation.definition.keyword.powershell
857- push : expect-regex-string
858874 - match : \B(-)(?i:[ic]?(?:not)?(?:like|contains|in)){{kebab_break}}
859875 scope : keyword.operator.logical.powershell
860876 captures :
861877 1 : punctuation.definition.keyword.powershell
862- - match : \B(-)(?i:replace){{kebab_break}}
863- scope : keyword.operator.string.powershell
864- captures :
865- 1 : punctuation.definition.keyword.powershell
866- push : expect-regex-string
867878 - match : \B(-)(?i:join|split){{kebab_break}}
868879 scope : keyword.operator.string.powershell
869880 captures :
@@ -885,31 +896,38 @@ contexts:
885896 captures :
886897 1 : punctuation.definition.keyword.powershell
887898
888- # Symbol operators
889- - match : \!
890- scope : keyword.operator.logical.powershell
899+ operator-symbols :
900+ # Assignment context
891901 - include : assignment-normal
892902 - match : (?:[+/*%-]|\?\?)=
893903 scope : keyword.operator.assignment.augmented.powershell
894904 push : in-assignment
905+ # Assignment same context
906+ - match : \|
907+ scope : keyword.operator.assignment.pipe.powershell
895908 - match : (?:\+\+|--)(?![ \t]*\d|[[:alpha:]])
896909 scope : keyword.operator.assignment.powershell
897- - match : ' [+-](?=\.?\d)' # This is sort of heuristic
910+
911+ # Heuristically guess the context with lookaheads
912+ # Mostly to avoid matching CLI parameters
913+ - match : ' [+-](?=\.?\d)'
898914 scope : keyword.operator.unary.powershell
899- # Be careful about matching arithmetic with tightly following words
900915 - match : ' [/+](?![[:alpha:]])'
901916 scope : keyword.operator.arithmetic.powershell
902917 - match : -(?![[:alpha:]-])
903918 scope : keyword.operator.arithmetic.powershell
904919 - match : \*(?!\.?[[:alpha:]])
905920 scope : keyword.operator.arithmetic.powershell
921+ - match : \.\.(?=\-?\d|\(|\$)
922+ scope : keyword.operator.range.powershell
906923 # Exclude foreach shortcut
907924 - match : ' %(?!\s*\{)'
908925 scope : keyword.operator.arithmetic.powershell
926+
927+ - match : \!
928+ scope : keyword.operator.logical.powershell
909929 - match : \|\||&&
910930 scope : keyword.operator.logical.powershell
911- - match : \|
912- scope : keyword.operator.logical.pipe.powershell
913931 - match : \?\?
914932 scope : keyword.operator.null-coalescing.powershell
915933 - match : ' [?:]'
@@ -919,17 +937,14 @@ contexts:
919937 - include : comma-separators
920938 - match : ' &'
921939 scope : keyword.operator.background.powershell
922- - match : \.\.(?=\-?\d|\(|\$)
923- # This is very imprecise. Is there a syntax for 'must come after...'?
924- scope : keyword.operator.range.powershell
925940
926941 assignment-normal :
927942 - match : =
928943 scope : keyword.operator.assignment.powershell
929944 push : in-assignment
930945
931946 in-assignment :
932- - include : command-ending-sequences
947+ - include : pop-end-of-command
933948 # INFO: Someday maybe we can nix the workflow stuff
934949 - include : workflow-execution-contexts
935950 - include : expressions
0 commit comments