Skip to content

Commit

Permalink
Simplified number regexes (#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
STRd6 committed Oct 25, 2022
1 parent 5748210 commit 98a2331
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions docs/v2/annotated-source/lexer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2605,9 +2605,9 @@ <h2 id="constants">Constants</h2>
^ 0b[01](?:_?[01])*n? | <span class="hljs-comment"># binary</span>
^ 0o[0-7](?:_?[0-7])*n? | <span class="hljs-comment"># octal</span>
^ 0x[\da-f](?:_?[\da-f])*n? | <span class="hljs-comment"># hex</span>
^ \d+n | <span class="hljs-comment"># decimal bigint</span>
^ (?:\d(?:_?\d)*)? \.? (?:\d(?:_?\d)*)+ <span class="hljs-comment"># decimal</span>
(?:e[+-]? (?:\d(?:_?\d)*)+ )?
^ \d+(?:_\d+)*n | <span class="hljs-comment"># decimal bigint</span>
^ (?:\d+(?:_\d+)*)? \.? \d+(?:_\d+)* <span class="hljs-comment"># decimal</span>
(?:e[+-]? \d+(?:_\d+)* )?
</span></pre></div></div>

</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/annotated-source/nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -10237,7 +10237,7 @@ <h2 id="constants">Constants</h2>

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

SIMPLENUM = <span class="hljs-regexp">/^[+-]?(?:\d(?:_?\d)*)+$/</span>
SIMPLENUM = <span class="hljs-regexp">/^[+-]?\d+(?:_\d+)*$/</span>
SIMPLE_STRING_OMIT = <span class="hljs-regexp">/\s*\n\s*/g</span>
LEADING_BLANK_LINE = <span class="hljs-regexp">/^[^\n\S]*\n/</span>
TRAILING_BLANK_LINE = <span class="hljs-regexp">/\n[^\n\S]*$/</span>
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/v2/browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/v2/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -29389,6 +29389,9 @@ <h2>Another heading</h2>
test "Parser recognizes decimal BigInt literals", ->
eq 42n, BigInt 42

test "Parser recognizes decimal BigInt literals with separator", ->
eq 1_000n, BigInt 1000

test "Parser recognizes binary BigInt literals", ->
eq 42n, 0b101010n

Expand Down
2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-legacy/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript-browser-compiler-modern/coffeescript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/coffeescript/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1310,9 +1310,9 @@ NUMBER = ///
^ 0b[01](?:_?[01])*n? | # binary
^ 0o[0-7](?:_?[0-7])*n? | # octal
^ 0x[\da-f](?:_?[\da-f])*n? | # hex
^ \d+n | # decimal bigint
^ (?:\d(?:_?\d)*)? \.? (?:\d(?:_?\d)*)+ # decimal
(?:e[+-]? (?:\d(?:_?\d)*)+ )?
^ \d+(?:_\d+)*n | # decimal bigint
^ (?:\d+(?:_\d+)*)? \.? \d+(?:_\d+)* # decimal
(?:e[+-]? \d+(?:_\d+)* )?
# decimal without support for numeric literal separators for reference:
# \d*\.?\d+ (?:e[+-]?\d+)?
///i
Expand Down
2 changes: 1 addition & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5772,7 +5772,7 @@ LEVEL_ACCESS = 6 # ...[0]
# Tabs are two spaces for pretty printing.
TAB = ' '

SIMPLENUM = /^[+-]?(?:\d(?:_?\d)*)+$/
SIMPLENUM = /^[+-]?\d+(?:_\d+)*$/
SIMPLE_STRING_OMIT = /\s*\n\s*/g
LEADING_BLANK_LINE = /^[^\n\S]*\n/
TRAILING_BLANK_LINE = /\n[^\n\S]*$/
Expand Down
3 changes: 3 additions & 0 deletions test/numbers_bigint.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ test "BigInt exists", ->
test "Parser recognizes decimal BigInt literals", ->
eq 42n, BigInt 42

test "Parser recognizes decimal BigInt literals with separator", ->
eq 1_000n, BigInt 1000

test "Parser recognizes binary BigInt literals", ->
eq 42n, 0b101010n

Expand Down

0 comments on commit 98a2331

Please sign in to comment.