package containers

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

Simple and efficient S-expression parsing/printing

  • since 0.7
type 'a or_error = [
  1. | `Ok of 'a
  2. | `Error of string
]
type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option

Basics

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

Serialization (encoding)

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

Print the given sequence of expressions to a file

val to_chan : out_channel -> t -> unit
val print : Format.formatter -> t -> unit

Pretty-printer nice on human eyes (including indentation)

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

Raw, direct printing as compact as possible

Deserialization (decoding)

module type MONAD = sig ... end
type 'a parse_result = [
  1. | 'a or_error
  2. | `End
]

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

module MakeDecode (M : MONAD) : sig ... end
module ID_MONAD : MONAD with type 'a t = 'a

The monad that just uses blocking calls as bind

module D : sig ... end

Decoder that just blocks when input is not available

val parse_string : string -> t or_error

Parse a string

val parse_chan : ?bufsize:int -> in_channel -> t 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 : ?bufsize:int -> in_channel -> t or_error gen

Parse a channel into a generator of S-expressions

val parse_chan_list : ?bufsize:int -> in_channel -> t list or_error
val parse_file : string -> t or_error

Open the file and read a S-exp from it

val parse_file_list : string -> t list or_error

Open the file and read a S-exp from it

OCaml

Innovation. Community. Security.