Code for managing s-expressions
no_raise is the identity, but by using
'a no_raise in a sexpable type, the
sexp_of_no_raise protects the conversion of
'a to a sexp so that if
it fails, one gets a sexp with an error message about the failure, rather than an
exception being raised.
WARNING: The resulting
no_raise_of_sexp can still raise.
Please refer to the Sexplib documentation in base/sexplib/doc to learn more about sexp_option, sexp_list, and sexp_array generators.
The purpose of these modules is to allow bin_io to work with these special sexp types. The more direct method of adding "with bin_io" at the point of the initial declaration of the types is not possible because sexplib does not (should not) depend on bin_io.
sexp_of_t fails, it returns
Error rather than raising. You can convert values
of this type to and from sexp in processes that can or cannot parse the underlying
sexp in any combination and still recover the original value. Also, the
contains a human-readable description of the error.
A common use case is to parse most of a sexp even when some small part fails to parse, e.g.:
type query = | Start of Initial_config.t Sexp_maybe.t | Stop of Reason_to_stop.t Sexp_maybe.t with sexp
Reason_to_stop.t_of_sexp fails, you can still tell it was a
With_text.t is a value paired with the full textual representation of its sexp.
This is useful for dealing with the case where you want to keep track of a value along
with the format of the s-expression it was generated from, which allows you to
maintain formatting details, comments, etc.
The s-expression representation of a
With_text.t is the raw text, stored as an atom.
The bin_io representation contains both the bin_io of the underlying value and the
bin_io'd version of the raw text.
This is similar to but simpler than the
With_layout module included above (via
Sexp_intf.S), which gives you access to a fully parsed version of the s-expression,
with attached comments and layout information, to allow you to build layout-preserving
The invariants of a
x With_text.t are broken if the
x value is mutated.
t from the value by creating the text automatically using the provided
of_sexp_allow_extra_fields of_sexp sexp uses
of_sexp to convert
sexp to a
value, but will not fail if there are any extra fields in a record (even deeply
The implementation uses global state, so it is not thread safe.