Skip to content

Commit ae94630

Browse files
Issue 5164: Allow capital E in scientific notation (#5242)
* Remove prohibition of capital E exponent signifier * Remove exponent error format test * Add test for lowercase 'e' in exponent notation * Update output Co-authored-by: Geoffrey Booth <[email protected]>
1 parent d3f06e3 commit ae94630

File tree

10 files changed

+16
-33
lines changed

10 files changed

+16
-33
lines changed

docs/v2/annotated-source/lexer.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,6 @@ <h2 id="tokenizers">Tokenizers</h2>
552552
<span class="hljs-keyword">switch</span>
553553
<span class="hljs-keyword">when</span> <span class="hljs-regexp">/^0[BOX]/</span>.test number
554554
@error <span class="hljs-string">&quot;radix prefix in &#x27;<span class="hljs-subst">#{number}</span>&#x27; must be lowercase&quot;</span>, offset: <span class="hljs-number">1</span>
555-
<span class="hljs-keyword">when</span> <span class="hljs-regexp">/^(?!0x).*E/</span>.test number
556-
@error <span class="hljs-string">&quot;exponential notation in &#x27;<span class="hljs-subst">#{number}</span>&#x27; must be indicated with a lowercase &#x27;e&#x27;&quot;</span>,
557-
offset: number.indexOf(<span class="hljs-string">&#x27;E&#x27;</span>)
558555
<span class="hljs-keyword">when</span> <span class="hljs-regexp">/^0\d*[89]/</span>.test number
559556
@error <span class="hljs-string">&quot;decimal literal &#x27;<span class="hljs-subst">#{number}</span>&#x27; must not be prefixed with &#x27;0&#x27;&quot;</span>, length: lexedLength
560557
<span class="hljs-keyword">when</span> <span class="hljs-regexp">/^0\d+/</span>.test number

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/v2/test.html

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21868,13 +21868,6 @@ <h1>CoffeeScript Test Suite</h1>
2186821868
0X0
2186921869
^
2187021870
'''
21871-
assertErrorFormat '''
21872-
10E0
21873-
''', '''
21874-
[stdin]:1:3: error: exponential notation in '10E0' must be indicated with a lowercase 'e'
21875-
10E0
21876-
^
21877-
'''
2187821871
assertErrorFormat '''
2187921872
018
2188021873
''', '''
@@ -29359,12 +29352,16 @@ <h2>Another heading</h2>
2935929352
eq Number::toString, 0o777['toString']
2936029353
eq Number::toString, 0o777.toString
2936129354

29362-
test "#2060: Disallow uppercase radix prefixes and exponential notation", ->
29363-
for char in ['b', 'o', 'x', 'e']
29355+
test "#2060: Disallow uppercase radix prefixes", ->
29356+
for char in ['b', 'o', 'x']
2936429357
program = "0#{char}0"
2936529358
doesNotThrowCompileError program, bare: yes
2936629359
throwsCompileError program.toUpperCase(), bare: yes
2936729360

29361+
test "#5164: Allow lowercase and uppercase exponent notation", ->
29362+
doesNotThrow -> CoffeeScript.compile "0e0", bare: yes
29363+
doesNotThrow -> CoffeeScript.compile "0E0", bare: yes
29364+
2936829365
test "#2224: hex literals with 0b or B or E", ->
2936929366
eq 176, 0x0b0
2937029367
eq 177, 0x0B1

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/lexer.js

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ exports.Lexer = class Lexer
270270
switch
271271
when /^0[BOX]/.test number
272272
@error "radix prefix in '#{number}' must be lowercase", offset: 1
273-
when /^(?!0x).*E/.test number
274-
@error "exponential notation in '#{number}' must be indicated with a lowercase 'e'",
275-
offset: number.indexOf('E')
276273
when /^0\d*[89]/.test number
277274
@error "decimal literal '#{number}' must not be prefixed with '0'", length: lexedLength
278275
when /^0\d+/.test number

test/error_messages.coffee

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,6 @@ test "invalid numbers", ->
806806
0X0
807807
^
808808
'''
809-
assertErrorFormat '''
810-
10E0
811-
''', '''
812-
[stdin]:1:3: error: exponential notation in '10E0' must be indicated with a lowercase 'e'
813-
10E0
814-
^
815-
'''
816809
assertErrorFormat '''
817810
018
818811
''', '''

test/numbers.coffee

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ test "Python-style octal literal notation '0o777'", ->
6666
eq Number::toString, 0o777['toString']
6767
eq Number::toString, 0o777.toString
6868

69-
test "#2060: Disallow uppercase radix prefixes and exponential notation", ->
70-
for char in ['b', 'o', 'x', 'e']
69+
test "#2060: Disallow uppercase radix prefixes", ->
70+
for char in ['b', 'o', 'x']
7171
program = "0#{char}0"
7272
doesNotThrowCompileError program, bare: yes
7373
throwsCompileError program.toUpperCase(), bare: yes
7474

75+
test "#5164: Allow lowercase and uppercase exponent notation", ->
76+
doesNotThrow -> CoffeeScript.compile "0e0", bare: yes
77+
doesNotThrow -> CoffeeScript.compile "0E0", bare: yes
78+
7579
test "#2224: hex literals with 0b or B or E", ->
7680
eq 176, 0x0b0
7781
eq 177, 0x0B1

0 commit comments

Comments
 (0)