-
Notifications
You must be signed in to change notification settings - Fork 60
/
read.mli
218 lines (181 loc) · 8.01 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
val prettify : ?std:bool -> string -> string
(** Combined parser and pretty-printer.
See [to_string] for the role of the optional [std] argument and raised exceptions. *)
val compact : ?std:bool -> string -> string
(** Combined parser and printer.
See [to_string] for the role of the optional [std] argument and raised exceptions. *)
(** {2 JSON readers} *)
exception Finally of exn * exn
(** Exception describing a failure in both finalizer and parsing. *)
val from_string : ?buf:Buffer.t -> ?fname:string -> ?lnum:int -> string -> t
(** 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.
@raise Json_error if parsing fails.
*)
val from_channel :
?buf:Buffer.t -> ?fname:string -> ?lnum:int -> in_channel -> t
(** Read a JSON value from a channel.
See [from_string] for the meaning of the optional arguments and raised exceptions. *)
val from_file : ?buf:Buffer.t -> ?fname:string -> ?lnum:int -> string -> t
(** Read a JSON value from a file.
See [from_string] for the meaning of the optional arguments and raised exceptions. *)
type lexer_state = Common.Lexer_state.t = {
buf : Buffer.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:Buffer.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 -> t
(** 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 and raised exceptions.
@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 seq_from_string :
?buf:Buffer.t -> ?fname:string -> ?lnum:int -> string -> t Seq.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 and raised exceptions. *)
val seq_from_channel :
?buf:Buffer.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel ->
t Seq.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
sequence is reached either because there is no more input or because
the input could not be parsed, raising an exception.
@raise Finally When the parsing and the finalizer both raised, [Finally (exn, fin_exn)]
is raised, [exn] being the parsing exception and [fin_exn] the finalizer one.
See [from_string] for the meaning of the other optional arguments and other raised exceptions. *)
val seq_from_file :
?buf:Buffer.t -> ?fname:string -> ?lnum:int -> string -> t Seq.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 and raised exceptions. *)
val seq_from_lexbuf :
lexer_state -> ?fin:(unit -> unit) -> Lexing.lexbuf -> t Seq.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.
@raise Finally When the parsing and the finalizer both raised, [Finally (exn, fin_exn)]
is raised, [exn] being the parsing exception and [fin_exn] the finalizer one.
See [seq_from_channel] for the meaning of the optional [fin]
argument and other raised exceptions. *)
type json_line = [ `Json of t | `Exn of exn ]
(** The type of values resulting from a parsing attempt of a JSON value. *)
val lineseq_from_channel :
?buf:Buffer.t ->
?fin:(unit -> unit) ->
?fname:string ->
?lnum:int ->
in_channel ->
json_line Seq.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 [seq_from_channel] for the meaning of the optional [fin]
argument.
See [from_string] for the meaning of the other optional arguments and raised exceptions. *)
val lineseq_from_file :
?buf:Buffer.t -> ?fname:string -> ?lnum:int -> string -> json_line Seq.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 [seq_from_channel] for the meaning of the optional [fin]
argument.
See [from_string] for the meaning of the other optional arguments and raised exceptions. *)
val read_t : lexer_state -> Lexing.lexbuf -> t
(** Read a JSON value from the given lexer_state and lexing buffer and return it.
Provided as a reader function for atdgen.
*)
(**/**)
(* 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_ident :
lexer_state -> (string -> int -> int -> 'a) -> Lexing.lexbuf -> 'a
(* equivalent to read_ident *)
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_lpar : lexer_state -> Lexing.lexbuf -> unit
val read_rpar : lexer_state -> Lexing.lexbuf -> unit
val read_lbr : lexer_state -> Lexing.lexbuf -> unit
val read_rbr : lexer_state -> Lexing.lexbuf -> unit
val read_fields :
('acc -> string -> lexer_state -> Lexing.lexbuf -> 'acc) ->
'acc ->
lexer_state ->
Lexing.lexbuf ->
'acc
val read_abstract_fields :
(lexer_state -> Lexing.lexbuf -> 'key) ->
('acc -> 'key -> lexer_state -> Lexing.lexbuf -> 'acc) ->
'acc ->
lexer_state ->
Lexing.lexbuf ->
'acc
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 -> t
val skip_json : lexer_state -> Lexing.lexbuf -> unit
val buffer_json : lexer_state -> Lexing.lexbuf -> unit
(* end undocumented section *)
(**/**)