package ppx_deriving
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=5595bfe668d3434b1f1babb3ccb43d4cab3dc1d562b8d8c47c410d88546253ff
sha512=68ab402c8d1461d644eceb5804df66eaab445486adbfbab326114e91f301c2c7e2a5290f04d88a0617a836d3890b4f48f1e1d4bf9aee406c5c2f5362753229f1
doc/ppx_deriving.api/Ppx_deriving/Arg/index.html
Module Ppx_deriving.ArgSource
Arg contains convenience functions that extract constants from AST fragments, to be used when parsing options or [\@attributes] attached to types, fields or constructors.
The ~name argument is used in error messages and should receive the name of the deriving plugin, e.g. "show".
A type of conversion functions.
A conversion function of type 'a conv converts a raw expression into an argument of type 'a. Or returns Error "error" if conversion fails.
expr returns the input expression as-is.
bool expr extracts a boolean constant from expr, or returns Error "boolean" if expr does not contain a boolean literal.
int expr extracts an integer constant from expr, or returns Error "integer" if expr does not contain an integer literal.
string expr extracts a string constant from expr, or returns Error "string" if expr does not contain a string literal.
char expr extracts a char constant from expr, or returns Error "char" if expr does not contain a char literal.
enum values expr extracts a polymorphic variant constant from expr, or returns 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 Error "list:..." where ... is the error returned by f, or returns Error "list" if expr does not contain a list.
get_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 ..get_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.
get_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.