package yocaml

  1. Overview
  2. Docs

Describes an mostly compatible Ezjsonm AST that acts as a generic AST for describing metadata that can be exchanged between source documents and templates. To summarise, source metadata is ultimately projected into a value of type Yocaml.Data.t and data injected into templates is projected from values of type Yocaml.Data.t.

To be generic, you need to provide a module capable of transforming the AST of arbitrary metadata (for example, Yaml) into a value of type Yocaml.Data.t to be used generically.

Types

type t = private
  1. | Null
  2. | Bool of bool
  3. | Int of int
  4. | Float of float
  5. | String of string
  6. | List of t list
  7. | Record of (string * t) list
    (*

    Describes the set of possible values for the Data AST.

    *)
type ezjsonm = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of ezjsonm list
  6. | `O of (string * ezjsonm) list
]

Describes type ezjsonm (to be compatible with historical libraries, such as ocaml_yaml).

Creating Data values

val null : t

null returns the t for null.

val bool : bool -> t

bool b converts a Boolean into a t.

val int : int -> t

int i converts an integer into a t.

val float : float -> t

float f converts a float into a t.

val string : string -> t

string s converts a string into a t.

val list : t list -> t

list v converts a list of t into a t.

Generic Data values

Building generic Data values.

val list_of : ('a -> t) -> 'a list -> t

list f v converts a list of arbitrary values into a t.

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

record fields converts a list of t into a t.

val option : ('a -> t) -> 'a option -> t

option opt converts an option into a t or null.

val sum : ('a -> string * t) -> 'a -> t

sum f x convert sum into a t.

val pair : ('a -> t) -> ('b -> t) -> ('a * 'b) -> t

pair f g (x, y) construct a pair as a t. A pair has the structure {"fst": a, "snd": b}.

val triple : ('a -> t) -> ('b -> t) -> ('c -> t) -> ('a * 'b * 'c) -> t

triple f g h (x, y, z) is pair f (pair g h) (x, (y, z)). It use pair to define triple.

val quad : ('a -> t) -> ('b -> t) -> ('c -> t) -> ('d -> t) -> ('a * 'b * 'c * 'd) -> t

quad f g h i (w, x, y, z) is pair f (triple g h) (w, (x, y, z))

val either : ('a -> t) -> ('b -> t) -> ('a, 'b) Stdlib.Either.t -> t

either f g x construct either as a t. Either has the structure {"constr": "left | right", "value": e}.

Validating Data values

module Validation : sig ... end

Used to validate data described by type Yocaml.Data.t to build validation pipelines. The aim of this module is to produce combinators for building validation pipelines that support nesting and that can transform any value described by the AST in Data into arbitrary OCaml values.

Utils

val equal : t -> t -> bool

Equality between t.

val pp : Stdlib.Format.formatter -> t -> unit

Pretty-printer for t (mostly used for debugging issue).

val to_ezjsonm : t -> ezjsonm

to_ezjsonm v converts a t into a ezjsonm.

val from_ezjsonm : ezjsonm -> t

from_ezjsonm v converts a ezjsonm into a t.

OCaml

Innovation. Community. Security.