Ppx_deriving_tools.ConvSourceA common scheme to define data conversions (like to_json/of_json).
A simplified parsetree representation.
We define a few types to represent the data we want to derive conversions for. Such types are less verbose but less precise than the original parsetree, though it is enough for conversion purposes.
The types still keep the original parsetree nodes as context (this is also needed to play well with Ppxlib.Attributes API).
type 'ctx tuple = {tpl_loc : Ppxlib.location;tpl_types : Ppxlib.core_type list;tpl_ctx : 'ctx;}type 'ctx record = {rcd_loc : Ppxlib.location;rcd_fields : Ppxlib.label_declaration list;rcd_ctx : 'ctx;}type variant_case = | Vcs_tuple of Ppxlib.label Ppxlib.loc * variant_case_ctx tuple| Vcs_record of Ppxlib.label Ppxlib.loc * variant_case_ctx recordand variant_case_ctx = | Vcs_ctx_variant of Ppxlib.constructor_declaration| Vcs_ctx_polyvariant of Ppxlib.row_fieldtype variant = {vrt_loc : Ppxlib.location;vrt_cases : variant_case list;vrt_ctx : variant_ctx;}and variant_ctx = | Vrt_ctx_variant of Ppxlib.type_declaration| Vrt_ctx_polyvariant of Ppxlib.core_typeval deriving_to :
name:Ppxlib.label ->
t_to:(loc:Ppxlib.location -> Ppxlib.core_type) ->
derive_of_tuple:
(derive_of_core_type ->
Ppxlib.core_type tuple ->
Ppxlib.expression list ->
Ppxlib.expression) ->
derive_of_record:
(derive_of_core_type ->
Ppxlib.type_declaration record ->
Ppxlib.expression list ->
Ppxlib.expression) ->
derive_of_variant_case:
(derive_of_core_type ->
variant_case ->
Ppxlib.expression list ->
Ppxlib.expression) ->
unit ->
derivingDefine a serializer.
val deriving_of :
name:Ppxlib.label ->
of_t:(loc:Ppxlib.location -> Ppxlib.core_type) ->
is_allow_any_constr:(variant_case_ctx -> bool) ->
derive_of_tuple:
(derive_of_core_type ->
Ppxlib.core_type tuple ->
Ppxlib.expression ->
Ppxlib.expression) ->
derive_of_record:
(derive_of_core_type ->
Ppxlib.type_declaration record ->
Ppxlib.expression ->
Ppxlib.expression) ->
derive_of_variant:
(derive_of_core_type ->
variant ->
allow_any_constr:(Ppxlib.expression -> Ppxlib.expression) option ->
Ppxlib.expression ->
Ppxlib.expression ->
Ppxlib.expression) ->
derive_of_variant_case:
(derive_of_core_type ->
(Ppxlib.expression option -> Ppxlib.expression) ->
variant_case ->
allow_any_constr:(Ppxlib.expression -> Ppxlib.expression) option ->
Ppxlib.expression ->
Ppxlib.expression) ->
unit ->
derivingDefine a deserializer.
val deriving_of_match :
name:Ppxlib.label ->
of_t:(loc:Ppxlib.location -> Ppxlib.core_type) ->
cmp_sort_vcs:(variant_case_ctx -> variant_case_ctx -> int) ->
derive_of_tuple:
(derive_of_core_type ->
Ppxlib.core_type tuple ->
Ppxlib.expression ->
Ppxlib.expression) ->
derive_of_record:
(derive_of_core_type ->
Ppxlib.type_declaration record ->
Ppxlib.expression ->
Ppxlib.expression) ->
derive_of_variant_case:
(derive_of_core_type ->
(Ppxlib.expression option -> Ppxlib.expression) ->
variant_case ->
Ppxlib.case) ->
unit ->
derivingDefine a deserializer using pattern matching.
This is a less general but more compact variant of deriving_of, for cases where the serialized data can be inspected with pattern matching.