File tree Expand file tree Collapse file tree 2 files changed +75
-12
lines changed
jscomp/syntax/tests/parsing/grammar/pattern Expand file tree Collapse file tree 2 files changed +75
-12
lines changed Original file line number Diff line number Diff line change 11let someDict = dict {
2- "one" : "one" ,
2+ "one" : "one" ,
33}
44
55let dict {"one" : ?one } = someDict
66
77let foo = () => switch someDict {
88| dict {"one" : "one" } => Js .log ("one" )
99| _ => Js .log ("not one" )
10- }
10+ }
11+
12+ @unboxed
13+ type rec json =
14+ | Boolean (bool )
15+ | @as (null ) Null
16+ | String (string )
17+ | Number (float )
18+ | Object (dict <json >)
19+ | Array (array <t >)
20+
21+ type user = {
22+ name : string ,
23+ age ?: float ,
24+ }
25+
26+ let decodeUser = (json : json ): option <user > => {
27+ switch json {
28+ | Object (dict {
29+ "name" : String (name ),
30+ "age" : ageJson
31+ }) =>
32+ Some ({
33+ name ,
34+ age : ?switch ageJson {
35+ | Number (age ) => Some (age )
36+ | _ =>
37+ /* Invalid age JSON type */
38+ None
39+ },
40+ })
41+ | _ =>
42+ Js .log ("Not an object." )
43+ None
44+ }
45+ }
46+
47+ Js .log (decodeUser (jsonParse (` {"name": "John", "age": 30}` )))
Original file line number Diff line number Diff line change 1- let someDict = Primitive_dict.make [|("one", {js|one|js})|]
2- let (({ one = ((one)[@res.optional ]);_})[@res.dictPattern ]) = someDict
3- let foo =
4- ((Function$
5- (fun () ->
6- match someDict with
7- | (({ one = {js|one|js};_})[@res.dictPattern ]) ->
8- Js.log {js|one|js}
9- | _ -> Js.log {js|not one|js}))
10- [@res.arity 1])
1+
2+ Syntax error!
3+ tests/parsing/grammar/pattern/dict.res:28:12-16
4+
5+ 26 │ let decodeUser = (json: json): option<user> => {
6+ 27 │ switch json {
7+ 28 │ | Object(dict{
8+ 29 │ "name": String(name),
9+ 30 │ "age": ageJson
10+
11+ Did you forget a `)` here?
12+
13+
14+ Syntax error!
15+ tests/parsing/grammar/pattern/dict.res:31:6
16+
17+ 29 ┆ "name": String(name),
18+ 30 ┆ "age": ageJson
19+ 31 ┆ }) =>
20+ 32 ┆ Some({
21+ 33 ┆ name,
22+
23+ I'm not sure what to parse here when looking at ")".
24+
25+
26+ Syntax error!
27+ tests/parsing/grammar/pattern/dict.res:41:3
28+
29+ 39 ┆ },
30+ 40 ┆ })
31+ 41 ┆ | _ =>
32+ 42 ┆ Js.log("Not an object.")
33+ 43 ┆ None
34+
35+ I'm not sure what to parse here when looking at "|".
36+
You can’t perform that action at this time.
0 commit comments