Module Sexplib.Sexp_grammarSource
include Sexplib.Sexp_grammar_intf.Sexp_grammar
module type S = Sexplib.Sexp_grammar_intf.Sinclude module type of struct include Sexplib0.Sexp_grammar end
include module type of struct include Sexp_grammar_type.Sexp_grammar end
type grammar = Sexp_grammar_type.Sexp_grammar.grammar = | Any of string(*accepts any sexp; string is a type name for human readability
*)| Bool(*accepts the atoms "true" or "false", modulo capitalization
*)| Char(*accepts any single-character atom
*)| Integer(*accepts any atom matching ocaml integer syntax, regardless of bit width
*)| Float(*accepts any atom matching ocaml float syntax
*)| String(*accepts any atom
*)| Option of Sexplib.Sexp_grammar.grammar(*accepts an option, both
*)NonevsSome _and()vs(_).| List of Sexplib.Sexp_grammar.list_grammar(*accepts a list
*)| Variant of Sexplib.Sexp_grammar.variant(*accepts clauses keyed by a leading or sole atom
*)| Union of Sexplib.Sexp_grammar.grammar list(*accepts a sexp if any of the listed grammars accepts it
*)| Tagged of Sexplib.Sexp_grammar.grammar Sexplib.Sexp_grammar.with_tag(*annotates a grammar with a client-specific key/value pair
*)| Tyvar of string(*Name of a type variable, e.g.
*)Tyvar "a"for'a. Only meaningful when the body of the innermost enclosingdefndefines a corresponding type variable.| Tycon of string * Sexplib.Sexp_grammar.grammar list * Sexplib.Sexp_grammar.defn list(*Type constructor applied to arguments, and its definition.
For example, writing
Tycon ("tree", [ Integer ], defns)representsint tree, for whatevertreeis defined as indefns. The following definestreeas a binary tree with the parameter type stored at the leaves.let defns = [ { tycon = "tree" ; tyvars = [ "a" ] ; grammar = Variant { name_kind = Capitalized ; clauses = [ { name = "Node" ; args = Cons (Recursive ("node", [ Tyvar "a" ]), Empty) } ; { name = "Leaf" ; args = Cons (Recursive ("leaf", [ Tyvar "a" ]), Empty) } ] } } ; { tycon = "node" ; tyvars = [ "a" ] ; grammar = List (Many (Recursive "tree", [ Tyvar "a" ])) } ; { tycon = "leaf"; tyvars = [ "a" ]; grammar = [ Tyvar "a" ] } ] ;;To illustrate the meaning of
Tyconwith respect todefns, and to demonstrate one way to access them, it is equivalent to expand the definition of "tree" one level and move thedefnsto enclosed recursive references:Tycon ("tree", [ Integer ], defns) --> Variant { name_kind = Capitalized ; clauses = [ { name = "Node" ; args = Cons (Tycon ("node", [ Tyvar "a" ], defns), Empty) } ; { name = "Leaf" ; args = Cons (Tycon ("leaf", [ Tyvar "a" ], defns), Empty) } ] }This transformation exposes the structure of a grammar with recursive references, while preserving the meaning of recursively-defined elements.
*)| Recursive of string * Sexplib.Sexp_grammar.grammar list(*Type constructor applied to arguments. Used to denote recursive type references. Only meaningful when used inside the
*)defns of aTycongrammar, to refer to a type constructor in the nearest enclosingdefnlist.| Lazy of Sexplib.Sexp_grammar.grammar Basement.Portable_lazy.t(*Lazily computed grammar. Use
*)Lazyto avoid top-level side effects. To define recursive grammars, useRecursiveinstead.
Grammar of a sexp.
and list_grammar = Sexp_grammar_type.Sexp_grammar.list_grammar = | Empty(*accepts an empty list of sexps
*)| Cons of Sexplib.Sexp_grammar.grammar * Sexplib.Sexp_grammar.list_grammar(*accepts a non-empty list with head and tail matching the given grammars
*)| Many of Sexplib.Sexp_grammar.grammar(*accepts zero or more sexps, each matching the given grammar
*)| Fields of Sexplib.Sexp_grammar.record(*accepts sexps representing fields of a record
*)
Grammar of a list of sexps.
and case_sensitivity = Sexp_grammar_type.Sexp_grammar.case_sensitivity = | Case_insensitive(*Comparison is case insensitive. Used for custom parsers.
*)| Case_sensitive(*Comparison is case sensitive. Used for polymorphic variants.
*)| Case_sensitive_except_first_character(*Comparison is case insensitive for the first character and case sensitive afterward. Used for regular variants.
*)
Case sensitivity options for names of variant constructors.
and variant = Sexp_grammar_type.Sexp_grammar.variant = {case_sensitivity : Sexplib.Sexp_grammar.case_sensitivity;clauses : Sexplib.Sexp_grammar.clause Sexplib.Sexp_grammar.with_tag_list list;
}Grammar of variants. Accepts any sexp matching one of the clauses.
and clause = Sexp_grammar_type.Sexp_grammar.clause = {name : string;clause_kind : Sexplib.Sexp_grammar.clause_kind;
}Grammar of a single variant clause. Accepts sexps based on the clause_kind.
Grammar of a single variant clause's contents. Atom_clause accepts an atom matching the clause's name. List_clause accepts a list whose head is an atom matching the clause's name and whose tail matches args. The clause's name is matched modulo the variant's name_kind.
and record = Sexp_grammar_type.Sexp_grammar.record = {allow_extra_fields : bool;fields : Sexplib.Sexp_grammar.field Sexplib.Sexp_grammar.with_tag_list list;
}Grammar of a record. Accepts any list of sexps specifying each of the fields, regardless of order. If allow_extra_fields is specified, ignores sexps with names not found in fields.
and field = Sexp_grammar_type.Sexp_grammar.field = {name : string;required : bool;args : Sexplib.Sexp_grammar.list_grammar;
}Grammar of a record field. A field must show up exactly once in a record if required, or at most once otherwise. Accepts a list headed by name as an atom, followed by sexps matching args.
and 'a with_tag = 'a Sexp_grammar_type.Sexp_grammar.with_tag = {key : string;value : Sexp_type.Sexp.t;grammar : 'a;
}Grammar tagged with client-specific key/value pair.
and 'a with_tag_list = 'a Sexp_grammar_type.Sexp_grammar.with_tag_list = | Tag of 'a Sexplib.Sexp_grammar.with_tag_list Sexplib.Sexp_grammar.with_tag| No_tag of 'a
and defn = Sexp_grammar_type.Sexp_grammar.defn = {tycon : string;tyvars : string list;grammar : Sexplib.Sexp_grammar.grammar;
}Grammar of a recursive type definition. Names the tycon being defined, and the tyvars it takes as parameters. Specifies the grammar of the tycon. The grammar may refer to any of the tyvars, and to any of the tycons from the same set of Recursive definitions.
Top-level grammar type. Has a phantom type parameter to associate each grammar with the type its sexps represent. This makes it harder to apply grammars to the wrong type, while grammars can still be easily coerced to a new type if needed.
val coerce :
('a : any) ('b : any). 'a Sexplib.Sexp_grammar.t ->
'b Sexplib.Sexp_grammar.t @@ statelessConvert a sexp grammar for one type to another.
val tag :
('a : any). 'a Sexplib.Sexp_grammar.t ->
key:string ->
value:Sexplib0.Sexp.t ->
'a Sexplib.Sexp_grammar.t @@ statelessAdd a key/value tag to a grammar.
This reserved key is used for all tags generated from doc comments.
This reserved key can be used to associate a type name with a grammar.
This reserved key indicates that a sexp represents a key/value association. The tag's value is ignored.
This reserved key indicates that a sexp is a key in a key/value association. The tag's value is ignored.
This reserved key indicates that a sexp is a value in a key/value association. The tag's value is ignored.
val remember_to_update_these_together :
t_of_sexp:(Sexplib.Sexp.t -> 'a) ->
t_sexp_grammar:'a Sexplib.Sexp_grammar.t ->
(Sexplib.Sexp.t -> 'a) * 'a Sexplib.Sexp_grammar.t @@ portableIdiomatic usage looks like this:
let t_of_sexp, t_sexp_grammar =
remember_to_update_these_together ~t_of_sexp ~t_sexp_grammar
;;val remember_to_update_these_together__portable :
t_of_sexp:(Sexplib.Sexp.t -> 'a) @ portable ->
t_sexp_grammar:'a Sexplib.Sexp_grammar.t ->
(Sexplib.Sexp.t -> 'a) * 'a Sexplib.Sexp_grammar.t @ portable @@ portable