package sturgeon

  1. Overview
  2. Docs

Module Sturgeon_sexpSource

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

Parametric S-exp

Sourcetype '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

    *)
Sourceval 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

Sourceval 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

Sourceval sym_nil : 'a sexp

nil constant: S "nil"

Sourceval sym_t : 'a sexp

t constant: S "t"

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

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

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

Does an element belong to a sexp list?

Monomorphic Emacs S-exp format

Sourcetype void
Sourceval void : void -> 'a
Sourcetype basic = void sexp
Sourceval generalize_basic : basic -> 'a sexp

Recover polymorphism

Low-level IO

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

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

Sourceval 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

Sourceval to_buf : basic -> Buffer.t -> unit
Sourceval to_string : basic -> string
Sourceval of_string : string -> basic
Sourceval 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.

Sourceval of_channel : in_channel -> unit -> basic option

Read from a channel.

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