File tree 4 files changed +66
-13
lines changed
tests/syntax_tests/data/parsing/errors/scanner
4 files changed +66
-13
lines changed Original file line number Diff line number Diff line change 11
11
> - :nail_care : [ Polish]
12
12
13
13
# 12.0.0-alpha.6 (Unreleased)
14
+ - Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
14
15
15
16
# 12.0.0-alpha.5
16
17
Original file line number Diff line number Diff line change @@ -209,24 +209,30 @@ let scan_identifier scanner =
209
209
210
210
let scan_digits scanner ~base =
211
211
if base < = 10 then
212
- let rec loop scanner =
212
+ let rec loop scanner found_digits =
213
213
match scanner.ch with
214
- | '0' .. '9' | '_' ->
214
+ | '0' .. '9' ->
215
215
next scanner;
216
- loop scanner
217
- | _ -> ()
216
+ loop scanner true
217
+ | '_' ->
218
+ next scanner;
219
+ loop scanner false
220
+ | _ -> found_digits
218
221
in
219
- loop scanner
222
+ loop scanner false
220
223
else
221
- let rec loop scanner =
224
+ let rec loop scanner found_digits =
222
225
match scanner.ch with
223
226
(* hex *)
224
- | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' ->
227
+ | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ->
228
+ next scanner;
229
+ loop scanner true
230
+ | '_' ->
225
231
next scanner;
226
- loop scanner
227
- | _ -> ()
232
+ loop scanner false
233
+ | _ -> found_digits
228
234
in
229
- loop scanner
235
+ loop scanner false
230
236
231
237
(* float: (0…9) { 0…9∣ _ } [. { 0…9∣ _ }] [(e∣ E) [+∣ -] (0…9) { 0…9∣ _ }] *)
232
238
let scan_number scanner =
@@ -251,25 +257,30 @@ let scan_number scanner =
251
257
8 )
252
258
| _ -> 10
253
259
in
254
- scan_digits scanner ~base ;
260
+ ignore ( scan_digits scanner ~base ) ;
255
261
256
262
(* *)
257
263
let is_float =
258
264
if '.' == scanner.ch then (
259
265
next scanner;
260
- scan_digits scanner ~base ;
266
+ ignore ( scan_digits scanner ~base ) ;
261
267
true )
262
268
else false
263
269
in
264
270
265
271
(* exponent part *)
266
272
let is_float =
273
+ let start_pos = position scanner in
267
274
match scanner.ch with
268
275
| 'e' | 'E' | 'p' | 'P' ->
269
276
(match peek scanner with
270
277
| '+' | '-' -> next2 scanner
271
278
| _ -> next scanner);
272
- scan_digits scanner ~base ;
279
+ let end_pos = position scanner in
280
+ let found_digits = scan_digits scanner ~base in
281
+ if not found_digits then
282
+ scanner.err ~start_pos ~end_pos
283
+ (Diagnostics. message " Expected digits after exponential notation." );
273
284
true
274
285
| _ -> is_float
275
286
in
Original file line number Diff line number Diff line change
1
+
2
+ Syntax error!
3
+ syntax_tests/data/parsing/errors/scanner/exponent_notation.res:7:10
4
+
5
+ 5 │ let x = 1_e_1
6
+ 6 │
7
+ 7 │ let x = 1e
8
+ 8 │
9
+ 9 │ let x = 1_e_
10
+
11
+ Expected digits after exponential notation.
12
+
13
+
14
+ Syntax error!
15
+ syntax_tests/data/parsing/errors/scanner/exponent_notation.res:9:11
16
+
17
+ 7 │ let x = 1e
18
+ 8 │
19
+ 9 │ let x = 1_e_
20
+ 10 │
21
+ 11 │ let x = 1.
22
+
23
+ Expected digits after exponential notation.
24
+
25
+ let x = 1e1
26
+ let x = 1e_1
27
+ let x = 1_e_1
28
+ let x = 1e
29
+ let x = 1_e_
30
+ let x = 1.
Original file line number Diff line number Diff line change
1
+ let x = 1e1
2
+
3
+ let x = 1e_1
4
+
5
+ let x = 1_e_1
6
+
7
+ let x = 1e
8
+
9
+ let x = 1_e_
10
+
11
+ let x = 1 .
You can’t perform that action at this time.
0 commit comments