Skip to content

Commit

Permalink
Merge pull request #1294 from Thom1729/javascript-fancy-numbers
Browse files Browse the repository at this point in the history
[JavaScript] Add BigInt suffix and Numeric Separators
  • Loading branch information
wbond authored Dec 1, 2017
2 parents 12f8481 + d0a6f14 commit 3ebd282
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 11 deletions.
52 changes: 41 additions & 11 deletions JavaScript/JavaScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1375,26 +1375,56 @@ contexts:
- include: object-property

literal-number:
- match: '(?i)(?:\B[-+]|\b)0x[0-9a-f]*\.(\B|\b[0-9]+)'
- match: '(?i)(?:\B[-+]|\b)0x[0-9a-f_]*\.(\B|\b[0-9_]+)'
scope: invalid.illegal.numeric.hex.js
pop: true
- match: '(?:\B[-+]|\b)0[0-9]+\.(\B|\b[0-9]+)'
- match: '(?:\B[-+]|\b)0[0-9_]+\.(\B|\b[0-9_]+)'
scope: invalid.illegal.numeric.octal.js
pop: true

- match: '[+-]?0[0-9]+'
scope: constant.numeric.octal.js invalid.deprecated.octal.js
pop: true

- match: '[+-]?(0[Xx])[0-9a-fA-F_]*(n)?'
scope: constant.numeric.hexadecimal.js
captures:
1: punctuation.definition.numeric.hexadecimal.js
2: storage.type.numeric.bigint.js
pop: true

- match: '[+-]?(0[Oo])[0-7_]*(n)?'
scope: constant.numeric.octal.js
captures:
1: punctuation.definition.numeric.octal.js
2: storage.type.numeric.bigint.js
pop: true

- match: '[+-]?(0[Bb])[0-1_]*(n)?'
scope: constant.numeric.binary.js
captures:
1: punctuation.definition.numeric.binary.js
2: storage.type.numeric.bigint.js
pop: true

- match: '[+-]?[0-9][0-9_]*(n)'
scope: constant.numeric.decimal.js
captures:
1: storage.type.numeric.bigint.js
pop: true

- match: |-
(?xi)
(?x)
(?:\B[-+])?
(?:
\b0b[0-1]*| # binary
\b0o[0-7]*| # octal
\b0x[0-9a-f]*| # hex
(?i:
(
\B\.[0-9]+| # e.g. .999
\b[0-9]+(\.[0-9]*)? # e.g. 999.999, 999. or 999
)(e[-+]?[0-9]+)? # e.g. e+123, E-123
\B\.[0-9][0-9_]*| # e.g. .999
\b[0-9][0-9_]*(\.[0-9_]*)?# e.g. 999.999, 999. or 999
)(e[-+]?[0-9_]*)? # e.g. e+123, E-123
)
scope: constant.numeric.js
scope: constant.numeric.decimal.js
pop: true
- match: '(?:\B[-+]|\b)(Infinity)\b'
scope: constant.language.infinity.js
pop: true
Expand Down
52 changes: 52 additions & 0 deletions JavaScript/syntax_test_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,55 @@ function yy (a, b) {
// ^ punctuation.section.group.end
// ^ meta.block punctuation.section.block - meta.function
}

// Integers

123_456_789_0n;
// ^^^^^^^^^^^^^^ constant.numeric.decimal
// ^ storage.type.numeric.bigint

0;
// ^ constant.numeric.decimal

0123456789;
// ^^^^^^^^^^ constant.numeric.octal invalid.deprecated.octal

0b0110_1001_1001_0110n;
// ^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.binary
// ^^ punctuation.definition.numeric.binary
// ^ storage.type.numeric.bigint

0o0123_4567n;
// ^^^^^^^^^^^^ constant.numeric.octal
// ^^ punctuation.definition.numeric.octal
// ^ storage.type.numeric.bigint

0x01_23_45_67_89_ab_CD_efn;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.hexadecimal
// ^^ punctuation.definition.numeric.hexadecimal
// ^ storage.type.numeric.bigint

0B0; 0O0; 0X0;
// ^^^ constant.numeric.binary
// ^^^ constant.numeric.octal
// ^^^ constant.numeric.hexadecimal

// Floats

1_234_567_890.123_456_789_0;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.decimal

.123_456_789_0;
// ^^^^^^^^^^^^^^ constant.numeric.decimal

0123.45;
// ^^^^^^^ invalid.illegal.numeric.octal

12345e6_7_8;
// ^^^^^^^^^^^ constant.numeric.decimal

123.456e+789;
// ^^^^^^^^^^^^ constant.numeric.decimal

.123E-7_8_9;
// ^^^^^^^^^^^ constant.numeric.decimal

0 comments on commit 3ebd282

Please sign in to comment.