forked from ocaml-community/yojson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.mli
246 lines (200 loc) · 7.84 KB
/
read.mli
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
val prettify : ?std:bool -> string -> string
(** Combined parser and pretty-printer.
See [to_string] for the role of the optional [std] argument. *)
val compact : ?std:bool -> string -> string
(** Combined parser and printer.
See [to_string] for the role of the optional [std] argument. *)
(** {2 JSON readers} *)
val from_string :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
string -> json
(** Read a JSON value from a string.
@param buf use this buffer at will during parsing instead of creating
a new one.
@param fname data file name to be used in error messages. It does
not have to be a real file.
@param lnum number of the first line of input. Default is 1.
*)
val from_channel :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
in_channel -> json
(** Read a JSON value from a channel.
See [from_string] for the meaning of the optional arguments. *)
val from_file :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
string -> json
(** Read a JSON value from a file.
See [from_string] for the meaning of the optional arguments. *)
type lexer_state = Lexer_state.t = {
buf : Bi_outbuf.t;
mutable lnum : int;
mutable bol : int;
mutable fname : string option;
}
(** This alias is provided for backward compatibility.
New code should refer to {!Yojson.lexer_state} directly.
*)
val init_lexer :
?buf: Bi_outbuf.t ->
?fname: string ->
?lnum: int ->
unit -> lexer_state
(** This alias is provided for backward compatibility.
New code should use {!Yojson.init_lexer} directly. *)
val from_lexbuf :
lexer_state ->
?stream:bool ->
Lexing.lexbuf -> json
(** Read a JSON value from a lexbuf.
A valid initial [lexer_state] can be created with [init_lexer].
See [from_string] for the meaning of the optional arguments.
@param stream indicates whether more data may follow. The default value
is false and indicates that only JSON whitespace can be found between
the end of the JSON value and the end of the input. *)
val stream_from_string :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
string -> json Stream.t
(** Input a sequence of JSON values from a string.
Whitespace between JSON values is fine but not required.
See [from_string] for the meaning of the optional arguments. *)
val stream_from_channel :
?buf:Bi_outbuf.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel -> json Stream.t
(** Input a sequence of JSON values from a channel.
Whitespace between JSON values is fine but not required.
@param fin finalization function executed once when the end of the
stream is reached either because there is no more input or because
the input could not be parsed, raising an exception.
See [from_string] for the meaning of the other optional arguments. *)
val stream_from_file :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
string -> json Stream.t
(** Input a sequence of JSON values from a file.
Whitespace between JSON values is fine but not required.
See [from_string] for the meaning of the optional arguments. *)
val stream_from_lexbuf :
lexer_state ->
?fin:(unit -> unit) ->
Lexing.lexbuf -> json Stream.t
(** Input a sequence of JSON values from a lexbuf.
A valid initial [lexer_state] can be created with [init_lexer].
Whitespace between JSON values is fine but not required.
See [stream_from_channel] for the meaning of the optional [fin]
argument. *)
type json_line = [ `Json of json | `Exn of exn ]
(** The type of values resulting from a parsing attempt of a JSON value. *)
val linestream_from_channel :
?buf:Bi_outbuf.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel -> json_line Stream.t
(** Input a sequence of JSON values, one per line, from a channel.
Exceptions raised when reading malformed lines are caught
and represented using [`Exn].
See [stream_from_channel] for the meaning of the optional [fin]
argument.
See [from_string] for the meaning of the other optional arguments. *)
val linestream_from_file :
?buf:Bi_outbuf.t ->
?fname:string ->
?lnum:int ->
string -> json_line Stream.t
(** Input a sequence of JSON values, one per line, from a file.
Exceptions raised when reading malformed lines are caught
and represented using [`Exn].
See [stream_from_channel] for the meaning of the optional [fin]
argument.
See [from_string] for the meaning of the other optional arguments. *)
(**/**)
(* begin undocumented section *)
val finish_string : lexer_state -> Lexing.lexbuf -> string
val read_string : lexer_state -> Lexing.lexbuf -> string
val read_ident : lexer_state -> Lexing.lexbuf -> string
val map_string :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to finish_string *)
val map_ident :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to read_ident *)
type variant_kind = [ `Edgy_bracket | `Square_bracket | `Double_quote ]
val start_any_variant : lexer_state -> Lexing.lexbuf -> variant_kind
val finish_variant : lexer_state -> Lexing.lexbuf -> json option
val finish_skip_variant : lexer_state -> Lexing.lexbuf -> unit
val read_lt : lexer_state -> Lexing.lexbuf -> unit
val read_gt : lexer_state -> Lexing.lexbuf -> unit
val read_comma : lexer_state -> Lexing.lexbuf -> unit
val finish_stringlit : lexer_state -> Lexing.lexbuf -> string
val finish_skip_stringlit : lexer_state -> Lexing.lexbuf -> unit
val finish_escaped_char : lexer_state -> Lexing.lexbuf -> unit
val finish_comment : lexer_state -> Lexing.lexbuf -> unit
val read_space : lexer_state -> Lexing.lexbuf -> unit
val read_eof : Lexing.lexbuf -> bool
val read_null : lexer_state -> Lexing.lexbuf -> unit
val read_null_if_possible : lexer_state -> Lexing.lexbuf -> bool
val read_bool : lexer_state -> Lexing.lexbuf -> bool
val read_int : lexer_state -> Lexing.lexbuf -> int
val read_int8 : lexer_state -> Lexing.lexbuf -> char
val read_int32 : lexer_state -> Lexing.lexbuf -> int32
val read_int64 : lexer_state -> Lexing.lexbuf -> int64
val read_number : lexer_state -> Lexing.lexbuf -> float
val skip_ident : lexer_state -> Lexing.lexbuf -> unit
val read_sequence :
('a -> lexer_state -> Lexing.lexbuf -> 'a) ->
'a ->
lexer_state ->
Lexing.lexbuf -> 'a
val read_list :
(lexer_state -> Lexing.lexbuf -> 'a) ->
lexer_state ->
Lexing.lexbuf -> 'a list
val read_list_rev :
(lexer_state -> Lexing.lexbuf -> 'a) ->
lexer_state ->
Lexing.lexbuf -> 'a list
val read_array_end : Lexing.lexbuf -> unit
val read_array_sep : lexer_state -> Lexing.lexbuf -> unit
val read_array :
(lexer_state -> Lexing.lexbuf -> 'a) ->
lexer_state ->
Lexing.lexbuf -> 'a array
val read_tuple :
(int -> 'a -> lexer_state -> Lexing.lexbuf -> 'a) ->
'a ->
lexer_state ->
Lexing.lexbuf -> 'a
val start_any_tuple : lexer_state -> Lexing.lexbuf -> bool
val read_lpar : lexer_state -> Lexing.lexbuf -> unit
val read_rpar : lexer_state -> Lexing.lexbuf -> unit
val read_tuple_end : Lexing.lexbuf -> unit
val read_tuple_end2 : lexer_state -> bool -> Lexing.lexbuf -> unit
val read_tuple_sep : lexer_state -> Lexing.lexbuf -> unit
val read_tuple_sep2 : lexer_state -> bool -> Lexing.lexbuf -> unit
val read_lbr : lexer_state -> Lexing.lexbuf -> unit
val read_rbr : lexer_state -> Lexing.lexbuf -> unit
val read_fields :
('a -> string -> lexer_state -> Lexing.lexbuf -> 'a) ->
'a ->
lexer_state ->
Lexing.lexbuf -> 'a
val read_lcurl : lexer_state -> Lexing.lexbuf -> unit
val read_object_end : Lexing.lexbuf -> unit
val read_object_sep : lexer_state -> Lexing.lexbuf -> unit
val read_colon : lexer_state -> Lexing.lexbuf -> unit
val read_json : lexer_state -> Lexing.lexbuf -> json
val skip_json : lexer_state -> Lexing.lexbuf -> unit
(* end undocumented section *)
(**/**)