File tree Expand file tree Collapse file tree 2 files changed +44
-39
lines changed
tests/parsing/grammar/pattern/expected Expand file tree Collapse file tree 2 files changed +44
-39
lines changed Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ let is_signature_item_start = function
131
131
132
132
let is_atomic_pattern_start = function
133
133
| Token. Int _ | String _ | Codepoint _ | Backtick | Lparen | Lbracket | Lbrace
134
- | Underscore | Lident _ | Uident _ | List | Exception | Percent ->
134
+ | Underscore | Lident _ | Uident _ | List | Dict | Exception | Percent ->
135
135
true
136
136
| _ -> false
137
137
@@ -170,8 +170,8 @@ let is_structure_item_start = function
170
170
171
171
let is_pattern_start = function
172
172
| Token. Int _ | Float _ | String _ | Codepoint _ | Backtick | True | False
173
- | Minus | Plus | Lparen | Lbracket | Lbrace | List | Underscore | Lident _
174
- | Uident _ | Hash | Exception | Percent | Module | At ->
173
+ | Minus | Plus | Lparen | Lbracket | Lbrace | List | Dict | Underscore
174
+ | Lident _ | Uident _ | Hash | Exception | Percent | Module | At ->
175
175
true
176
176
| _ -> false
177
177
Original file line number Diff line number Diff line change 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
-
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])
11
+ type json =
12
+ | Boolean of bool
13
+ | Null [@as null]
14
+ | String of string
15
+ | Number of float
16
+ | Object of json dict
17
+ | Array of t array [@@unboxed ]
18
+ type nonrec user = {
19
+ name: string ;
20
+ age: float [@res.optional ]}
21
+ let decodeUser =
22
+ ((Function$
23
+ (fun (json : json) ->
24
+ (((match json with
25
+ | Object
26
+ (({ name = String name; age = ageJson;_})[@res.dictPattern ])
27
+ ->
28
+ Some
29
+ {
30
+ name;
31
+ age =
32
+ (((match ageJson with
33
+ | Number age -> Some age
34
+ | _ -> None))[@res.optional ])
35
+ }
36
+ | _ -> (Js.log {js|Not an object.|js}; None))
37
+ [@res.braces ]) : user option)))
38
+ [@res.arity 1])
39
+ ;;Js.log
40
+ (decodeUser
41
+ (jsonParse (({js|{"name": "John", "age": 30}|js})[@res.template ])))
You can’t perform that action at this time.
0 commit comments