package sexplib
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=da863b42b81235fdcf45eb32c04fb8bde22ff446a779cfb6f989730a35103160
doc/sexplib/Sexplib/Sexp/index.html
Module Sexplib.SexpSource
Sexp: Module for handling S-expressions (I/O, etc.)
include Sexp_intf.S
Type of bigstrings
Defaults
default_indent reference to default indentation level for human-readable conversions. Initialisation value: 2.
S-expression size
Scan functions
scan_sexp ?buf lexbuf scans an S-expression from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
scan_sexps ?buf lexbuf reads a list of S-expressions from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.
scan_rev_sexps ?buf lexbuf same as scan_sexps, but returns the reversed list and is slightly more efficient.
scan_sexp_opt ?buf lexbuf is equivalent to scan_sexp ?buf lexbuf except that it returns None when the eof is reached.
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.
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.
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
type ('a, 't) parse_result = ('a, 't) Pre_sexp.parse_result = | Done of 't * Parse_pos.t(*
*)Done (t, parse_pos)finished parsing an S-expression. Current parse position isparse_pos.| Cont of Cont_state.t * ('a, 't) parse_fun(*
*)Cont (cont_state, parse_fun)met the end of input before completely parsing an S-expression. The user has to callparse_funto continue parsing the S-expression in another buffer.cont_stateis the current parsing state of the continuation. NOTE: the continuation may only be called once and will raiseFailureotherwise!
Type of result from calling Sexp.parse.
Type of parsing functions with given offsets and lengths.
Module for parsing S-expressions annotated with location information
type 't parse_state = private 't Pre_sexp.parse_state = {parse_pos : Parse_pos.t;(*Current parse position
*)
}Type of state maintained during parsing
type parse_error = Pre_sexp.parse_error = {err_msg : string;(*Reason why parsing failed
*)parse_state : [ `Sexp of t list list parse_state | `Annot of Annotated.stack parse_state ];(*State of parser
*)
}Type of parse errors
Exception raised during partial parsing
Unannotated (partial) parsing
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.
val parse_bigstring :
?parse_pos:Parse_pos.t ->
?len:int ->
bigstring ->
(bigstring, t) parse_resultparse_bigstring ?parse_pos ?len str same as parse, but operates on bigstrings.
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.
input_sexps ?parse_pos ?buf ic parses S-expressions from input channel ic until EOF is reached. Faster than the scan-functions.
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
load_sexp ?strict ?buf file reads one S-expression from file using buffer buf for storing intermediate data. Faster than the scan-functions.
load_sexps ?buf file reads a list of S-expressions 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.
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.
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.
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.
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).
output_hum oc sexp outputs S-expression sexp to output channel oc in human readable form.
output_hum_indent indent oc sexp outputs S-expression sexp to output channel oc in human readable form using indentation level indent.
output_mach oc sexp outputs S-expression sexp to output channel oc in machine readable (i.e. most compact) form.
output oc sexp same as output_mach.
Output of S-expressions to file
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.
save_hum ?perm file sexp outputs S-expression sexp to file in human readable form.
save_mach ?perm file sexp outputs S-expression sexp to file in machine readable (i.e. most compact) form.
save_sexps_hum ?perm file sexps outputs S-expression list sexps to file in human readable form, each sexp being followed by a newline.
save_sexps_mach ?perm file sexps outputs S-expression list sexps to file in machine readable form, each sexp being followed by a newline.
save_sexps ?perm file sexp same as save_sexps_mach.
Output of S-expressions to formatters
pp_hum ppf sexp outputs S-expression sexp to formatter ppf in human readable form.
pp_hum_indent n ppf sexp outputs S-expression sexp to formatter ppf in human readable form and indentation level n.
pp_mach ppf sexp outputs S-expression sexp to formatter ppf in machine readable (i.e. most compact) form.
pp ppf sexp same as pp_mach.
String and bigstring conversions
Module encapsulating the exception raised by string converters when type conversions fail.
of_string_many parses a string containing zero or more S-expressions.
Unlike many other functions in this module, on parse failure it raises Parsexp.Parse_error rather than a native Sexplib.Sexp.Parse_error.
of_string_conv str conv like of_string, but performs type conversion with conv.
of_string_many_conv_exn str conv like of_string_many, but performs type conversion with conv. Raises if type conversion fails.
Unlike many other functions in this module, on parse failure it raises Parsexp.Parse_error rather than a native Sexplib.Sexp.Parse_error.
It still raises Sexplib.Sexp.Of_string_conv_exn on sexp conversion errors.
of_string_conv_exn str conv like of_string_conv, but raises Of_string_conv_exn.E if type conversion fails.
of_bigstring bstr same as of_string, but operates on bigstrings.
of_bigstring_conv bstr conv like of_bigstring, but performs type conversion with conv.
of_bigstring_conv_exn bstr conv like of_bigstring_conv, but raises Of_string_conv_exn.E if type conversion fails.
to_string_hum ?indent sexp converts S-expression sexp to a string in human readable form with indentation level indent.
to_string_mach sexp converts S-expression sexp to a string in machine readable (i.e. most compact) form.
Buffer conversions
to_buffer_hum ~buf ?indent sexp outputs the S-expression sexp converted to a string in human readable form to buffer buf.
to_buffer_mach ~buf sexp outputs the S-expression sexp converted to a string in machine readable (i.e. most compact) form to buffer buf.
to_buffer ~buf sexp same as to_buffer_mach.
val to_buffer_gen :
buf:'buffer ->
add_char:('buffer -> char -> unit) ->
add_string:('buffer -> string -> unit) ->
t ->
unitto_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.
Utilities for automated type conversions
sexp_of_t sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
t_of_sexp sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.
Utilities for conversion error handling
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.
Type of search results. `Not_found means that an S-expression was not found within another S-expression.
search_physical sexp ~contained
S-expressions annotated with relative source positions and comments