type t = Base.Sexp.t =| Atom of Base.String.t| List of t Base.List.t
include Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
val bin_size_t : t Bin_prot.Size.sizerval bin_write_t : t Bin_prot.Write.writerval bin_read_t : t Bin_prot.Read.readerval __bin_read_t__ : (int -> t) Bin_prot.Read.readerThis function only needs implementation if
texposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the varianttafterwards.
val bin_shape_t : Bin_prot.Shape.tval bin_writer_t : t Bin_prot.Type_class.writerval bin_reader_t : t Bin_prot.Type_class.readerval bin_t : t Bin_prot.Type_class.t
val hash_fold_t : Base.Hash.state -> t -> Base.Hash.stateval hash : t -> Base.Hash.hash_value
include Ppx_sexp_conv_lib.Sexpable.S with type t := t
val t_of_sexp : Sexplib0.Sexp.t -> tval sexp_of_t : t -> Sexplib0.Sexp.t
module O : sig ... endinclude Comparable.S with type t := t
include Base.Comparable.S with type t := t
val ascending : t -> t -> intascendingis identical tocompare.descending x y = ascending y x. These are intended to be mnemonic when used likeList.sort ~compare:ascendingandList.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.
val descending : t -> t -> intval between : t -> low:t -> high:t -> boolbetween t ~low ~highmeanslow <= t <= high
val clamp_exn : t -> min:t -> max:t -> tclamp_exn t ~min ~maxreturnst', the closest value totsuch thatbetween t' ~low:min ~high:maxis true.Raises if
not (min <= max).
val clamp : t -> min:t -> max:t -> t Base.Or_error.t
include Base.Comparator.S with type t := t
val comparator : (t, comparator_witness) Base.Comparator.comparator
val validate_lbound : min:t Base.Maybe_bound.t -> t Base.Validate.checkval validate_ubound : max:t Base.Maybe_bound.t -> t Base.Validate.checkval validate_bound : min:t Base.Maybe_bound.t -> max:t Base.Maybe_bound.t -> t Base.Validate.check
module Replace_polymorphic_compare : sig ... endmodule Map : Map.S with type Key.t = t with type Key.comparator_witness = comparator_witnessmodule Set : Set.S with type Elt.t = t with type Elt.comparator_witness = comparator_witnessinclude Base.Stringable.S with type t := t
include Quickcheckable.S with type t := t
val quickcheck_generator : t Base_quickcheck.Generator.tval quickcheck_observer : t Base_quickcheck.Observer.tval quickcheck_shrinker : t Base_quickcheck.Shrinker.t
include module type of sig ... end with type Sexp.t := t
include module type of Sexplib.Sexp with type t := t
include Sexplib.Sexp_intf.S with type t := t
module Raw_grammar = Sexplib0.Sexp.Private.Raw_grammartype bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.tType of bigstrings
Defaults
val default_indent : int Stdlib.refdefault_indentreference to default indentation level for human-readable conversions. Initialisation value: 2.
S-expression size
val size : t -> int * intsize sexp- returns
(n_atoms, n_chars), wheren_atomsis the number of atoms in S-expressionsexp, andn_charsis the number of characters in the atoms of the S-expression.
Scan functions
val scan_sexp : ?buf:Stdlib.Buffer.t -> Stdlib.Lexing.lexbuf -> tscan_sexp ?buf lexbufscans an S-expression from lex bufferlexbufusing the optional string bufferbuffor storing intermediate strings.
val scan_sexps : ?buf:Stdlib.Buffer.t -> Stdlib.Lexing.lexbuf -> t listscan_sexps ?buf lexbufreads a list of whitespace separated S-expressions from lex bufferlexbufusing the optional string bufferbuffor storing intermediate strings.
val scan_rev_sexps : ?buf:Stdlib.Buffer.t -> Stdlib.Lexing.lexbuf -> t listscan_rev_sexps ?buf lexbufsame asscan_sexps, but returns the reversed list and is slightly more efficient.
val scan_sexp_opt : ?buf:Stdlib.Buffer.t -> Stdlib.Lexing.lexbuf -> t optionscan_sexp_opt ?buf lexbufis equivalent toscan_sexp ?buf lexbufexcept that it returnsNonewhen the eof is reached.
val scan_iter_sexps : ?buf:Stdlib.Buffer.t -> f:(t -> unit) -> Stdlib.Lexing.lexbuf -> unitscan_iter_sexps ?buf ~f lexbufiterates over all whitespace separated S-expressions scanned from lex bufferlexbufusing functionf, and the optional string bufferbuffor storing intermediate strings.
val scan_fold_sexps : ?buf:Stdlib.Buffer.t -> f:('a -> t -> 'a) -> init:'a -> Stdlib.Lexing.lexbuf -> 'ascan_fold_sexps ?buf ~f ~init lexbuffolds over all whitespace separated S-expressions scanned from lex bufferlexbufusing functionf, initial stateinit, and the optional string bufferbuffor storing intermediate strings.
val scan_sexps_conv : ?buf:Stdlib.Buffer.t -> f:(t -> 'a) -> Stdlib.Lexing.lexbuf -> 'a listscan_sexps_conv ?buf ~f lexbufmaps all whitespace separated S-expressions scanned from lex bufferlexbufto some list using functionf, and the optional string bufferbuffor storing intermediate strings.
Type and exception definitions for (partial) parsing
module Parse_pos : sig ... endmodule Cont_state : sig ... endtype ('a, 't) parse_result = ('a, 't) Sexplib.Pre_sexp.parse_result =| Done of 't * Parse_pos.tDone (t, parse_pos)finished parsing an S-expression. Current parse position isparse_pos.| Cont of Cont_state.t * ('a, 't) parse_funCont (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.
and ('a, 't) parse_fun = pos:int -> len:int -> 'a -> ('a, 't) parse_resultType of parsing functions with given offsets and lengths.
module Annotated : sig ... endModule for parsing S-expressions annotated with location information
type 't parse_state = private 't Sexplib.Pre_sexp.parse_state = {parse_pos : Parse_pos.t;Current parse position
}Type of state maintained during parsing
type parse_error = Sexplib.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 Parse_error of parse_errorException raised during partial parsing
Unannotated (partial) parsing
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_resultparse ?parse_pos ?len str(partially) parses an S-expression in string bufferstrstarting out with position information provided inparse_posand reading at mostlencharacters. 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.parsestarts parsingstrat positionparse_pos.buf_pos. Each subsequentparse_funfrom aContuses thebufandposthat is supplied to it. The finalparse_funthat returnsDonemutates thebuf_posin the originally suppliedparse_pos, and then returns it.- parameter parse_pos
default =
Parse_pos.create ()
- parameter len
default =
String.length str - parse_pos.Parse_pos.buf_pos
val parse_bigstring : ?parse_pos:Parse_pos.t -> ?len:int -> bigstring -> (bigstring, t) parse_resultparse_bigstring ?parse_pos ?len strsame asparse, but operates on bigstrings.
val input_sexp : ?parse_pos:Parse_pos.t -> Stdlib.in_channel -> tinput_sexp ?parse_pos icparses an S-expression from input channelicusing initial position information inparse_pos. NOTE: this function is not as fast on files asSexp.load_sexp, and is also slightly slower than the scan-functions. But it is guaranteed thatinput_sexpis only going to read data parseable as an S-expression. Thus, subsequent input functions will see the data immediately following it.- parameter parse_pos
default =
Parse_pos.create ()
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Stdlib.in_channel -> t listinput_sexps ?parse_pos ?buf icparses whitespace separated S-expressions from input channelicuntil EOF is reached. Faster than the scan-functions.- parameter parse_pos
default =
Parse_pos.create ()
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:bytes -> Stdlib.in_channel -> t listinput_rev_sexps ?parse_pos ?buf icsame asSexp.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 -> tload_sexp ?strict ?buf filereads one S-expression fromfileusing bufferbuffor storing intermediate data. Faster than the scan-functions.- raises Parse_error
if the S-expression is unparseable.
- raises Failure
if parsing reached the end of file before one S-expression could be read.
- raises Failure
if
strictis true and there is more than one S-expression in the file.
- parameter strict
default =
true
val load_sexps : ?buf:bytes -> string -> t listload_sexps ?buf filereads a list of whitespace separated S-expressions fromfileusing bufferbuffor storing intermediate data. Faster than the scan-functions.- raises Parse_error
if there is unparseable data in the file.
- raises Failure
if parsing reached the end of file before the last S-expression could be fully read.
val load_rev_sexps : ?buf:bytes -> string -> t listload_rev_sexps ?buf filesame asSexp.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) -> 'a Annotated.convload_sexp_conv ?strict ?buf file flikeSexp.load_sexp, but performs a conversion on the fly usingf. Performance is equivalent to executingSexp.load_sexpand 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.- raises Parse_error
if there is unparseable data in the file.
- raises Failure
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) -> 'aload_sexp_conv_exn ?strict ?buf file flikeload_sexp_conv, but returns the converted value or raisesOf_sexp_errorwith exact location information in the case of a conversion error.
val load_sexps_conv : ?buf:bytes -> string -> (t -> 'a) -> 'a Annotated.conv listload_sexps_conv ?buf file flikeSexp.load_sexps, but performs a conversion on the fly usingf. Performance is equivalent to executingSexp.load_sexpsand 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.- raises Parse_error
if there is unparseable data in the file.
- raises Failure
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 listload_sexps_conv_exn ?buf file flikeload_sexps_conv, but returns the converted value or raisesOf_sexp_errorwith exact location information in the case of a conversion error.
Output of S-expressions to I/O-channels
val output_hum : Stdlib.out_channel -> t -> unitoutput_hum oc sexpoutputs S-expressionsexpto output channelocin human readable form.
val output_hum_indent : int -> Stdlib.out_channel -> t -> unitoutput_hum_indent indent oc sexpoutputs S-expressionsexpto output channelocin human readable form using indentation levelindent.
val output_mach : Stdlib.out_channel -> t -> unitoutput_mach oc sexpoutputs S-expressionsexpto output channelocin machine readable (i.e. most compact) form.
val output : Stdlib.out_channel -> t -> unitoutput oc sexpsame asoutput_mach.
Output of S-expressions to file
val save_hum : ?perm:int -> string -> t -> unitsave_hum ?perm file sexpoutputs S-expressionsexptofilein human readable form.- parameter perm
default = umask
val save_mach : ?perm:int -> string -> t -> unitsave_mach ?perm file sexpoutputs S-expressionsexptofilein machine readable (i.e. most compact) form.- parameter perm
default = umask
val save_sexps_hum : ?perm:int -> string -> t list -> unitsave_sexps_hum ?perm file sexpsoutputs S-expression listsexpstofilein human readable form, each sexp being followed by a newline.- parameter perm
default = umask
val save_sexps_mach : ?perm:int -> string -> t list -> unitsave_sexps_mach ?perm file sexpsoutputs S-expression listsexpstofilein machine readable form, each sexp being followed by a newline.- parameter perm
default = umask
val save_sexps : ?perm:int -> string -> t list -> unitsave_sexps ?perm file sexpsame assave_sexps_mach.
Output of S-expressions to formatters
val pp_hum : Stdlib.Format.formatter -> t -> unitpp_hum ppf sexpoutputs S-expressionsexpto formatterppfin human readable form.
val pp_hum_indent : int -> Stdlib.Format.formatter -> t -> unitpp_hum_indent n ppf sexpoutputs S-expressionsexpto formatterppfin human readable form and indentation leveln.
val pp_mach : Stdlib.Format.formatter -> t -> unitpp_mach ppf sexpoutputs S-expressionsexpto formatterppfin machine readable (i.e. most compact) form.
val pp : Stdlib.Format.formatter -> t -> unitpp ppf sexpsame aspp_mach.
String and bigstring conversions
module Of_string_conv_exn : sig ... endModule encapsulating the exception raised by string converters when type conversions fail.
val of_string : string -> tof_string strconverts stringstrto an S-expression. NOTE: trailing whitespace is considered an error, which may be overly strict for some applications. Either strip the string of trailing whitespace first, or, even cheaper, useparseinstead.
val of_string_conv : string -> (t -> 'a) -> 'a Annotated.convof_string_conv str convlikeof_string, but performs type conversion withconv.- returns
conversion result.
val of_string_conv_exn : string -> (t -> 'a) -> 'aof_string_conv_exn str convlikeof_string_conv, but raisesOf_string_conv_exn.Eif type conversion fails.- returns
converted value.
val of_bigstring_conv : bigstring -> (t -> 'a) -> 'a Annotated.convof_bigstring_conv bstr convlikeof_bigstring, but performs type conversion withconv.- returns
conversion result.
val of_bigstring_conv_exn : bigstring -> (t -> 'a) -> 'aof_bigstring_conv_exn bstr convlikeof_bigstring_conv, but raisesOf_string_conv_exn.Eif type conversion fails.- returns
converted value.
val to_string_hum : ?indent:int -> t -> stringto_string_hum ?indent sexpconverts S-expressionsexpto a string in human readable form with indentation levelindent.- parameter indent
default =
!default_indent
val to_string_mach : t -> stringto_string_mach sexpconverts S-expressionsexpto a string in machine readable (i.e. most compact) form.
val to_string : t -> stringto_string sexpsame asto_string_mach.
Buffer conversions
val to_buffer_hum : buf:Stdlib.Buffer.t -> ?indent:int -> t -> unitto_buffer_hum ~buf ?indent sexpoutputs the S-expressionsexpconverted to a string in human readable form to bufferbuf.- parameter indent
default =
!default_indent
val to_buffer_mach : buf:Stdlib.Buffer.t -> t -> unitto_buffer_mach ~buf sexpoutputs the S-expressionsexpconverted to a string in machine readable (i.e. most compact) form to bufferbuf.
val to_buffer : buf:Stdlib.Buffer.t -> t -> unitto_buffer ~buf sexpsame asto_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 sexpoutputs the S-expressionsexpconverted to a string to bufferbufusing the output functionsadd_charandadd_string.
Utilities for automated type conversions
val unit : tunitthe unit-value as expressed by an S-expression.
val is_unit : t -> boolval sexp_of_t : t -> tsexp_of_t sexpmaps S-expressions which are part of a type with automated S-expression conversion to themselves.
val t_of_sexp : t -> tt_of_sexp sexpmaps S-expressions which are part of a type with automated S-expression conversion to themselves.
val t_sexp_grammar : Sexplib0.Private.Raw_grammar.t
Utilities for conversion error handling
type found = [|`Found|`Pos of int * found]Type of successful search results.
`Foundmeans that an S-expression was found at the immediate position, and`Pos (pos, found)indicates that it was found at positionposwithin a structure (= S-expression list) wherefounddescribes recursively where it was found in that structure.
type search_result = [|`Not_found|found]Type of search results.
`Not_foundmeans that an S-expression was not found within another S-expression.
val search_physical : t -> contained:t -> search_resultsearch_physical sexp ~contained- returns
the search result indicating whether, and if, where the S-expression
containedwas found within S-expressionsexp.
val subst_found : t -> subst:t -> found -> tsubst_found sexp ~subst found- returns
the S-expression that results from substituting
substwithin S-expressionsexpat the location described byfound.
module With_layout : sig ... endS-expressions annotated with relative source positions and comments
exception Of_sexp_error of Base.Exn.t * t
val of_float_style : [ `Underscores | `No_underscores ] Base.Ref.tval of_int_style : [ `Underscores | `No_underscores ] Base.Ref.t
type 'a no_raise = 'ano_raiseis the identity, but by using'a no_raisein a sexpable type, the resulting usesexp_of_no_raiseprotects the conversion of'ato 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_sexpcan still raise.
val bin_shape_no_raise : Bin_prot.Shape.t -> Bin_prot.Shape.tval bin_size_no_raise : 'a Bin_prot.Size.sizer -> 'a no_raise Bin_prot.Size.sizerval bin_write_no_raise : 'a Bin_prot.Write.writer -> 'a no_raise Bin_prot.Write.writerval bin_writer_no_raise : 'a Bin_prot.Type_class.writer -> 'a no_raise Bin_prot.Type_class.writerval bin_read_no_raise : 'a Bin_prot.Read.reader -> 'a no_raise Bin_prot.Read.readerval __bin_read_no_raise__ : 'a Bin_prot.Read.reader -> (Base.Int.t -> 'a no_raise) Bin_prot.Read.readerval bin_reader_no_raise : 'a Bin_prot.Type_class.reader -> 'a no_raise Bin_prot.Type_class.readerval bin_no_raise : 'a Bin_prot.Type_class.t -> 'a no_raise Bin_prot.Type_class.tval sexp_of_no_raise : ('a -> Ppx_sexp_conv_lib.Sexp.t) -> 'a no_raise -> Ppx_sexp_conv_lib.Sexp.tval no_raise_of_sexp : (Ppx_sexp_conv_lib.Sexp.t -> 'a) -> Ppx_sexp_conv_lib.Sexp.t -> 'a no_raise
module Sexp_maybe : sig ... endIf
sexp_of_t fails, it returnsErrorrather 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, theErrorcase contains a human-readable description of the error.
module With_text : sig ... endA
With_text.tis 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.
val of_sexp_allow_extra_fields_recursively : (Base.Sexp.t -> 'a) -> Base.Sexp.t -> 'aof_sexp_allow_extra_fields_recursively of_sexp sexpusesof_sexpto convertsexpto a value, but will not fail if there are any extra fields in a record (even deeply nested records).The implementation uses global state, so it is not thread safe.
module Stable : sig ... end