package sturgeon

  1. Overview
  2. Docs

This is an implementation of (a subset of) Emacs s-expressions.

Parametric S-exp

type 'a sexp =
  1. | C of 'a sexp * 'a sexp
    (*

    cons cell

    *)
  2. | S of string
    (*

    'sym

    *)
  3. | T of string
    (*

    "text"

    *)
  4. | P of 'a sexp
    (*

    #(property)

    *)
  5. | I of int
    (*

    1

    *)
  6. | F of float
    (*

    1.0

    *)
  7. | V of 'a sexp list
    (*

    vectors

    *)
  8. | M of 'a
    (*

    user-defined construction, outside of s-exp language

    *)
val transform_list : inj:('a -> 'b sexp) -> ?map:('b sexp -> 'b sexp) -> 'a sexp -> 'b sexp

Recursively transform a sexp. map function is applied on each atom and at the root of each list

val transform_cons : inj:('a -> 'b sexp) -> ?map:('b sexp -> 'b sexp) -> 'a sexp -> 'b sexp

Recursively transform a sexp. map function is applied on each atom and each cons-cell

val sym_nil : 'a sexp

nil constant: S "nil"

val sym_t : 'a sexp

t constant: S "t"

val sexp_of_list : ?tail:'a sexp -> 'a sexp list -> 'a sexp

Build a sexp list, -> nil x :: xs -> C (x, sexp_of_list xs)

val sexp_mem : 'a sexp -> 'a sexp -> bool

Does an element belong to a sexp list?

Monomorphic Emacs S-exp format

type void
val void : void -> 'a
type basic = void sexp
val generalize_basic : basic -> 'a sexp

Recover polymorphism

Low-level IO

val tell_sexp : (string -> unit) -> basic -> unit

Serialize an s-exp by repetively calling a string printing function.

val read_sexp : (unit -> char) -> basic * char

Read an basic by repetively calling a character reading function.

The character reading function can return '\000' to signal EOF.

Returns the basic and, if any, the last character read but not part of the sexp, or '\000'.

If the basic is not well-formed, a Failure is raised. You can catch it and add relevant location information. The error is always due to the last call to the reading function, which should be enough to locate the erroneous input, except for unterminated string.

Higher-level IO

val to_buf : basic -> Buffer.t -> unit
val to_string : basic -> string
val of_string : string -> basic
val of_file_descr : on_read:(Unix.file_descr -> unit) -> Unix.file_descr -> unit -> basic option

Read from a file descriptor.

on_read is called before a potentially blocking read is done, so that you can act before blocking (select, notify scheduler ...).

Partial application (stopping before the last ()) allows to read a stream of sexp.

val of_channel : in_channel -> unit -> basic option

Read from a channel.

Partial application (stopping before the last ()) allows to read a stream of sexp.

OCaml

Innovation. Community. Security.