Skip to content

Commit aefb65b

Browse files
authored
Fix error reporting when parsing an lident (rescript-lang#448)
* Fix syntax error in tests * Add tests for illegal identifier * Fix parsing lident
1 parent b50be68 commit aefb65b

File tree

6 files changed

+34
-4
lines changed

6 files changed

+34
-4
lines changed

syntax/src/res_core.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ let rec parseLident p =
583583
loop p
584584
end
585585
in
586+
Parser.err p (Diagnostics.lident p.Parser.token);
586587
Parser.next p;
587588
loop p;
588589
match p.Parser.token with

syntax/tests/parsing/errors/expressions/expected/letBinding.res.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,21 @@
6868

6969
This let-binding misses an expression
7070

71+
72+
Syntax error!
73+
tests/parsing/errors/expressions/letBinding.res:15:12
74+
75+
13 │ }
76+
14 │
77+
15 │ let foo as 'x = ()
78+
16 │
79+
80+
I'm expecting a lowercase name like `user or `age`
81+
7182
let foo = 2.
7283
let foo = true
7384
let foo = 2
7485
let foo = f ()
7586
let foo = ((2)[@ns.braces ])
76-
let foo = (("foo")[@ns.braces ])
87+
let foo = (("foo")[@ns.braces ])
88+
let foo as x = ()

syntax/tests/parsing/errors/expressions/letBinding.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ let foo = == {
1212
"foo"
1313
}
1414

15+
let foo as 'x = ()

syntax/tests/parsing/errors/other/expected/labelledParameters.res.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
1 │ let f = (x, y=2, z) => x + y + z
66
2 │
7-
3 │ type f = (x: int, y: int) => int
7+
3 │ let g = (~?x, ~y=2, ~z) => x + y + z
88

99
A labeled parameter starts with a `~`. Did you mean: `~y`?
1010

@@ -14,10 +14,24 @@
1414

1515
1 │ let f = (x, y=2, z) => x + y + z
1616
2 │
17-
3 │ type f = (x: int, y: int) => int
17+
3 │ let g = (~?x, ~y=2, ~z) => x + y + z
1818
4 │
19+
5 │ type f = (x: int, y: int) => int
20+
21+
I'm expecting a lowercase name like `user or `age`
22+
23+
24+
Syntax error!
25+
tests/parsing/errors/other/labelledParameters.res:5:11
26+
27+
3 │ let g = (~?x, ~y=2, ~z) => x + y + z
28+
4 │
29+
5 │ type f = (x: int, y: int) => int
30+
6 │
1931

2032
A labeled parameter starts with a `~`. Did you mean: `~x`?
2133

2234
let f x ?(y= 2) z = (x + y) + z
35+
let g ~x:((x)[@ns.namedArgLoc ]) ?y:(((y)[@ns.namedArgLoc ])= 2)
36+
~z:((z)[@ns.namedArgLoc ]) = (x + y) + z
2337
type nonrec f = x:int -> y:int -> int
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
let f = (x, y=2, z) => x + y + z
22

3+
let g = (~?x, ~y=2, ~z) => x + y + z
4+
35
type f = (x: int, y: int) => int

syntax/tests/printer/comments/pattern.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let /* before */ 123 /* after */ = 123
1111
// Ppat_interval of constant * constant
1212

1313
// Ppat_alias
14-
let /* before pat */ p /* after pat */ as /* before alias */ 'x /* after alias */ = ()
14+
let /* before pat */ p /* after pat */ as /* before alias */ x /* after alias */ = ()
1515
let /*c0 */ (/* c1 */ p /* c2 */ as /* c3 */x /* c4*/) as /* c5 */ y /* c6 */ = ()
1616

1717
// Ppat_array

0 commit comments

Comments
 (0)