(n_atoms, n_chars), where n_atoms is the number of atoms in S-expression sexp, and n_chars is the number of characters in the atoms of the S-expression.
Scan functions
val scan_sexp : ?buf:Stdlib.Buffer.t ->Stdlib.Lexing.lexbuf ->t
scan_sexp ?buf lexbuf scans an S-expression from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_sexps : ?buf:Stdlib.Buffer.t ->Stdlib.Lexing.lexbuf ->t list
scan_sexps ?buf lexbuf reads a list of S-expressions from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
val scan_rev_sexps : ?buf:Stdlib.Buffer.t ->Stdlib.Lexing.lexbuf ->t list
scan_rev_sexps ?buf lexbuf same as scan_sexps, but returns the reversed list and is slightly more efficient.
val scan_sexp_opt : ?buf:Stdlib.Buffer.t ->Stdlib.Lexing.lexbuf ->t option
scan_sexp_opt ?buf lexbuf is equivalent to scan_sexp ?buf lexbuf except that it returns None when the eof is reached.
val scan_iter_sexps :
?buf:Stdlib.Buffer.t ->f:(t-> unit)->Stdlib.Lexing.lexbuf ->
unit
scan_iter_sexps ?buf ~f lexbuf iterates over all S-expressions scanned from lex buffer lexbuf using function f, and the optional string buffer buf for storing intermediate strings.
val scan_fold_sexps :
?buf:Stdlib.Buffer.t ->f:('a->t->'a)->init:'a->Stdlib.Lexing.lexbuf ->'a
scan_fold_sexps ?buf ~f ~init lexbuf folds over all S-expressions scanned from lex buffer lexbuf using function f, initial state init, and the optional string buffer buf for storing intermediate strings.
val scan_sexps_conv :
?buf:Stdlib.Buffer.t ->f:(t->'a)->Stdlib.Lexing.lexbuf ->'a list
scan_sexps_conv ?buf ~f lexbuf maps all S-expressions scanned from lex buffer lexbuf to some list using function f, and the optional string buffer buf for storing intermediate strings.
Type and exception definitions for (partial) parsing
Cont (cont_state, parse_fun) met the end of input before completely parsing an S-expression. The user has to call parse_fun to continue parsing the S-expression in another buffer. cont_state is the current parsing state of the continuation. NOTE: the continuation may only be called once and will raise Failure otherwise!
parse ?parse_pos ?len str (partially) parses an S-expression in string buffer str starting out with position information provided in parse_pos and reading at most len characters. To parse a single atom that is not delimited by whitespace it is necessary to call this function a second time with the returned continuation, and a dummy buffer that contains whitespace.
parse starts parsing str at position parse_pos.buf_pos. Each subsequent parse_fun from a Cont uses the buf and pos that is supplied to it. The final parse_fun that returns Done mutates the buf_pos in the originally supplied parse_pos, and then returns it.
parse_bigstring ?parse_pos ?len str same as parse, but operates on bigstrings.
val input_sexp : ?parse_pos:Parse_pos.t->Stdlib.in_channel ->t
input_sexp ?parse_pos ic parses an S-expression from input channel ic using initial position information in parse_pos. NOTE: this function is not as fast on files as Sexp.load_sexp, and is also slightly slower than the scan-functions. But it is guaranteed that input_sexp is only going to read data parseable as an S-expression. Thus, subsequent input functions will see the data immediately following it.
parameterparse_pos
default = Parse_pos.create ()
val input_sexps :
?parse_pos:Parse_pos.t->?buf:bytes ->Stdlib.in_channel ->t list
input_sexps ?parse_pos ?buf ic parses S-expressions from input channel ic until EOF is reached. Faster than the scan-functions.
parameterparse_pos
default = Parse_pos.create ()
val input_rev_sexps :
?parse_pos:Parse_pos.t->?buf:bytes ->Stdlib.in_channel ->t list
input_rev_sexps ?parse_pos ?buf ic same as Sexp.input_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
Loading of (converted) S-expressions
val load_sexp : ?strict:bool ->?buf:bytes ->string ->t
load_sexp ?strict ?buf file reads one S-expression from file using buffer buf for storing intermediate data. Faster than the scan-functions.
load_rev_sexps ?buf file same as Sexp.load_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.
val load_sexp_conv :
?strict:bool ->?buf:bytes ->string ->(t->'a)->'aAnnotated.conv
load_sexp_conv ?strict ?buf file f like Sexp.load_sexp, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexp and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
if parsing reached the end of file before the last S-expression could be fully read.
val load_sexp_conv_exn :
?strict:bool ->?buf:bytes ->string ->(t->'a)->'a
load_sexp_conv_exn ?strict ?buf file f like load_sexp_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
val load_sexps_conv :
?buf:bytes ->string ->(t->'a)->'aAnnotated.conv list
load_sexps_conv ?buf file f like Sexp.load_sexps, but performs a conversion on the fly using f. Performance is equivalent to executing Sexp.load_sexps and performing conversion when there are no errors. In contrast to the plain S-expression loader, this function not only performs the conversion, it will give exact error ranges for conversion errors.
if parsing reached the end of file before the last S-expression could be fully read.
val load_sexps_conv_exn : ?buf:bytes ->string ->(t->'a)->'a list
load_sexps_conv_exn ?buf file f like load_sexps_conv, but returns the converted value or raises Of_sexp_error with exact location information in the case of a conversion error.
Output of S-expressions to I/O-channels
NOTE: for performance reasons these output functions may need to allocate large strings to write out huge S-expressions. This may cause problems on 32-bit platforms. If you think that you may need to write huge S-expressions on such platforms, you might want to use the pretty-printers that write to formatters instead (see further below).
All save-functions write to a temporary file before moving it into place to avoid intermittent garbling of existing files, which may cause problems for other processes that try to read.
val to_buffer_gen :
buf:'buffer->add_char:('buffer->char -> unit)->add_string:('buffer->string -> unit)->t->
unit
to_buffer_gen ~buf ~add_char ~add_string sexp outputs the S-expression sexp converted to a string to buffer buf using the output functions add_char and add_string.
Type of successful search results. `Found means that an S-expression was found at the immediate position, and `Pos (pos,
found) indicates that it was found at position pos within a structure (= S-expression list) where found describes recursively where it was found in that structure.