-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathtest_ambiguous_variant_j.expected.ml
202 lines (195 loc) · 6.48 KB
/
test_ambiguous_variant_j.expected.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
(* Auto-generated from "test_ambiguous_variant.atd" *)
[@@@ocaml.warning "-27-32-33-35-39"]
type ambiguous' = Test_ambiguous_variant_t.ambiguous' =
Int of int
| String of string
type ambiguous = Test_ambiguous_variant_t.ambiguous =
Int of int
| String of string
let write_ambiguous' : _ -> ambiguous' -> _ = (
Atdgen_runtime.Oj_run.write_with_adapter Json_adapters.Identity.restore (
fun ob (x : ambiguous') ->
match x with
| Int x ->
Buffer.add_string ob "[\"Int\",";
(
Yojson.Safe.write_int
) ob x;
Buffer.add_char ob ']'
| String x ->
Buffer.add_string ob "[\"String\",";
(
Yojson.Safe.write_string
) ob x;
Buffer.add_char ob ']'
)
)
let string_of_ambiguous' ?(len = 1024) x =
let ob = Buffer.create len in
write_ambiguous' ob x;
Buffer.contents ob
let read_ambiguous' = (
Atdgen_runtime.Oj_run.read_with_adapter Json_adapters.Identity.normalize (
fun p lb ->
Yojson.Safe.read_space p lb;
match Yojson.Safe.start_any_variant p lb with
| `Edgy_bracket -> (
match Yojson.Safe.read_ident p lb with
| "Int" ->
Atdgen_runtime.Oj_run.read_until_field_value p lb;
let x = (
Atdgen_runtime.Oj_run.read_int
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_gt p lb;
(Int x : ambiguous')
| "String" ->
Atdgen_runtime.Oj_run.read_until_field_value p lb;
let x = (
Atdgen_runtime.Oj_run.read_string
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_gt p lb;
(String x : ambiguous')
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
| `Double_quote -> (
match Yojson.Safe.finish_string p lb with
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
| `Square_bracket -> (
match Atdgen_runtime.Oj_run.read_string p lb with
| "Int" ->
Yojson.Safe.read_space p lb;
Yojson.Safe.read_comma p lb;
Yojson.Safe.read_space p lb;
let x = (
Atdgen_runtime.Oj_run.read_int
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_rbr p lb;
(Int x : ambiguous')
| "String" ->
Yojson.Safe.read_space p lb;
Yojson.Safe.read_comma p lb;
Yojson.Safe.read_space p lb;
let x = (
Atdgen_runtime.Oj_run.read_string
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_rbr p lb;
(String x : ambiguous')
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
)
)
let ambiguous'_of_string s =
read_ambiguous' (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
let write_ambiguous : _ -> ambiguous -> _ = (
Atdgen_runtime.Oj_run.write_with_adapter Json_adapters.Identity.restore (
fun ob (x : ambiguous) ->
match x with
| Int x ->
Buffer.add_string ob "[\"Int\",";
(
Yojson.Safe.write_int
) ob x;
Buffer.add_char ob ']'
| String x ->
Buffer.add_string ob "[\"String\",";
(
Yojson.Safe.write_string
) ob x;
Buffer.add_char ob ']'
)
)
let string_of_ambiguous ?(len = 1024) x =
let ob = Buffer.create len in
write_ambiguous ob x;
Buffer.contents ob
let read_ambiguous = (
Atdgen_runtime.Oj_run.read_with_adapter Json_adapters.Identity.normalize (
fun p lb ->
Yojson.Safe.read_space p lb;
match Yojson.Safe.start_any_variant p lb with
| `Edgy_bracket -> (
match Yojson.Safe.read_ident p lb with
| "Int" ->
Atdgen_runtime.Oj_run.read_until_field_value p lb;
let x = (
Atdgen_runtime.Oj_run.read_int
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_gt p lb;
(Int x : ambiguous)
| "String" ->
Atdgen_runtime.Oj_run.read_until_field_value p lb;
let x = (
Atdgen_runtime.Oj_run.read_string
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_gt p lb;
(String x : ambiguous)
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
| `Double_quote -> (
match Yojson.Safe.finish_string p lb with
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
| `Square_bracket -> (
match Atdgen_runtime.Oj_run.read_string p lb with
| "Int" ->
Yojson.Safe.read_space p lb;
Yojson.Safe.read_comma p lb;
Yojson.Safe.read_space p lb;
let x = (
Atdgen_runtime.Oj_run.read_int
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_rbr p lb;
(Int x : ambiguous)
| "String" ->
Yojson.Safe.read_space p lb;
Yojson.Safe.read_comma p lb;
Yojson.Safe.read_space p lb;
let x = (
Atdgen_runtime.Oj_run.read_string
) p lb
in
Yojson.Safe.read_space p lb;
Yojson.Safe.read_rbr p lb;
(String x : ambiguous)
| x ->
Atdgen_runtime.Oj_run.invalid_variant_tag p x
)
)
)
let ambiguous_of_string s =
read_ambiguous (Yojson.Safe.init_lexer ()) (Lexing.from_string s)
(** {3 Generic Modules } *)
module Ambiguous' = struct
type nonrec t = ambiguous'
let write = write_ambiguous'
let read = read_ambiguous'
let to_string = string_of_ambiguous'
let of_string = ambiguous'_of_string
end
module Ambiguous = struct
type nonrec t = ambiguous
let write = write_ambiguous
let read = read_ambiguous
let to_string = string_of_ambiguous
let of_string = ambiguous_of_string
end