Module Dune_lang.Decoder
type ast= Ast.t=|Atom of Stdune.Loc.t * Atom.t|Quoted_string of Stdune.Loc.t * string|Template of Template.t|List of Stdune.Loc.t * ast listtype hint={on : string;candidates : string list;}
exceptionDecoder of Stdune.Loc.t * string * hint option
type ('a, 'kind) parserMonad producing a value of type
'aby parsing an input composed of a sequence of S-expressions.The input can be seen either as a plain sequence of S-expressions or a list of fields. The
'kindparameter indicates how the input is seen:with
'kind = [values], the input is seen as an ordered sequence of S-expressions
with
'kind = [fields], the input is seen as an unordered sequence of fields
A field is a S-expression of the form:
(<atom> <values>...)whereatomis a plain atom, i.e. not a quoted string and not containing variables.valuesis a sequence of zero, one or more S-expressions.It is possible to switch between the two mode at any time using the appropriate combinator. Some primitives can be used in both mode while some are specific to one mode.
val parse : 'a t -> Stdune.Univ_map.t -> ast -> 'aparse parser context sexpparse a S-expression using the following parser. The input consist of a single S-expression.contextallows to pass extra information such as versions to individual parsers.
val return : 'a -> ('a, _) parserval (>>=) : ('a, 'k) parser -> ('a -> ('b, 'k) parser) -> ('b, 'k) parserval (>>|) : ('a, 'k) parser -> ('a -> 'b) -> ('b, 'k) parserval (>>>) : (unit, 'k) parser -> ('a, 'k) parser -> ('a, 'k) parserval map : ('a, 'k) parser -> f:('a -> 'b) -> ('b, 'k) parserval try_ : ('a, 'k) parser -> (exn -> ('a, 'k) parser) -> ('a, 'k) parserval get : 'a Stdune.Univ_map.Key.t -> ('a option, _) parserAccess to the context
val set : 'a Stdune.Univ_map.Key.t -> 'a -> ('b, 'k) parser -> ('b, 'k) parserval get_all : (Stdune.Univ_map.t, _) parserval set_many : Stdune.Univ_map.t -> ('a, 'k) parser -> ('a, 'k) parserval loc : (Stdune.Loc.t, _) parserReturn the location of the list currently being parsed.
val if_eos : then_:('a, 'b) parser -> else_:('a, 'b) parser -> ('a, 'b) parserEnd of sequence condition. Uses
then_if there are no more S-expressions to parse,else_otherwise.
val if_list : then_:'a t -> else_:'a t -> 'a tIf the next element of the sequence is a list, parse it with
then_, otherwise parse it withelse_.
val if_paren_colon_form : then_:((Stdune.Loc.t * string) -> 'a) t -> else_:'a t -> 'a tIf the next element of the sequence is of the form
(:<name> ...), usethen_to parse.... Otherwise useelse_.
val keyword : string -> unit tExpect the next element to be the following atom.
val match_keyword : (string * 'a t) list -> fallback:'a t -> 'a tmatch_keyword [(k1, t1); (k2, t2); ...] ~fallbackinspects the next element of the input sequence. If it is an atom equal to one of
k1,k2, ... then the corresponding parser is used to parse the rest of the sequence. Otherfallbackis used.
val until_keyword : string -> before:'a t -> after:'b t -> ('a list * 'b option) tUse
beforeto parse elements until the keyword is reached. Then useafterto parse the rest.
type kind=|Values of Stdune.Loc.t * string option|Fields of Stdune.Loc.t * string optionWhat is currently being parsed. The second argument is the atom at the beginnig of the list when inside a
sum ...orfield ....
val kind : (kind, _) parserval repeat : 'a t -> 'a list trepeat tusetto consume all remaning elements of the input until the end of sequence is reached.
val enter : 'a t -> 'a tenter texpect the next element of the input to be a list and parse its contents witht.
val fields : 'a fields_parser -> 'a tfields fpconverts the rest of the current input to a list of fields and parse them withfp. This operation fails if one the S-expression in the input is not of the form(<atom> <values>...)
val record : 'a fields_parser -> 'a trecord fp = enter (fields fp)
Consume the next element of the input as a string, int, char, ...
include Stdune.Sexp_intf.Combinators with type 'a t := 'a t
val junk : unit tConsume and ignore the next element of the input
val junk_everything : (unit, _) parserIgnore all the rest of the input
val plain_string : (loc:Stdune.Loc.t -> string -> 'a) -> 'a tplain_string fexpects the next element of the input to be a plain string, i.e. either an atom or a quoted string, but not a template nor a list.
val fix : ('a t -> 'a t) -> 'a tval of_sexp_error : ?hint:hint -> Stdune.Loc.t -> string -> _val of_sexp_errorf : ?hint:hint -> Stdune.Loc.t -> ('a, unit, string, 'b) Stdlib.format4 -> 'aval no_templates : ?hint:hint -> Stdune.Loc.t -> ('a, unit, string, 'b) Stdlib.format4 -> 'aval located : ('a, 'k) parser -> (Stdune.Loc.t * 'a, 'k) parserval enum : (string * 'a) list -> 'a tval sum : (string * 'a t) list -> 'a tParser that parse a S-expression of the form
(<atom> <s-exp1> <s-exp2> ...)or<atom>.<atom>is looked up in the list and the remaining s-expressions are parsed using the corresponding list parser.
val map_validate : 'a fields_parser -> f:('a -> ('b, string) Stdune.Result.t) -> 'b fields_parserCheck the result of a list parser, and raise a properly located error in case of failure.
Parsing record fields
val field : string -> ?default:'a -> ?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) -> 'a t -> 'a fields_parserval field_o : string -> ?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) -> 'a t -> 'a option fields_parserval field_b : ?check:unit t -> ?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) -> string -> bool fields_parserval field_o_b : ?check:unit t -> ?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) -> string -> bool option fields_parserval multi_field : string -> 'a t -> 'a list fields_parserA field that can appear multiple times
val field_present_too_many_times : Stdune.Univ_map.t -> string -> Ast.t list -> _Default value for
on_dup. It fails with an appropriate error message.
val leftover_fields : Ast.t list fields_parser
module Let_syntax : sig ... end