Up

Module Sexp

Signature

include Core.Std.Sexp
type t = Sexplib.Sexp.t =
| Atom of string
| List of t list
val t_of_sexp : Sexplib.Sexp.t -> t
val sexp_of_t : t -> Sexplib.Sexp.t
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int -> t) Bin_prot.Read.reader
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_writer_t : t Bin_prot.Type_class.writer
module O : sig .. end
include Core_kernel.Interfaces.Comparable with type t := t
include Comparable_intf.S_common
include Comparable_intf.Polymorphic_compare
include Polymorphic_compare_intf.Infix
type t
val (>=) : t -> t -> bool
val (<=) : t -> t -> bool
val (=) : t -> t -> bool
val (>) : t -> t -> bool
val (<) : t -> t -> bool
val (<>) : t -> t -> bool
val equal : t -> t -> bool
val compare : t -> t -> int
val min : t -> t -> t
val max : t -> t -> t
val ascending : t -> t -> int

ascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~cmp:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.

val descending : t -> t -> int
val between : t -> low:t -> high:t -> bool
val clamp_exn : t -> min:t -> max:t -> t

clamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.

Raises if not (min <= max).

val clamp : t -> min:t -> max:t -> t Or_error.t
include Comparator.S with type t := t
type t
type comparator_witness
include Comparable_intf.Validate with type t := t
type t
val validate_lbound : min:t Maybe_bound.t -> t Validate.check
val validate_ubound : max:t Maybe_bound.t -> t Validate.check
val validate_bound : min:t Maybe_bound.t -> max:t Maybe_bound.t -> t Validate.check
include Core_kernel.Interfaces.Stringable with type t := t
type t
val of_string : string -> t
val to_string : t -> string
include Core_kernel.Interfaces.Quickcheckable with type t := t
type 'a gen
type 'a obs
type 'a shr
type t
val gen : t gen
val obs : t obs
val shrinker : t shr
include Sexplib.Sexp_intf.S with type t := t
type t = Sexplib.Type.t =
| Atom of string
| List of t list

Type of S-expressions

type bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t

Type of bigstrings

Defaults
val default_indent : int Pervasives.ref

default_indent reference to default indentation level for human-readable conversions. Initialisation value: 2.

S-expression size
val size : t -> int * int

size sexp

