Dune_lang.DecoderSourceReading OCaml values from dune lang ones
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 listMonad producing a value of type 'a by 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 'kind parameter indicates how the input is seen:
'kind = [values], the input is seen as an ordered sequence of S-expressions!'kind = [fields], the input is seen as an unordered sequence of fieldsA field is a S-expression of the form: (<atom> <values>...) where atom is a plain atom, i.e. not a quoted string and not containing variables. values is 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.
parse parser context sexp parse a S-expression using the following parser. The input consist of a single S-expression. context allows to pass extra information such as versions to individual parsers.
Access to the context
Return the location of the list currently being parsed.
a <|> b is either a or b. If a fails to parse the input, then try b. If b fails as well, raise the error from the parser that consumed the most input.
atom_matching f expects the next element to be an atom for which f returns Some v. desc is used to describe the atom in case of error. f must not raise.
keyword s is a short-hand for
atom_matching (String.equal s) ~desc:(sprintf "'%s'" s) Use before to parse elements until the keyword is reached. Then use after to parse the rest.
What is currently being parsed. The second argument is the atom at the beginnig of the list when inside a sum ... or field ....
repeat t uses t to consume all remaining elements of the input until the end of sequence is reached.
enter t expect the next element of the input to be a list and parse its contents with t.
fields fp converts the rest of the current input to a list of fields and parse them with fp. This operation fails if one the S-expression in the input is not of the form (<atom> <values>...)
maybe t is a short-hand for:
(let+ x = t in
Some x)
<|> return NoneConsume the next element as a number of bytes, requiring 'B', 'KB', 'MB' or 'GB' suffix
plain_string f expects 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.
Parser 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.
If force_parens is true, then the form <atom> is never accepted. The default is false.
val map_validate :
('a, 'k) parser ->
f:('a -> ('b, Stdune.User_message.t) Stdune.Result.t) ->
('b, 'k) parserCheck the result of a list parser, and raise a properly located error in case of failure.
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 fields_mutually_exclusive :
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
?default:'a ->
(string * 'a t) list ->
'a fields_parserParser for mutually exclusive fields. If default is provided, allow fields absence.
val field_b :
?check:unit t ->
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
string ->
bool fields_parserTest if the field is present
val field_o_b :
?check:unit t ->
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
string ->
bool option fields_parserDifferentiate between not present and set to true or false
A field that can appear multiple times
Treat the remainig fields as a list of sum values
Default value for on_dup. It fails with an appropriate error message.