Skip to content

Commit 5fff229

Browse files
committed
add fix, but that changes list parsing slightly
1 parent c4dcac5 commit 5fff229

File tree

4 files changed

+81
-28
lines changed

4 files changed

+81
-28
lines changed

jscomp/syntax/src/res_grammar.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ let is_structure_item_start = function
171171
let is_pattern_start = function
172172
| Token.Int _ | Float _ | String _ | Codepoint _ | Backtick | True | False
173173
| Minus | Plus | Lparen | Lbracket | Lbrace | List | Dict | Underscore
174-
| Lident _ | Uident _ | Hash | Exception | Percent | Module | At ->
174+
| DotDotDot | Lident _ | Uident _ | Hash | Exception | Percent | Module | At
175+
->
175176
true
176177
| _ -> false
177178

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,56 @@
1-
2-
Syntax error!
3-
tests/parsing/grammar/pattern/variantSpreads.res:37:10-12
4-
5-
35 │ let lookupOpt = (b: option<b>) =>
6-
36 │ switch b {
7-
37 │ | Some(...a as a) => doWithA(a)
8-
38 │ | Some(Four) => Js.log("four")
9-
39 │ | Some(Five) => Js.log("five")
10-
11-
Did you forget a `)` here?
12-
13-
14-
Syntax error!
15-
tests/parsing/grammar/pattern/variantSpreads.res:37:10-12
16-
17-
35 │ let lookupOpt = (b: option<b>) =>
18-
36 │ switch b {
19-
37 │ | Some(...a as a) => doWithA(a)
20-
38 │ | Some(Four) => Js.log("four")
21-
39 │ | Some(Five) => Js.log("five")
22-
23-
Did you forget a `}` here?
24-
1+
type nonrec a =
2+
| One
3+
| Two
4+
| Three
5+
type nonrec b =
6+
| ... of a
7+
| Four
8+
| Five
9+
type nonrec c =
10+
| Six
11+
| Seven
12+
type nonrec d =
13+
| ... of b
14+
| ... of c
15+
let doWithA =
16+
((Function$
17+
(fun (a : a) ->
18+
((match a with
19+
| One -> Js.log {js|aaa|js}
20+
| Two -> Js.log {js|twwwoooo|js}
21+
| Three -> Js.log {js|threeeee|js})
22+
[@res.braces ])))
23+
[@res.arity 1])
24+
let doWithB =
25+
((Function$
26+
(fun (b : b) ->
27+
((match b with
28+
| One -> Js.log {js|aaa|js}
29+
| _ -> Js.log {js|twwwoooo|js})
30+
[@res.braces ])))
31+
[@res.arity 1])
32+
let lookup =
33+
((Function$
34+
(fun (b : b) ->
35+
match b with
36+
| ((#a)[@res.patVariantSpread ]) as a -> doWithA a
37+
| Four -> Js.log {js|four|js}
38+
| Five -> Js.log {js|five|js}))
39+
[@res.arity 1])
40+
let lookup2 =
41+
((Function$
42+
(fun (d : d) ->
43+
match d with
44+
| ((#a)[@res.patVariantSpread ]) as a -> doWithA a
45+
| ((#b)[@res.patVariantSpread ]) as b -> doWithB b
46+
| Six|Seven -> Js.log {js|Got rest of d|js}))
47+
[@res.arity 1])
48+
let lookupOpt =
49+
((Function$
50+
(fun (b : b option) ->
51+
match b with
52+
| Some (((#a)[@res.patVariantSpread ]) as a) -> doWithA a
53+
| Some (Four) -> Js.log {js|four|js}
54+
| Some (Five) -> Js.log {js|five|js}
55+
| None -> Js.log {js|None|js}))
56+
[@res.arity 1])

jscomp/syntax/tests/parsing/recovery/pattern/expected/list.res.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424

2525

2626
Syntax error!
27-
tests/parsing/recovery/pattern/list.res:4:13
27+
tests/parsing/recovery/pattern/list.res:4:9-11
2828

2929
2 │ | list{} => ()
3030
3 │ | list{1, list{} => ()
3131
4 │ | list{}...1, ...list{3, 4} => ()
3232
5 │ }
3333
6 │
3434

35-
I'm not sure what to parse here when looking at ",".
35+
Did you forget a `}` here?
3636

37-
;;match x with | [] -> () | 1::[]::[] -> () | [] -> 1
37+
;;match x with | [] -> () | 1::[]::[] -> () | [] -> [%rescript.exprhole ]
38+
;;1
3839
;;[3; 4]
3940
;;()

tests/tests/src/VariantPatternMatchingSpreads.js

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

0 commit comments

Comments
 (0)