Skip to content

Commit f21161d

Browse files
author
deathaxe
authored
Fix number scopes (#187)
This commit... 1. removes `_` separators in digits as both Windows Powershell and PWSH 7.4 raise errors if present. 2. adjusts number related scopes to ST core syntaxes 3. ensures `.` after numbers is scoped member accessor.
1 parent bea280e commit f21161d

File tree

3 files changed

+185
-145
lines changed

3 files changed

+185
-145
lines changed

PowerShell.sublime-syntax

+52-44
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ first_line_match: |-
1717
)
1818
1919
variables:
20-
dec_digits: (?:[\d_]*\d)
21-
dec_exponent: (?:[eE][-+]?{{dec_digits}})
22-
float_suffix: (?i:[fdm](?!b))
23-
integer_suffix: (?i:ul?|lu?)
24-
bytes_unit: (?i:[kmgtp]b)
20+
dec_exponent: (?:[eE][-+]?\d*)
21+
dec_suffix: '[dDlL]'
22+
double_suffix: '[dD]'
23+
long_suffix: '[lL]'
24+
unit_suffix: (?i:[kmgtp]b)
2525
kebab_break: (?![\w-])
2626

2727
contexts:
@@ -548,48 +548,56 @@ contexts:
548548
pop: true
549549

550550
numeric-constant:
551-
- match: \b((0[xX])[\h_]*\h({{integer_suffix}})?)({{bytes_unit}})?\b
552-
captures:
553-
1: constant.numeric.integer.hexadecimal.powershell
554-
2: punctuation.definition.numeric.base.powershell
555-
3: storage.type.numeric.powershell
556-
4: keyword.other.unit.powershell
557-
- match: \b((0[bB])[01_]*[01]({{integer_suffix}})?)({{bytes_unit}})?\b
558-
captures:
559-
1: constant.numeric.integer.binary.powershell
560-
2: punctuation.definition.numeric.base.powershell
561-
3: storage.type.numeric.powershell
562-
4: keyword.other.unit.powershell
551+
- match: \b(0[bB])([01]*)({{long_suffix}}?{{unit_suffix}}?)\b
552+
scope: meta.number.integer.binary.powershell
553+
captures:
554+
1: constant.numeric.base.powershell
555+
2: constant.numeric.value.powershell
556+
3: constant.numeric.suffix.powershell
557+
push: members
558+
- match: \b(0[xX])(\h*)({{long_suffix}}?{{unit_suffix}}?)\b
559+
scope: meta.number.integer.hexadecimal.powershell
560+
captures:
561+
1: constant.numeric.base.powershell
562+
2: constant.numeric.value.powershell
563+
3: constant.numeric.suffix.powershell
564+
push: members
563565
- match: |-
564-
(?x:
565-
(
566-
\b{{dec_digits}}
567-
(?:
568-
(?:
569-
(?:(\.(?!\.))\d*) # No `_` after the `.`
570-
{{dec_exponent}}?
571-
| {{dec_exponent}}
572-
)
573-
({{float_suffix}})?
574-
| ({{float_suffix}})
575-
)
576-
| \b{{dec_digits}}\.(?!\.)
577-
| (\.)\d+
578-
)
579-
({{bytes_unit}}\b)?
566+
(?x)
567+
(
568+
# .10 .10e5
569+
(\.)\d+{{dec_exponent}}?
570+
# 1.2 1.2e-3 1.e2 1e2
571+
| \d+ (?: (\.) \d+ {{dec_exponent}}? | (\.)? {{dec_exponent}} )
580572
)
581-
captures:
582-
1: constant.numeric.float.decimal.powershell
573+
( {{dec_suffix}}? {{unit_suffix}}? )\b
574+
|
575+
# 10.l 10.lGB 10.GB
576+
( \d+ (\.) )
577+
( {{dec_suffix}} {{unit_suffix}}? | {{unit_suffix}} )\b
578+
scope: meta.number.float.decimal.powershell
579+
captures:
580+
1: constant.numeric.value.powershell
583581
2: punctuation.separator.decimal.powershell
584-
3: storage.type.numeric.powershell
585-
4: storage.type.numeric.powershell
586-
5: punctuation.separator.decimal.powershell
587-
6: keyword.other.unit.powershell
588-
- match: \b((?:0|[1-9]{{dec_digits}}?)({{integer_suffix}})?)({{bytes_unit}})?\b
589-
captures:
590-
1: constant.numeric.integer.decimal.powershell
591-
2: storage.type.numeric.powershell
592-
3: keyword.other.unit.powershell
582+
3: punctuation.separator.decimal.powershell
583+
4: punctuation.separator.decimal.powershell
584+
5: constant.numeric.suffix.powershell
585+
6: constant.numeric.value.powershell
586+
7: punctuation.separator.decimal.powershell
587+
8: constant.numeric.suffix.powershell
588+
push: members
589+
- match: \b(\d+)({{double_suffix}}{{unit_suffix}}?)\b
590+
scope: meta.number.float.decimal.powershell
591+
captures:
592+
1: constant.numeric.value.powershell
593+
2: constant.numeric.suffix.powershell
594+
push: members
595+
- match: \b(\d+)({{long_suffix}}?{{unit_suffix}}?)\b
596+
scope: meta.number.integer.decimal.powershell
597+
captures:
598+
1: constant.numeric.value.powershell
599+
2: constant.numeric.suffix.powershell
600+
push: members
593601

594602
script-block:
595603
- match: (%)?(\{)

Tests/syntax_test_Function.ps1

+7-7
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function Verb-Noun {
141141
#^^^^^^^^^^^^^^^^^^^^^^ meta.attribute
142142
# ^^^^^^^^ variable.parameter.attribute
143143
# ^ keyword.operator.assignment
144-
# ^ constant.numeric.integer
144+
# ^ constant.numeric.value
145145
# ^ punctuation.separator
146146
ParameterSetName = 'Parameter Set 1')]
147147
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.attribute
@@ -177,9 +177,9 @@ function Verb-Noun {
177177
# <- punctuation.section.brackets.begin
178178
# ^^^^^^^^^^^^ support.function.attribute
179179
# ^ punctuation.section.group.begin
180-
# ^ constant.numeric.integer
180+
# ^ constant.numeric.value
181181
# ^ punctuation.separator
182-
# ^ constant.numeric.integer
182+
# ^ constant.numeric.value
183183
# ^ punctuation.section.group.end
184184
# ^ punctuation.section.brackets.end
185185
[ValidateSet("sun", "moon", "earth")]
@@ -256,9 +256,9 @@ function Verb-Noun {
256256
# <- meta.attribute punctuation.section.brackets.begin
257257
# ^^^^^^^^^^^^ support.function.attribute
258258
# ^ punctuation.section.group.begin
259-
# ^ constant.numeric.integer
259+
# ^ constant.numeric.value
260260
# ^ punctuation.separator
261-
# ^ constant.numeric.integer
261+
# ^ constant.numeric.value
262262
# ^ punctuation.section.group.end
263263
# ^ punctuation.section.brackets.end
264264
[int32]
@@ -294,9 +294,9 @@ function Verb-Noun {
294294
# <- meta.attribute punctuation.section.brackets.begin
295295
# ^ meta.attribute support.function.attribute
296296
# ^ meta.attribute punctuation.section.group.begin
297-
# ^ meta.attribute constant.numeric.integer
297+
# ^ meta.attribute meta.number.integer.decimal constant.numeric.value
298298
# ^ punctuation.separator
299-
# ^^ meta.attribute constant.numeric.integer
299+
# ^^ meta.attribute meta.number.integer.decimal constant.numeric.value
300300
# ^ meta.attribute punctuation.section.group.end
301301
# ^ meta.attribute punctuation.section.brackets.end
302302
[String]

0 commit comments

Comments
 (0)