Skip to content

Commit 98a2331

Browse files
authored
Simplified number regexes (#5430)
1 parent 5748210 commit 98a2331

File tree

12 files changed

+20
-14
lines changed

12 files changed

+20
-14
lines changed

docs/v2/annotated-source/lexer.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -2605,9 +2605,9 @@ <h2 id="constants">Constants</h2>
26052605
^ 0b[01](?:_?[01])*n? | <span class="hljs-comment"># binary</span>
26062606
^ 0o[0-7](?:_?[0-7])*n? | <span class="hljs-comment"># octal</span>
26072607
^ 0x[\da-f](?:_?[\da-f])*n? | <span class="hljs-comment"># hex</span>
2608-
^ \d+n | <span class="hljs-comment"># decimal bigint</span>
2609-
^ (?:\d(?:_?\d)*)? \.? (?:\d(?:_?\d)*)+ <span class="hljs-comment"># decimal</span>
2610-
(?:e[+-]? (?:\d(?:_?\d)*)+ )?
2608+
^ \d+(?:_\d+)*n | <span class="hljs-comment"># decimal bigint</span>
2609+
^ (?:\d+(?:_\d+)*)? \.? \d+(?:_\d+)* <span class="hljs-comment"># decimal</span>
2610+
(?:e[+-]? \d+(?:_\d+)* )?
26112611
</span></pre></div></div>
26122612

26132613
</li>

docs/v2/annotated-source/nodes.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10237,7 +10237,7 @@ <h2 id="constants">Constants</h2>
1023710237

1023810238
<div class="content"><div class='highlight'><pre>TAB = <span class="hljs-string">&#x27; &#x27;</span>
1023910239

10240-
SIMPLENUM = <span class="hljs-regexp">/^[+-]?(?:\d(?:_?\d)*)+$/</span>
10240+
SIMPLENUM = <span class="hljs-regexp">/^[+-]?\d+(?:_\d+)*$/</span>
1024110241
SIMPLE_STRING_OMIT = <span class="hljs-regexp">/\s*\n\s*/g</span>
1024210242
LEADING_BLANK_LINE = <span class="hljs-regexp">/^[^\n\S]*\n/</span>
1024310243
TRAILING_BLANK_LINE = <span class="hljs-regexp">/\n[^\n\S]*$/</span>

docs/v2/browser-compiler-legacy/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/browser-compiler-modern/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/test.html

+3
Original file line numberDiff line numberDiff line change
@@ -29389,6 +29389,9 @@ <h2>Another heading</h2>
2938929389
test "Parser recognizes decimal BigInt literals", ->
2939029390
eq 42n, BigInt 42
2939129391

29392+
test "Parser recognizes decimal BigInt literals with separator", ->
29393+
eq 1_000n, BigInt 1000
29394+
2939229395
test "Parser recognizes binary BigInt literals", ->
2939329396
eq 42n, 0b101010n
2939429397

lib/coffeescript-browser-compiler-legacy/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript-browser-compiler-modern/coffeescript.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/lexer.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/nodes.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,9 @@ NUMBER = ///
13101310
^ 0b[01](?:_?[01])*n? | # binary
13111311
^ 0o[0-7](?:_?[0-7])*n? | # octal
13121312
^ 0x[\da-f](?:_?[\da-f])*n? | # hex
1313-
^ \d+n | # decimal bigint
1314-
^ (?:\d(?:_?\d)*)? \.? (?:\d(?:_?\d)*)+ # decimal
1315-
(?:e[+-]? (?:\d(?:_?\d)*)+ )?
1313+
^ \d+(?:_\d+)*n | # decimal bigint
1314+
^ (?:\d+(?:_\d+)*)? \.? \d+(?:_\d+)* # decimal
1315+
(?:e[+-]? \d+(?:_\d+)* )?
13161316
# decimal without support for numeric literal separators for reference:
13171317
# \d*\.?\d+ (?:e[+-]?\d+)?
13181318
///i

src/nodes.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -5772,7 +5772,7 @@ LEVEL_ACCESS = 6 # ...[0]
57725772
# Tabs are two spaces for pretty printing.
57735773
TAB = ' '
57745774

5775-
SIMPLENUM = /^[+-]?(?:\d(?:_?\d)*)+$/
5775+
SIMPLENUM = /^[+-]?\d+(?:_\d+)*$/
57765776
SIMPLE_STRING_OMIT = /\s*\n\s*/g
57775777
LEADING_BLANK_LINE = /^[^\n\S]*\n/
57785778
TRAILING_BLANK_LINE = /\n[^\n\S]*$/

test/numbers_bigint.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ test "BigInt exists", ->
77
test "Parser recognizes decimal BigInt literals", ->
88
eq 42n, BigInt 42
99

10+
test "Parser recognizes decimal BigInt literals with separator", ->
11+
eq 1_000n, BigInt 1000
12+
1013
test "Parser recognizes binary BigInt literals", ->
1114
eq 42n, 0b101010n
1215

0 commit comments

Comments
 (0)