Skip to content

Commit 24a58d8

Browse files
committed
fix: correct floating point literal parsing
1 parent 33a3868 commit 24a58d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

grammar.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ module.exports = grammar({
141141
decimal_floating_point_literal: _ => token(choice(
142142
seq(DECIMAL_DIGITS, '.', optional(DECIMAL_DIGITS), optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
143143
seq('.', DECIMAL_DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), optional(/[fFdD]/)),
144-
seq(DIGITS, /[eEpP]/, optional(choice('-', '+')), DECIMAL_DIGITS, optional(/[fFdD]/)),
144+
seq(DIGITS, /[eE]/, optional(choice('-', '+')), DECIMAL_DIGITS, optional(/[fFdD]/)),
145145
seq(DIGITS, optional(seq((/[eE]/), optional(choice('-', '+')), DECIMAL_DIGITS)), (/[fFdD]/)),
146146
)),
147147

@@ -152,7 +152,7 @@ module.exports = grammar({
152152
seq(optional(HEX_DIGITS), '.', HEX_DIGITS),
153153
),
154154
optional(seq(
155-
/[eEpP]/,
155+
/[pP]/,
156156
optional(choice('-', '+')),
157157
DIGITS,
158158
optional(/[fFdD]/),

test/corpus/literals.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ hex integer literals
2020
0xa_bcd_ef0;
2121
0Xa_bcd_ef0;
2222
0X8000L;
23+
0x7e-0x21;
2324

2425
---
2526

2627
(program
2728
(expression_statement (hex_integer_literal))
2829
(expression_statement (hex_integer_literal))
29-
(expression_statement (hex_integer_literal)))
30+
(expression_statement (hex_integer_literal))
31+
(expression_statement (binary_expression (hex_integer_literal) (hex_integer_literal))))
3032

3133
======================
3234
octal integer literals
@@ -77,7 +79,7 @@ floating point literals
7779
0.0e-4;
7880
.2e-2;
7981
0x5.4;
80-
0x5.4e-10;
82+
0x5.4p-10;
8183

8284
---
8385

0 commit comments

Comments
 (0)