Module OpamPp
Generic bidirectional transformation toolbox for parsing/printing
Parsing positions and error reporting helpers
type bad_format= OpamTypes.pos option * stringFormat error reporting: position and message
exceptionBad_format of bad_formatAll the following parsing function raise
Bad_formatin case the input does not have the right format.
exceptionBad_format_list of bad_format list
val bad_format : ?pos:OpamTypes.pos -> ('a, unit, string, 'b) Stdlib.format4 -> 'aRaise
Bad_format.
val string_of_bad_format : ?file:string -> exn -> stringval add_pos : OpamTypes.pos -> exn -> exnAdds a position to a Bad_format exception if it doesn't have one yet
Parser/printers
type ('a, 'b) t= private{parse : pos:OpamTypes.pos -> 'a -> 'b;print : 'b -> 'a;ppname : string;name_constr : string -> string;}The type of bidirectional parsers from
'ato'b. We abuse the terms and describe going from'ato'bas "parsing", and going from'bto'aas "printing". Parsing is generally error-prone, while printing is not expected to fail, so the handling isn't really symmetrical.parse (print x)should always be the identity, while no guarantee is given regardingprint (parse x)
val pp : ?name:string -> ?name_constr:(string -> string) -> (pos:OpamTypes.pos -> 'a -> 'b) -> ('b -> 'a) -> ('a, 'b) tBase constructor for Pp.t, from a parser function and a printer function.
name_constris used to construct the resulting name when on the left of a pipe. Names are for tracing errors.
val of_pair : string -> (('a -> 'b) * ('b -> 'a)) -> ('a, 'b) tConstructor of Pp.t from a name and a pair
val parse : ('a, 'b) t -> pos:OpamTypes.pos -> 'a -> 'bBase call for parsing with a pp
val print : ('a, 'b) t -> 'b -> 'aBase call for printing with a pp
val unexpected : ?pos:OpamTypes.pos -> unit -> 'aRaises an exception handled by parser calls
Various pp constructors
module Op : sig ... endval check : ?name:string -> ?errmsg:string -> ('a -> bool) -> ('a, 'a) tIdentity pp, unless the check fails. The check is turned into an assertion when printing
val map_pair : ?name:string -> ?posf1:('a -> OpamTypes.pos) -> ?posf2:('b -> OpamTypes.pos) -> ('a, 'c) t -> ('b, 'd) t -> ('a * 'b, 'c * 'd) tval map_fst : ('a, 'b) t -> ('a * 'c, 'b * 'c) tBuilds a pp of pairs by passing the second term along
val map_snd : ('a, 'b) t -> ('c * 'a, 'c * 'b) tBuilds a pp of pairs by passing the first term along
val map_list : ?name:string -> ?posf:('a -> OpamTypes.pos) -> ('a, 'b) t -> ('a list, 'b list) tval map_option : ?name:string -> ('a, 'b) t -> ('a option, 'b option) tval singleton : ('a list, 'a) tParsing fails on non-singleton lists
val last : ('a list, 'a) tUse for the rightmost element to close a
^+sequence, e.g.pp1 ^+ pp2 ^+ last -| pp3
module type STR = sig ... endval of_module : string -> (module STR with type t = 'a) -> (string, 'a) tGenerates a string pp from a module with of/to string functions
Combinators to parse to a record from a list of (field name, field setter, field getter)
type ('a, 'value) field_parser= ('a * 'value option, 'a) tUsed to parse a single field of a record:
'aon the left is the accumulator, or value of the record parsed so far. (in lens terms,getwould be the print operation that extracts the field for the record, whilesetwould be the parse operation that takes the input and record, and updates a given field in the record)
val ppacc : ?cleanup:(pos:OpamTypes.pos -> 'acc -> 'a -> 'a) -> ('a -> 'acc -> 'acc) -> ('acc -> 'a) -> ('value, 'a) t -> ('acc, 'value) field_parserMake a field parser from setter, getter and base pp.
cleanupis an optional sanitisation function that is called on parsed elements before calling the setter.
val ppacc_opt : ?cleanup:(pos:OpamTypes.pos -> 'acc -> 'a -> 'a) -> ('a -> 'acc -> 'acc) -> ('acc -> 'a option) -> ('value, 'a) t -> ('acc, 'value) field_parserSame as
ppacc, but when the field may be unset in the record, i.e. the getter returns an option
val ppacc_ignore : ('a, OpamTypes.value) field_parserA field parser that ignores its argument
val embed : ('a -> 'acc -> 'acc) -> ('acc -> 'a) -> ('a, 'value) field_parser -> ('acc, 'value) field_parser