Skip to content

Commit 516b442

Browse files
authored
Merge pull request #568 from weswigham/master
Add numeric seperator support
2 parents 0247d14 + de397cd commit 516b442

File tree

5 files changed

+483
-33
lines changed

5 files changed

+483
-33
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,25 +1232,28 @@ repository:
12321232
- include: '#expression'
12331233
- include: '#punctuation-comma'
12341234

1235+
# With respect to seperators, we allow mroe than is syntacically valid below
1236+
# (multiple consecutive and trailing ones are errors), to be more graceful
1237+
# when the code contains errors
12351238
numeric-literal:
12361239
patterns:
12371240
- name: constant.numeric.hex.ts
1238-
match: \b(?<!\$)0(x|X)[0-9a-fA-F]+\b(?!\$)
1241+
match: \b(?<!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)
12391242
- name: constant.numeric.binary.ts
1240-
match: \b(?<!\$)0(b|B)[01]+\b(?!\$)
1243+
match: \b(?<!\$)0(b|B)[01][01_]*\b(?!\$)
12411244
- name: constant.numeric.octal.ts
1242-
match: \b(?<!\$)0(o|O)?[0-7]+\b(?!\$)
1245+
match: \b(?<!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)
12431246
- match: |-
12441247
(?x)
12451248
(?<!\$)(?:
1246-
(?:\b[0-9]+(\.)[0-9]+[eE][+-]?[0-9]+\b)| # 1.1E+3
1247-
(?:\b[0-9]+(\.)[eE][+-]?[0-9]+\b)| # 1.E+3
1248-
(?:\B(\.)[0-9]+[eE][+-]?[0-9]+\b)| # .1E+3
1249-
(?:\b[0-9]+[eE][+-]?[0-9]+\b)| # 1E+3
1250-
(?:\b[0-9]+(\.)[0-9]+\b)| # 1.1
1251-
(?:\b[0-9]+(\.)\B)| # 1.
1252-
(?:\B(\.)[0-9]+\b)| # .1
1253-
(?:\b[0-9]+\b(?!\.)) # 1
1249+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
1250+
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
1251+
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
1252+
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
1253+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
1254+
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
1255+
(?:\B(\.)[0-9][0-9_]*\b)| # .1
1256+
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
12541257
)(?!\$)
12551258
captures:
12561259
'0': {name: constant.numeric.decimal.ts}

TypeScript.tmLanguage

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,32 +3845,32 @@
38453845
<key>name</key>
38463846
<string>constant.numeric.hex.ts</string>
38473847
<key>match</key>
3848-
<string>\b(?&lt;!\$)0(x|X)[0-9a-fA-F]+\b(?!\$)</string>
3848+
<string>\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)</string>
38493849
</dict>
38503850
<dict>
38513851
<key>name</key>
38523852
<string>constant.numeric.binary.ts</string>
38533853
<key>match</key>
3854-
<string>\b(?&lt;!\$)0(b|B)[01]+\b(?!\$)</string>
3854+
<string>\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$)</string>
38553855
</dict>
38563856
<dict>
38573857
<key>name</key>
38583858
<string>constant.numeric.octal.ts</string>
38593859
<key>match</key>
3860-
<string>\b(?&lt;!\$)0(o|O)?[0-7]+\b(?!\$)</string>
3860+
<string>\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)</string>
38613861
</dict>
38623862
<dict>
38633863
<key>match</key>
38643864
<string>(?x)
38653865
(?&lt;!\$)(?:
3866-
(?:\b[0-9]+(\.)[0-9]+[eE][+-]?[0-9]+\b)| # 1.1E+3
3867-
(?:\b[0-9]+(\.)[eE][+-]?[0-9]+\b)| # 1.E+3
3868-
(?:\B(\.)[0-9]+[eE][+-]?[0-9]+\b)| # .1E+3
3869-
(?:\b[0-9]+[eE][+-]?[0-9]+\b)| # 1E+3
3870-
(?:\b[0-9]+(\.)[0-9]+\b)| # 1.1
3871-
(?:\b[0-9]+(\.)\B)| # 1.
3872-
(?:\B(\.)[0-9]+\b)| # .1
3873-
(?:\b[0-9]+\b(?!\.)) # 1
3866+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
3867+
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
3868+
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
3869+
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
3870+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
3871+
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
3872+
(?:\B(\.)[0-9][0-9_]*\b)| # .1
3873+
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
38743874
)(?!\$)</string>
38753875
<key>captures</key>
38763876
<dict>

TypeScriptReact.tmLanguage

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,32 +3791,32 @@
37913791
<key>name</key>
37923792
<string>constant.numeric.hex.tsx</string>
37933793
<key>match</key>
3794-
<string>\b(?&lt;!\$)0(x|X)[0-9a-fA-F]+\b(?!\$)</string>
3794+
<string>\b(?&lt;!\$)0(x|X)[0-9a-fA-F][0-9a-fA-F_]*\b(?!\$)</string>
37953795
</dict>
37963796
<dict>
37973797
<key>name</key>
37983798
<string>constant.numeric.binary.tsx</string>
37993799
<key>match</key>
3800-
<string>\b(?&lt;!\$)0(b|B)[01]+\b(?!\$)</string>
3800+
<string>\b(?&lt;!\$)0(b|B)[01][01_]*\b(?!\$)</string>
38013801
</dict>
38023802
<dict>
38033803
<key>name</key>
38043804
<string>constant.numeric.octal.tsx</string>
38053805
<key>match</key>
3806-
<string>\b(?&lt;!\$)0(o|O)?[0-7]+\b(?!\$)</string>
3806+
<string>\b(?&lt;!\$)0(o|O)?[0-7][0-7_]*\b(?!\$)</string>
38073807
</dict>
38083808
<dict>
38093809
<key>match</key>
38103810
<string>(?x)
38113811
(?&lt;!\$)(?:
3812-
(?:\b[0-9]+(\.)[0-9]+[eE][+-]?[0-9]+\b)| # 1.1E+3
3813-
(?:\b[0-9]+(\.)[eE][+-]?[0-9]+\b)| # 1.E+3
3814-
(?:\B(\.)[0-9]+[eE][+-]?[0-9]+\b)| # .1E+3
3815-
(?:\b[0-9]+[eE][+-]?[0-9]+\b)| # 1E+3
3816-
(?:\b[0-9]+(\.)[0-9]+\b)| # 1.1
3817-
(?:\b[0-9]+(\.)\B)| # 1.
3818-
(?:\B(\.)[0-9]+\b)| # .1
3819-
(?:\b[0-9]+\b(?!\.)) # 1
3812+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1.1E+3
3813+
(?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*\b)| # 1.E+3
3814+
(?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # .1E+3
3815+
(?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*\b)| # 1E+3
3816+
(?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*\b)| # 1.1
3817+
(?:\b[0-9][0-9_]*(\.)\B)| # 1.
3818+
(?:\B(\.)[0-9][0-9_]*\b)| # .1
3819+
(?:\b[0-9][0-9_]*\b(?!\.)) # 1
38203820
)(?!\$)</string>
38213821
<key>captures</key>
38223822
<dict>

0 commit comments

Comments
 (0)