type 'a conv = Parsetree.expression -> ('a, string) Result.resultA type of conversion functions.
A conversion function of type 'a conv converts a raw expression into an argument of type 'a. Or returns Result.Error "error" if conversion fails.
val expr : Parsetree.expression convexpr returns the input expression as-is.
val bool : bool convbool expr extracts a boolean constant from expr, or returns Result.Error "boolean" if expr does not contain a boolean literal.
val int : int convint expr extracts an integer constant from expr, or returns Result.Error "integer" if expr does not contain an integer literal.
val string : string convstring expr extracts a string constant from expr, or returns Result.Error "string" if expr does not contain a string literal.
val char : char convchar expr extracts a char constant from expr, or returns Result.Error "char" if expr does not contain a char literal.
val enum : string list -> string convenum values expr extracts a polymorphic variant constant from expr, or returns Result.Error "one of: `a, `b, ..." if expr does not contain a polymorphic variant constructor included in values.
list f expr extracts a list constant from expr and maps every element through f, or returns Result.Error "list:..." where ... is the error returned by f, or returns Result.Error "list" if expr does not contain a list.
val get_attr : deriver:string -> 'a conv -> Parsetree.attribute option -> 'a optionget_attr ~deriver conv attr extracts the expression from attr and converts it with conv, raising Location.Error if attr is not a structure with a single expression or conv fails; or returns None if attr is None. The name of the deriving plugin should be passed as deriver; it is used in error messages.
Example usage:
let deriver = "index"
(* ... *)
let kind =
match Ppx_deriving.attr ~deriver "kind" pcd_attributes |>
Ppx_deriving.Arg.(get_attr ~deriver (enum ["flat"; "nested"])) with
| Some "flat" -> `flat | Some "nested" -> `nested | None -> `default
in ..val get_flag : deriver:string -> Parsetree.attribute option -> boolget_flag ~deriver attr returns true if attr is an empty attribute or false if it is absent, raising Location.Error if attr is not a structure. The name of the deriving plugin should be passed as deriver; it is used in error messages.
val get_expr : deriver:string -> 'a conv -> Parsetree.expression -> 'aget_expr ~deriver conv exp converts expression exp with conv, raising Location.Error if conv fails. The name of the deriving plugin should be passed as deriver; it is used in error messages.