package containers

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Handling S-expressions

type 'a or_error = ('a, string) Result.result
type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option
module type SEXP = CCSexp_intf.SEXP
module type S = CCSexp_intf.S
module Make (Sexp : SEXP) : S with type t = Sexp.t

Basics

type t = [
  1. | `Atom of string
  2. | `List of t list
]

A simple, structural representation of S-expressions.

include S with type t := t
type sexp = t
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

Reverse the list.

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 instance of_variant "some" [of_int 1] represents the value Some 1.

val of_field : string -> t -> t

Used to represent one record field.

val of_record : (string * t) list -> t

Represent a record by its named fields.

Printing

val to_buf : Buffer.t -> t -> unit
val to_string : t -> string
val to_file : string -> t -> unit
val to_file_seq : string -> t CCSexp_intf.sequence -> unit

Print the given sequence of expressions to a file.

val to_chan : Pervasives.out_channel -> t -> unit
val pp : Format.formatter -> t -> unit

Pretty-printer nice on human eyes (including indentation).

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

Raw, direct printing as compact as possible.

Parsing

type 'a parse_result =
  1. | Yield of 'a
  2. | Fail of string
  3. | End

A parser of 'a can return Yield x when it parsed a value, or Fail e when a parse error was encountered, or End if the input was empty.

module Decoder : sig ... end
val parse_string : string -> t CCSexp_intf.or_error

Parse a string.

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

Parse a channel into a generator of S-expressions.

val parse_chan_list : Pervasives.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.

OCaml

Innovation. Community. Security.