Returns (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:Buffer.t -> 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:Buffer.t -> Lexing.lexbuf -> t list

scan_sexps ?buf lexbuf reads a list of whitespace separated S-expressions from lex buffer lexbuf using the optional string buffer buf for storing intermediate strings.

val scan_rev_sexps : ?buf:Buffer.t -> 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:Buffer.t -> 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:Buffer.t -> f:(t -> unit) -> Lexing.lexbuf -> unit

scan_iter_sexps ?buf ~f lexbuf iterates over all whitespace separated 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:Buffer.t -> f:('a -> t -> 'a) -> init:'a -> Lexing.lexbuf -> 'a

scan_fold_sexps ?buf ~f ~init lexbuf folds over all whitespace separated 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:Buffer.t -> f:(t -> 'a) -> Lexing.lexbuf -> 'a list

scan_sexps_conv ?buf ~f lexbuf maps all whitespace separated 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
module Parse_pos : sig .. end
module Cont_state : sig .. end
type ('a, 't) parse_result = ('a, 't) Sexplib.Pre_sexp.parse_result =
| Done of 't * Parse_pos.t
(* Done (t, parse_pos) finished parsing an S-expression. Current parse position is parse_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 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! *)

Type of result from calling Sexplib.Sexp.parse.

type ('a, 't) parse_fun = pos:int -> len:int -> 'a -> ('a, 't) parse_result

Type of parsing functions with given offsets and lengths.

module Annotated : sig .. end
Module for parsing S-expressions annotated with location information
type 't parse_state = 't Sexplib.Pre_sexp.parse_state = private {
parse_pos
: Parse_pos.t ; (* Current parse position *)
mutable pstack
: 't ; (* Stack of found S-expression lists *)
pbuf
: Buffer.t ; (* Current atom buffer *)
}

Type of state maintained during parsing

type parse_error = Sexplib.Pre_sexp.parse_error = {
location
: string ; (* Function in which the parse failed *)
err_msg
: string ; (* Reason why parsing failed *)
parse_state
: [
| `Sexp of t list list parse_state
]
; (* State of parser *)
}

Type of parse errors

exception Parse_error of parse_error

Exception raised during partial parsing

Unannotated (partial) parsing
val parse : ?parse_pos:Parse_pos.t -> ?len:int -> string -> (string, t) parse_result

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.

Param [parse_pos] default = Parse_pos.create ()
Param [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_result

parse_bigstring ?parse_pos ?len str same as parse, but operates on bigstrings.

val input_sexp : ?parse_pos:Parse_pos.t -> Pervasives.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 Sexplib.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.

Param [parse_pos] default = Parse_pos.create ()
val input_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list

input_sexps ?parse_pos ?buf ic parses whitespace separated S-expressions from input channel ic until EOF is reached. Faster than the scan-functions.

Param [parse_pos] default = Parse_pos.create ()
val input_rev_sexps : ?parse_pos:Parse_pos.t -> ?buf:string -> Pervasives.in_channel -> t list

input_rev_sexps ?parse_pos ?buf ic same as Sexplib.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:string -> 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.

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 strict is true and there is more than one S-expression in the file.
Param [strict] default = true
val load_sexps : ?buf:string -> string -> t list

load_sexps ?buf file reads a list of whitespace separated S-expressions from file using buffer buf for 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:string -> string -> t list

load_rev_sexps ?buf file same as Sexplib.Sexp.load_sexps, but returns a reversed list of S-expressions, which is slightly more efficient.

val load_sexp_conv : ?strict:bool -> ?buf:string -> string -> (t -> 'a) -> 'a Annotated.conv

load_sexp_conv ?strict ?buf file f like Sexplib.Sexp.load_sexp, but performs a conversion on the fly using f. Performance is equivalent to executing Sexplib.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.

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:string -> 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:string -> string -> (t -> 'a) -> 'a Annotated.conv list

load_sexps_conv ?buf file f like Sexplib.Sexp.load_sexps, but performs a conversion on the fly using f. Performance is equivalent to executing Sexplib.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.

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:string -> 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).

val output_hum : Pervasives.out_channel -> t -> unit

output_hum oc sexp outputs S-expression sexp to output channel oc in human readable form.

val output_hum_indent : int -> Pervasives.out_channel -> t -> unit

output_hum_indent indent oc sexp outputs S-expression sexp to output channel oc in human readable form using indentation level indent.

val output_mach : Pervasives.out_channel -> t -> unit

output_mach oc sexp outputs S-expression sexp to output channel oc in machine readable (i.e. most compact) form.

val output : Pervasives.out_channel -> t -> unit

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.

val save_hum : ?perm:int -> string -> t -> unit

save_hum ?perm file sexp outputs S-expression sexp to file in human readable form.

Param [perm] default = umask
val save_mach : ?perm:int -> string -> t -> unit

save_mach ?perm file sexp outputs S-expression sexp to file in machine readable (i.e. most compact) form.

Param [perm] default = umask
val save : ?perm:int -> string -> t -> unit

save ?perm file sexp same as save_mach.

val save_sexps_hum : ?perm:int -> string -> t list -> unit

save_sexps_hum ?perm file sexps outputs S-expression list sexps to file in human readable form, each sexp being followed by a newline.

Param [perm] default = umask
val save_sexps_mach : ?perm:int -> string -> t list -> unit

save_sexps_mach ?perm file sexps outputs S-expression list sexps to file in machine readable form, each sexp being followed by a newline.

Param [perm] default = umask
val save_sexps : ?perm:int -> string -> t list -> unit

save_sexps ?perm file sexp same as save_sexps_mach.

Output of S-expressions to formatters
val pp_hum : Format.formatter -> t -> unit

pp_hum ppf sexp outputs S-expression sexp to formatter ppf in human readable form.

val pp_hum_indent : int -> Format.formatter -> t -> unit

pp_hum_indent n ppf sexp outputs S-expression sexp to formatter ppf in human readable form and indentation level n.

val pp_mach : Format.formatter -> t -> unit

pp_mach ppf sexp outputs S-expression sexp to formatter ppf in machine readable (i.e. most compact) form.

val pp : Format.formatter -> t -> unit

pp ppf sexp same as pp_mach.

String and bigstring conversions
module Of_string_conv_exn : sig .. end
Module encapsulating the exception raised by string converters when type conversions fail.
val of_string : string -> t

of_string str converts string str to 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, use parse instead.

val of_string_conv : string -> (t -> 'a) -> 'a Annotated.conv

of_string_conv str conv like of_string, but performs type conversion with conv.

Returns conversion result.
val of_string_conv_exn : string -> (t -> 'a) -> 'a

of_string_conv_exn str conv like of_string_conv, but raises Of_string_conv_exn.E if type conversion fails.

Returns converted value.
val of_bigstring : bigstring -> t

of_bigstring bstr same as of_string, but operates on bigstrings.

val of_bigstring_conv : bigstring -> (t -> 'a) -> 'a Annotated.conv

of_bigstring_conv bstr conv like of_bigstring, but performs type conversion with conv.

Returns conversion result.
val of_bigstring_conv_exn : bigstring -> (t -> 'a) -> 'a

of_bigstring_conv_exn bstr conv like of_bigstring_conv, but raises Of_string_conv_exn.E if type conversion fails.

Returns converted value.
val to_string_hum : ?indent:int -> t -> string

to_string_hum ?indent sexp converts S-expression sexp to a string in human readable form with indentation level indent.

Param [indent] default = !default_indent
val to_string_mach : t -> string

to_string_mach sexp converts S-expression sexp to a string in machine readable (i.e. most compact) form.

val to_string : t -> string

to_string sexp same as to_string_mach.

Buffer conversions
val to_buffer_hum : buf:Buffer.t -> ?indent:int -> t -> unit

to_buffer_hum ~buf ?indent sexp outputs the S-expression sexp converted to a string in human readable form to buffer buf.

Param [indent] default = !default_indent
val to_buffer_mach : buf:Buffer.t -> t -> unit

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.

val to_buffer : buf:Buffer.t -> t -> unit

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 -> 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.

Utilities for automated type conversions
val unit : t

unit the unit-value as expressed by an S-expression.

val sexp_of_t : t -> t

sexp_of_t sexp maps S-expressions which are part of a type with automated S-expression conversion to themselves.

val t_of_sexp : t -> t

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 found = [
| `Found
| `Pos of int * found
]

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 search_result = [
| `Not_found
| found
]

Type of search results. `Not_found means that an S-expression was not found within another S-expression.

val search_physical : t -> contained:t -> search_result

search_physical sexp ~contained

Returns the search result indicating whether, and if, where the S-expression contained was found within S-expression sexp.
val subst_found : t -> subst:t -> found -> t

subst_found sexp ~subst found

Returns the S-expression that results from substituting subst within S-expression sexp at the location described by found.
module With_layout : sig .. end
S-expressions annotated with relative source positions and comments
exception Of_sexp_error of exn * t
val of_int_style : [
| `Underscores
| `No_underscores
] Pervasives.ref
type 'a no_raise = 'a

no_raise is the identity, but by using 'a no_raise in a sexpable type, the resulting use 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.

val no_raise_of_sexp : (Sexplib.Sexp.t -> 'a) -> Sexplib.Sexp.t -> 'a no_raise
val sexp_of_no_raise : ('a -> Sexplib.Sexp.t) -> 'a no_raise -> Sexplib.Sexp.t
val bin_read_no_raise : 'a Bin_prot.Read.reader -> 'a no_raise Bin_prot.Read.reader
val __bin_read_no_raise__ : 'a Bin_prot.Read.reader -> (int -> 'a no_raise) Bin_prot.Read.reader
val bin_size_no_raise : 'a Bin_prot.Size.sizer -> 'a no_raise Bin_prot.Size.sizer
val bin_write_no_raise : 'a Bin_prot.Write.writer -> 'a no_raise Bin_prot.Write.writer

Please refer to the Sexplib documentation in base/sexplib/doc to learn more about sexp_option, sexp_list, and sexp_array generators.

module Sexp_option : sig .. end
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.
module Sexp_list : sig .. end
module Sexp_array : sig .. end
module Sexp_opaque : sig .. end
module Sexp_maybe : sig .. end
If sexp_of_t fails, it returns Error rather than raising.
module With_text : sig .. end
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.
val of_sexp_allow_extra_fields : (Sexplib.Sexp.t -> 'a) -> Sexplib.Sexp.t -> 'a

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 nested records). The implementation uses global state, so it is not thread safe.

include Extended_sexp
val is_atom : Core.Std.Sexp.t -> bool
val is_list : Core.Std.Sexp.t -> bool

Constructors

val atom : string -> Core.Std.Sexp.t
val list : Core.Std.Sexp.t list -> Core.Std.Sexp.t
val to_string_hum' : Core.Std.Sexp.t -> string

The ocaml pretty printer (used by sexplib) is a speed daemon but is, sadly enough, produces wrong output (e.g it overflows in places where this could have avoided). This uses a printer from wadler's a prettier printer to output strings suited to human consumption.

val format : Core.Std.Sexp.t -> Pp.t
val pp_hum' : Format.formatter -> Core.Std.Sexp.t -> unit

A more readable but less compact pretty printer than the one bundled by sexplib. This is going through a test period at which point it might make it in sexplib. It uses ocaml's pretty-printing library so it is both fast and broken.

val comment : string -> string

Takes a string and returns the same string but commented according to sexp's syntax

module Diff : sig .. end
val print_diff : ?oc:Core.Std.out_channel -> original:Core.Std.Sexp.t -> updated:Core.Std.Sexp.t -> unit -> unit
val summarize : Core.Std.Sexp.t -> sub_sexp:Core.Std.Sexp.t -> size:[
| `depth of int
| `string of int
] -> Core.Std.Sexp.t

Returns a smaller sexp by replacing sections with "...". Will try to show parts of the sexp "near" sub_sexp.

Limiting size to length a string length is less efficient than a certain depth. The meaning of a given depth is arbitrary except that more depth gives you a bigger sexp. Try 100 or so.

Transforming sexp parsers

module Records_table : sig .. end
module Make_explicit_sexp_option (T : sig .. end) : sig .. end
val load_sexp_conv_exn_sample : ?strict:bool -> ?buf:string -> ?on_non_existence:[
| `Exit
| `Raise
] -> ?name:string -> string -> sexp_of_t:('a -> Core.Std.Sexp.t) -> t_of_sexp:(Core.Std.Sexp.t -> 'a) -> sample:'a -> 'a
module Comprehension : sig .. end