package dune
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=77cb5f483221b266ded2b85fc84173ae0089a25134a086be922e82c131456ce6
sha512=02f00fd872aa49b832fc8c1e928409f23c79ddf84a53009a58875f222cca36fbb92c905e12c539caec9cbad723f195a8aa24218382dca35a903b3f52b11f06f2
doc/dune._dune_lang/Dune_lang/Decoder/index.html
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 list
Monad 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:
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>...)
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.
val parse : 'a t -> Stdune.Univ_map.t -> ast -> 'a
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.
val return : 'a -> ('a, _) parser
val get : 'a Stdune.Univ_map.Key.t -> ('a option, _) parser
Access to the context
val set : 'a Stdune.Univ_map.Key.t -> 'a -> ('b, 'k) parser -> ('b, 'k) parser
val get_all : (Stdune.Univ_map.t, _) parser
val set_many : Stdune.Univ_map.t -> ('a, 'k) parser -> ('a, 'k) parser
val loc : (Stdune.Loc.t, _) parser
Return the location of the list currently being parsed.
End of sequence condition. Uses then_
if there are no more S-expressions to parse, else_
otherwise.
If the next element of the sequence is a list, parse it with then_
, otherwise parse it with else_
.
val if_paren_colon_form :
then_:((Stdune.Loc.t * string) -> 'a) t ->
else_:'a t ->
'a t
If the next element of the sequence is of the form (:<name> ...)
, use then_
to parse ...
. Otherwise use else_
.
val keyword : string -> unit t
Expect the next element to be the following atom.
match_keyword [(k1, t1); (k2, t2); ...] ~fallback
inspects 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. Other fallback
is used.
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
use t
to consume all remaning 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
.
val fields : 'a fields_parser -> 'a 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>...)
val record : 'a fields_parser -> 'a t
record fp = enter (fields fp)
Consume the next element of the input as a string, int, char, ...
val unit : unit t
val char : char t
val string : string t
val int : int t
val float : float t
val bool : bool t
val junk : unit t
Consume and ignore the next element of the input
val junk_everything : (unit, _) parser
Ignore all the rest of the input
val plain_string : (loc:Stdune.Loc.t -> string -> 'a) -> 'a t
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.
val located : ('a, 'k) parser -> (Stdune.Loc.t * 'a, 'k) parser
val enum : (string * 'a) list -> 'a t
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.
val map_validate :
'a fields_parser ->
f:('a -> ('b, Stdune.User_message.t) Stdune.Result.t) ->
'b fields_parser
Check 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_parser
val field_o :
string ->
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
'a t ->
'a option fields_parser
val fields_mutually_exclusive :
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
(string * 'a t) list ->
'a fields_parser
val field_b :
?check:unit t ->
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
string ->
bool fields_parser
val field_o_b :
?check:unit t ->
?on_dup:(Stdune.Univ_map.t -> string -> Ast.t list -> unit) ->
string ->
bool option fields_parser
val multi_field : string -> 'a t -> 'a list fields_parser
A 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