Module Context_free.Rule
Local rewriting rules.
This module lets you define local rewriting rules, such as extension point expanders. It is not completely generic and you cannot define any kind of rewriting, it currently focuses on what is commonly used. New scheme can be added on demand.
We have some ideas to make this fully generic, but this hasn't been a priority so far.
val extension : Ppxlib.Extension.t -> tRewrite an extension point
val special_function : Ppxlib__.Import.string -> (Ppxlib__.Import.expression -> Ppxlib__.Import.expression Ppxlib__.Import.option) -> tspecial_function id expandis a rule to rewrite a function call at parsing time.idis the identifier to match on andexpandis used to expand the full function application (it gets the Pexp_apply node). If the function is found in the tree without being applied,expandgets only the identifier (Pexp_ident node) so you should handle both cases.If
idis an operator identifier and contains dots, it should be parenthesized (e.g."(+.+)").expandmust decide whether the expression it receive can be rewritten or not. Especially ppxlib makes the assumption thatexpandis idempotent. It will loop if it is not.
module Constant_kind : sig ... endUsed for the
constantfunction.
val constant : Constant_kind.t -> Ppxlib__.Import.char -> (Ppxlib.Location.t -> Ppxlib__.Import.string -> Ppxlib__.Import.Parsetree.expression) -> tconstant kind suffix expanderRegisters an extension for transforming constants literals, based on the suffix character.
type ('a, 'b, 'c) attr_group_inline= ('b, 'c) Ppxlib.Attribute.t -> (ctxt:Ppxlib.Expansion_context.Deriver.t -> Ppxlib__.Import.Asttypes.rec_flag -> 'b Ppxlib__.Import.list -> 'c Ppxlib__.Import.option Ppxlib__.Import.list -> 'a Ppxlib__.Import.list) -> tMatch the attribute on a group of items, such as a group of recursive type definitions (Pstr_type, Psig_type). The expander will be triggered if any of the item has the attribute. The expander is called as follow:
expand ~loc ~path rec_flag items valueswhere
valuesis the list of values associated to the attribute for each item initems.expandmust return a list of element to add after the group. For instance a list of structure item to add after a group of type definitions.
val attr_str_type_decl : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_declaration, _) attr_group_inlineval attr_sig_type_decl : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_declaration, _) attr_group_inlineval attr_str_type_decl_expect : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_declaration, _) attr_group_inlineThe _expect variants are for producing code that is compared to what the user wrote in the source code.
val attr_sig_type_decl_expect : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_declaration, _) attr_group_inline
type ('a, 'b, 'c) attr_inline= ('b, 'c) Ppxlib.Attribute.t -> (ctxt:Ppxlib.Expansion_context.Deriver.t -> 'b -> 'c -> 'a Ppxlib__.Import.list) -> tSame as
attr_group_inlinebut for elements that are not part of a group, such as exceptions and type extensions
val attr_str_module_type_decl : (Ppxlib__.Import.structure_item, Ppxlib__.Import.module_type_declaration, _) attr_inlineval attr_sig_module_type_decl : (Ppxlib__.Import.signature_item, Ppxlib__.Import.module_type_declaration, _) attr_inlineval attr_str_module_type_decl_expect : (Ppxlib__.Import.structure_item, Ppxlib__.Import.module_type_declaration, _) attr_inlineval attr_sig_module_type_decl_expect : (Ppxlib__.Import.signature_item, Ppxlib__.Import.module_type_declaration, _) attr_inlineval attr_str_type_ext : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_extension, _) attr_inlineval attr_sig_type_ext : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_extension, _) attr_inlineval attr_str_type_ext_expect : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_extension, _) attr_inlineval attr_sig_type_ext_expect : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_extension, _) attr_inlineval attr_str_exception : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_exception, _) attr_inlineval attr_sig_exception : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_exception, _) attr_inlineval attr_str_exception_expect : (Ppxlib__.Import.structure_item, Ppxlib__.Import.type_exception, _) attr_inlineval attr_sig_exception_expect : (Ppxlib__.Import.signature_item, Ppxlib__.Import.type_exception, _) attr_inline