Module CCSexp
Handling S-expressions
- since
- 3.0 moved into containers-core, previously in [containers.sexp]
module type SEXP = CCSexp_intf.SEXP
module type S = CCSexp_intf.S
Basics
type t
=[
|
`Atom of string
|
`List of t list
]
A simple, structural representation of S-expressions.
include S with type S.t := t
type t
type sexp
= t
Re-exports
val atom : string -> t
Make an atom out of this string.
- since
- 2.8
Constructors
val of_int : int -> t
val of_bool : bool -> t
val of_list : t list -> t
val of_rev_list : t list -> t
Reverse the list.
val of_float : float -> t
val of_unit : t
val of_pair : (t * t) -> t
val of_triple : (t * t * t) -> t
val of_quad : (t * t * t * t) -> t
val of_variant : string -> t list -> t
of_variant name args
is used to encode algebraic variants into a S-expr. For instanceof_variant "some" [of_int 1]
represents the valueSome 1
.
Printing
val to_buf : Stdlib.Buffer.t -> t -> unit
val to_string : t -> string
val to_file : string -> t -> unit
val to_file_iter : string -> t CCSexp_intf.iter -> unit
Print the given iter of expressions to a file.
val to_chan : Stdlib.out_channel -> t -> unit
val pp : Stdlib.Format.formatter -> t -> unit
Pretty-printer nice on human eyes (including indentation).
val pp_noindent : Stdlib.Format.formatter -> t -> unit
Raw, direct printing as compact as possible.
Parsing
type 'a parse_result
=
|
Yield of 'a
|
Fail of string
|
End
A parser of
'a
can returnYield x
when it parsed a value, orFail e
when a parse error was encountered, orEnd
if the input was empty.
module Decoder : sig ... end
val parse_string : string -> t CCSexp_intf.or_error
Parse a string.
val parse_string_list : string -> t list CCSexp_intf.or_error
Parse a string into a list of S-exprs.
- since
- 2.8
val parse_chan : Stdlib.in_channel -> t CCSexp_intf.or_error
Parse a S-expression from the given channel. Can read more data than necessary, so don't use this if you need finer-grained control (e.g. to read something else after the S-exp).
val parse_chan_gen : Stdlib.in_channel -> t CCSexp_intf.or_error CCSexp_intf.gen
Parse a channel into a generator of S-expressions.
val parse_chan_list : Stdlib.in_channel -> t list CCSexp_intf.or_error
val parse_file : string -> t CCSexp_intf.or_error
Open the file and read a S-exp from it.
val parse_file_list : string -> t list CCSexp_intf.or_error
Open the file and read a S-exp from it.
val atom : string -> t
Build an atom directly from a string.