Module Sexp_helpers.Variant_spec

Helper to read variants from s-expressions. Supports nullary, unary, and variadic variants with proper error messages for each case.

The goal overtime is to extend the capability of this mini interpreter by improving behaviors such as error reporting, user-friendly hints, etc. This is left as future work.

type 'a conv =
  1. | Nullary of 'a
    (*

    Variant with no argument, e.g., `return

    *)
  2. | Unary_with_context of context:Sexplib0.Sexp.t -> arg:Sexplib0.Sexp.t -> 'a
    (*

    Variant with one argument, e.g., `equals of string

    *)
  3. | Unary of Sexplib0.Sexp.t -> 'a
    (*

    For Unary when context is not needed (most of them).

    *)
  4. | Variadic of context:Sexplib0.Sexp.t -> fields:Sexplib0.Sexp.t list -> 'a
    (*

    Variant with multiple arguments, e.g., `skip_paths of Glob.t list

    *)
type 'a case = {
  1. atom : string;
  2. conv : 'a conv;
}
type 'a t = 'a case list