Skip to content

Commit 28143b5

Browse files
committed
Allow numbers to immediately follow operators
Fixes #206
1 parent 8a4b6f9 commit 28143b5

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

PowerShell.sublime-syntax

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -858,46 +858,46 @@ contexts:
858858

859859
operator-words:
860860
# RegExp context
861-
- match: \B(-)(?i:[ic]?(?:not)?(?:match)){{kebab_break}}
861+
- match: (-)(?i:[ic]?(?:not)?(?:match)){{operator_break}}
862862
scope: keyword.operator.logical.powershell
863863
captures:
864864
1: punctuation.definition.keyword.powershell
865865
push: expect-regex-string
866-
- match: \B(-)(?i:replace){{kebab_break}}
866+
- match: (-)(?i:replace){{operator_break}}
867867
scope: keyword.operator.string.powershell
868868
captures:
869869
1: punctuation.definition.keyword.powershell
870870
push: expect-regex-string
871871

872-
- match: \B(-)(?i:as){{kebab_break}}
872+
- match: (-)(?i:as){{operator_break}}
873873
scope: keyword.operator.cast.powershell
874874
captures:
875875
1: punctuation.definition.keyword.powershell
876-
- match: \B(-)(?i:[ic]?(?:eq|ne|[gl][te])){{kebab_break}}
876+
- match: (-)(?i:[ic]?(?:eq|ne|[gl][te])){{operator_break}}
877877
scope: keyword.operator.comparison.powershell
878878
captures:
879879
1: punctuation.definition.keyword.powershell
880-
- match: \B(-)(?i:[ic]?(?:not)?(?:like|contains|in)){{kebab_break}}
880+
- match: (-)(?i:[ic]?(?:not)?(?:like|contains|in)){{operator_break}}
881881
scope: keyword.operator.logical.powershell
882882
captures:
883883
1: punctuation.definition.keyword.powershell
884-
- match: \B(-)(?i:join|split){{kebab_break}}
884+
- match: (-)(?i:join|split){{operator_break}}
885885
scope: keyword.operator.string.powershell
886886
captures:
887887
1: punctuation.definition.keyword.powershell
888-
- match: \B(-)(?i:is(?:not)?){{kebab_break}}
888+
- match: (-)(?i:is(?:not)?){{operator_break}}
889889
scope: keyword.operator.logical.powershell
890890
captures:
891891
1: punctuation.definition.keyword.powershell
892-
- match: \B(-)(?i:and|or|not|xor){{kebab_break}}
892+
- match: (-)(?i:and|or|not|xor){{operator_break}}
893893
scope: keyword.operator.logical.powershell
894894
captures:
895895
1: punctuation.definition.keyword.powershell
896-
- match: \B(-)(?i:band|bor|bnot|bxor|sh[lr]){{kebab_break}}
896+
- match: (-)(?i:band|bor|bnot|bxor|sh[lr]){{operator_break}}
897897
scope: keyword.operator.bitwise.powershell
898898
captures:
899899
1: punctuation.definition.keyword.powershell
900-
- match: \B(-)(?i:f){{kebab_break}}
900+
- match: (-)(?i:f){{operator_break}}
901901
scope: keyword.operator.string-format.powershell
902902
captures:
903903
1: punctuation.definition.keyword.powershell
@@ -1174,15 +1174,15 @@ contexts:
11741174

11751175
numbers:
11761176
# Binary numbers
1177-
- match: \b(0[bB])([01]*)({{int_suffix}}?{{unit_suffix}}?)
1177+
- match: (0[bB])([01]*)({{int_suffix}}?{{unit_suffix}}?)
11781178
scope: meta.number.integer.binary.powershell
11791179
captures:
11801180
1: constant.numeric.base.powershell
11811181
2: constant.numeric.value.powershell
11821182
3: constant.numeric.suffix.powershell
11831183
push: members
11841184
# Hexadecimal numbers
1185-
- match: \b(0[xX])(\h*)({{int_suffix}}?{{unit_suffix}}?)
1185+
- match: (0[xX])(\h*)({{int_suffix}}?{{unit_suffix}}?)
11861186
scope: meta.number.integer.hexadecimal.powershell
11871187
captures:
11881188
1: constant.numeric.base.powershell
@@ -1215,14 +1215,14 @@ contexts:
12151215
8: constant.numeric.suffix.powershell
12161216
push: members
12171217
# "Decimal" numbers
1218-
- match: \b(\d+)({{dec_suffix}}{{unit_suffix}}?)
1218+
- match: (\d+)({{dec_suffix}}{{unit_suffix}}?)
12191219
scope: meta.number.float.decimal.powershell
12201220
captures:
12211221
1: constant.numeric.value.powershell
12221222
2: constant.numeric.suffix.powershell
12231223
push: members
12241224
# Integers
1225-
- match: \b(\d+)({{int_suffix}}?{{unit_suffix}}?)
1225+
- match: (\d+)({{int_suffix}}?{{unit_suffix}}?)
12261226
scope: meta.number.integer.decimal.powershell
12271227
captures:
12281228
1: constant.numeric.value.powershell
@@ -1367,6 +1367,7 @@ contexts:
13671367

13681368
variables:
13691369
kebab_break: (?![\w-])
1370+
operator_break: (?![[:alpha:]]|-\d)
13701371
builtin_types: |-
13711372
\b(?x:
13721373
void | null | object | bool | char | string

Tests/syntax_test_PowerShell.ps1

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,39 @@ $a3[1..2]
16431643
# ^ punctuation.definition.keyword.powershell
16441644
# ^^ variable.other.readwrite.powershell
16451645
# ^ punctuation.definition.variable.powershell
1646+
1 -bxor1
1647+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
1648+
# ^^^^^ keyword.operator.bitwise.powershell
1649+
# ^ punctuation.definition.keyword.powershell
1650+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
1651+
1-bxor1
1652+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
1653+
# ^^^^^ keyword.operator.bitwise.powershell
1654+
# ^ punctuation.definition.keyword.powershell
1655+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
1656+
$a -bxor$a
1657+
# ^^ variable.other.readwrite.powershell
1658+
# ^ punctuation.definition.variable.powershell
1659+
# ^^^^^ keyword.operator.bitwise.powershell
1660+
# ^ punctuation.definition.keyword.powershell
1661+
# ^^ variable.other.readwrite.powershell
1662+
# ^ punctuation.definition.variable.powershell
1663+
$a-bxor$a
1664+
# ^^ variable.other.readwrite.powershell
1665+
# ^ punctuation.definition.variable.powershell
1666+
# ^^^^^ keyword.operator.bitwise.powershell
1667+
# ^ punctuation.definition.keyword.powershell
1668+
# ^^ variable.other.readwrite.powershell
1669+
# ^ punctuation.definition.variable.powershell
1670+
-bnot1
1671+
# ^^^^^ keyword.operator.bitwise.powershell
1672+
# ^ punctuation.definition.keyword.powershell
1673+
# ^ meta.number.integer.decimal.powershell constant.numeric.value.powershell
1674+
-bnot$a
1675+
# ^^^^^ keyword.operator.bitwise.powershell
1676+
# ^ punctuation.definition.keyword.powershell
1677+
# ^^ variable.other.readwrite.powershell
1678+
# ^ punctuation.definition.variable.powershell
16461679
$a -icontains $c
16471680
# ^^ variable.other.readwrite.powershell
16481681
# ^ punctuation.definition.variable.powershell

0 commit comments

Comments
 (0)