File tree 4 files changed +66
-13
lines changed
tests/parsing/errors/scanner
4 files changed +66
-13
lines changed Original file line number Diff line number Diff line change 22
22
23
23
- Handle absolute file paths in gentype. https://github.com/rescript-lang/rescript-compiler/pull/7111
24
24
- Fix "rescript format" with many files. https://github.com/rescript-lang/rescript-compiler/pull/7081
25
+ - Fix exponential notation syntax. https://github.com/rescript-lang/rescript/pull/7174
25
26
26
27
#### :house : Internal
27
28
Original file line number Diff line number Diff line change @@ -203,24 +203,30 @@ let scanIdentifier scanner =
203
203
204
204
let scanDigits scanner ~base =
205
205
if base < = 10 then
206
- let rec loop scanner =
206
+ let rec loop scanner foundDigits =
207
207
match scanner.ch with
208
- | '0' .. '9' | '_' ->
208
+ | '0' .. '9' ->
209
209
next scanner;
210
- loop scanner
211
- | _ -> ()
210
+ loop scanner true
211
+ | '_' ->
212
+ next scanner;
213
+ loop scanner false
214
+ | _ -> foundDigits
212
215
in
213
- loop scanner
216
+ loop scanner false
214
217
else
215
- let rec loop scanner =
218
+ let rec loop scanner foundDigits =
216
219
match scanner.ch with
217
220
(* hex *)
218
- | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_' ->
221
+ | '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ->
222
+ next scanner;
223
+ loop scanner true
224
+ | '_' ->
219
225
next scanner;
220
- loop scanner
221
- | _ -> ()
226
+ loop scanner false
227
+ | _ -> foundDigits
222
228
in
223
- loop scanner
229
+ loop scanner false
224
230
225
231
(* float: (0…9) { 0…9∣ _ } [. { 0…9∣ _ }] [(e∣ E) [+∣ -] (0…9) { 0…9∣ _ }] *)
226
232
let scanNumber scanner =
@@ -245,25 +251,30 @@ let scanNumber scanner =
245
251
8 )
246
252
| _ -> 10
247
253
in
248
- scanDigits scanner ~base ;
254
+ ignore ( scanDigits scanner ~base ) ;
249
255
250
256
(* *)
251
257
let isFloat =
252
258
if '.' == scanner.ch then (
253
259
next scanner;
254
- scanDigits scanner ~base ;
260
+ ignore ( scanDigits scanner ~base ) ;
255
261
true )
256
262
else false
257
263
in
258
264
259
265
(* exponent part *)
260
266
let isFloat =
267
+ let startPos = position scanner in
261
268
match scanner.ch with
262
269
| 'e' | 'E' | 'p' | 'P' ->
263
270
(match peek scanner with
264
271
| '+' | '-' -> next2 scanner
265
272
| _ -> next scanner);
266
- scanDigits scanner ~base ;
273
+ let endPos = position scanner in
274
+ let foundDigits = scanDigits scanner ~base in
275
+ if not foundDigits then
276
+ scanner.err ~start Pos ~end Pos
277
+ (Diagnostics. message " Expected digits after exponential notation." );
267
278
true
268
279
| _ -> isFloat
269
280
in
Original file line number Diff line number Diff line change
1
+
2
+ Syntax error!
3
+ tests/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
+ tests/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