Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file sexp_grammar_intf.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267open!Core[@@@warning"-30"](*_ allow duplicate field names *)openstructmoduleSexp_grammar=Sexplib0.Sexp_grammarendmoduleField=structtype'at=|Optionalof'a|Requiredof'aendmoduleAnd_tags=structtype'at='a*(string,Sexp.t)List.Assoc.tend(** Common callbacks for folding over a sexp grammar. *)moduletypeCallbacks_for_fold_common=sig(** Represents the result of folding over a grammar. *)typet(** Represents the result of folding over a list grammar. *)typelist_t(** The remaining functions correspond to grammar constructors. Excludes the
constructors related to recursive grammars: [Tycon], [Tyvar], and [Recursive]. *)valany:string->tvalbool:tvalchar:tvalinteger:tvalfloat:tvalstring:tvaloption:t->tvalunion:tlist->tvallist:list_t->tvalempty:list_tvalcons:t->list_t->list_tvalmany:t->list_tvalrecord:(string,list_tField.tAnd_tags.t)List.Assoc.t->allow_extra_fields:bool->list_tvalvariant:(string,list_toptionAnd_tags.t)List.Assoc.t->case_sensitivity:Sexp_grammar.case_sensitivity->tvallazy_:tLazy.t->tvaltag:t->string->Sexp.t->tend(** Callbacks for nonrecursive folds. *)moduletypeCallbacks_for_fold_nonrecursive=sigincludeCallbacks_for_fold_common(** Callers must explicitly handle constructors for recursive grammars. *)valtyvar:string->tvaltycon:string->params:tlist->defns:(string,stringlist*t)List.Assoc.t->tvalrecursive:string->params:tlist->tend(** Callbacks for recursive folds. *)moduletypeCallbacks_for_fold_recursive=sigincludeCallbacks_for_fold_common(** Allows folds to tie the knot for recursive grammars. Must not force its argument
immediately. *)valof_lazy_recursive:tLazy.t->tendmoduletypeFold=sigtypettypelist_tvalof_typed_grammar:_Sexp_grammar.t->tvalof_grammar:Sexp_grammar.grammar->tvalof_list_grammar:Sexp_grammar.list_grammar->list_tendmoduletypeFold_partial=sigtypettypelist_tvalof_typed_grammar_exn:_Sexp_grammar.t->tvalof_grammar_exn:Sexp_grammar.grammar->tvalof_list_grammar_exn:Sexp_grammar.list_grammar->list_tendmoduletypeSexp_grammar=sigmoduletypeCallbacks_for_fold_common=Callbacks_for_fold_commonmoduletypeCallbacks_for_fold_nonrecursive=Callbacks_for_fold_nonrecursivemoduletypeCallbacks_for_fold_recursive=Callbacks_for_fold_recursivemoduletypeFold=FoldmoduletypeFold_partial=Fold_partialmoduleField:sigincludemoduletypeofstructincludeFieldendvalmap:'at->f:('a->'b)->'btendmoduleCase_sensitivity:sigtypet=Sexp_grammar.case_sensitivity=|Case_insensitive|Case_sensitive|Case_sensitive_except_first_character[@@derivingsexp_of](** Produces a comparator that compares with respect to a name kind. *)valto_string_comparator:t->(moduleComparator.Swithtypet=string)endtypegrammar=Sexp_grammar.grammar=|Anyofstring|Bool|Char|Integer|Float|String|Optionofgrammar|Listoflist_grammar|Variantofvariant|Unionofgrammarlist|Taggedofgrammarwith_tag|Tyvarofstring|Tyconofstring*grammarlist*defnlist|Recursiveofstring*grammarlist|LazyofgrammarLazy.tandlist_grammar=Sexp_grammar.list_grammar=|Empty|Consofgrammar*list_grammar|Manyofgrammar|Fieldsofrecordandrecord=Sexp_grammar.record={allow_extra_fields:bool;fields:fieldwith_tag_listlist}andfield=Sexp_grammar.field={name:string;required:bool;args:list_grammar}andcase_sensitivity=Sexp_grammar.case_sensitivity=|Case_insensitive|Case_sensitive|Case_sensitive_except_first_characterandvariant=Sexp_grammar.variant={case_sensitivity:case_sensitivity;clauses:clausewith_tag_listlist}andclause=Sexp_grammar.clause={name:string;clause_kind:clause_kind}andclause_kind=Sexp_grammar.clause_kind=|Atom_clause|List_clauseof{args:list_grammar}and'awith_tag='aSexp_grammar.with_tag={key:string;value:Sexp.t;grammar:'a}and'awith_tag_list='aSexp_grammar.with_tag_list=|Tagof'awith_tag_listwith_tag|No_tagof'aanddefn=Sexp_grammar.defn={tycon:string;tyvars:stringlist;grammar:grammar}and'at='aSexp_grammar.t={untyped:grammar}[@@unboxed][@@derivingbin_io,compare,equal,sexp](** For stable serializations of these types, see [Sexp_grammar_stable]. *)valcoerce:_t->_t(** Folds over a grammar. *)moduleFold_nonrecursive(Callbacks:Callbacks_for_fold_nonrecursive):Foldwithtypet:=Callbacks.tandtypelist_t:=Callbacks.list_t(** Like [Fold_nonrecursive]. Ties the knot for recursive grammars. May raise if the
grammar contains malformed recursive definitions, e.g. an undefined type variable or
applying a type constructor with the wrong arity. Exceptions may be delayed until
[of_lazy] values are forced. *)moduleFold_recursive(Callbacks:Callbacks_for_fold_recursive):Fold_partialwithtypet:=Callbacks.tandtypelist_t:=Callbacks.list_t(** An instance of [Fold_nonrecursive]. Produces an equivalent grammar with no [Lazy]
nodes. Implicitly used by [sexp_of_t]. *)moduleEager_copy:Foldwithtypet:=grammarandtypelist_t:=list_grammar(** An instance of [Fold_recursive]. Produces an equivalent grammar with no [Recursive],
[Tycon], or [Tyvar] nodes. This can be useful for subsequent grammar processing
without the need for type variable / type constructor bookkeeping. The resulting
tree may unfold infinitely, and uses [Lazy] nodes to avoid divergence. *)moduleUnroll_recursion:Fold_partialwithtypet:=grammarandtypelist_t:=list_grammar(** {2 Tagging} *)(** [first_tag_value tags name of_sexp] returns the first value of [name] in [tags]. *)valfirst_tag_value:(string*Sexp.t)list->string->[%of_sexp:'a]->'aOr_error.toption(** [completion_suggested = false] on a variant constructor means that
[Sexp_grammar_completion] will not suggest the constructor as a completion. The
constructor is still recognized as valid syntax. Completions are still suggested for
its arguments.
Default is [true].
This tag is ignored if its value is not a bool or if it is not placed on a variant
constructor. *)valcompletion_suggested:string(** [validate_sexp [%sexp_grammar: t]] prepares a function to report whether the grammar
of [t] accepts a sexp.
Staged because the outer application does a lot of work. It is often valuable to apply
[accepts] to a grammar once, then apply the result to multiple sexps. *)valvalidate_sexp:_t->(Sexp.t->unitOr_error.t)Staged.t(** [validate_sexp_untyped] is like [validate_sexp] but takes the untyped grammar. *)valvalidate_sexp_untyped:grammar->(Sexp.t->unitOr_error.t)Staged.t(** [validate_sexp_list] is like [validate_sexp] but validates a sequence of sexps. *)valvalidate_sexp_list:list_grammar->(Sexp.tlist->unitOr_error.t)Staged.t(** [unroll_tycon [%sexp_grammar: t]] returns an equivalent grammar in which
the top-most node is not a [Tycon].
Acts as identity if the condition is already satisfied, and
does a shallow evaluation of the [Tycon] otherwise.
If [tag_prefix] is provided, then [Recursive] and [Tyvar] nodes substituted by
[unroll_tycon] will be tagged respectively with keys [tag_prefix ^ ".tycon"] and
[tag_prefix ^ ".tyvar"]. The value is the name of the tycon / tyvar. *)valunroll_tycon:?tag_prefix:string->'at->'at(** [unroll_tycon_untyped] is like [unroll_tycon] but takes the untyped grammar. *)valunroll_tycon_untyped:?tag_prefix:string->grammar->grammarend