Module Ppxlib__.Attribute
type ('context, 'payload) tType of declared attribute.
The
'contexttype parameter describes where the attribute is expected and the'payloadone what its payload should contain.
module Context : sig ... endval declare : Ppxlib__.Import.string -> 'a Context.t -> (Ppxlib__.Import.payload, 'b, 'c) Ppxlib.Ast_pattern.t -> 'b -> ('a, 'c) tdeclare fully_qualified_name context payload_pattern kdeclares an attribute.kis used to build the value resulting from parsing the payload.For instance if a rewriter named "foo" expect the attribute
@@defaulton record field declaration with an expression as payload:let default = Attribute.declare "foo.default" Attribute.Context.label_declaration Ast_pattern.(pstr (pstr_eval __ nil)) (fun x -> x) ;;fully_qualified_nameis expected to be a dot-separated list of names. When matching, any full suffix will be accepted. So for instance an attribute declared with name "foo.bar.default" will match exactly these attribute names: "default", "bar.default" and "foo.bar.default".Additionally it is possible to prevent a suffix to be shortened by prefixing it with '@'. So for instance an attribute declared with name "foo.@bar.default" will match exactly these attribute names: "bar.default" and "foo.bar.default".
When matching against a list of attributes on an item, if several matches are possible, the longest one is used. For instance using the attribute "foo.default" declared in the previous example, on this code it will match the
@foo.default 0attribute:type t = { x : int [@default 42] [@foo.default 0] }This is to allow the user to specify a
@defaultattribute for all re-writers that use it but still put a specific one for one specific re-writer.It is not allowed to declare an attribute with a name that matches a previously-defined one on the same context. For instance trying to declare the same attribute twice will fail.
val declare_with_name_loc : Ppxlib__.Import.string -> 'a Context.t -> (Ppxlib__.Import.payload, 'b, 'c) Ppxlib.Ast_pattern.t -> (name_loc:Ppxlib.Location.t -> 'b) -> ('a, 'c) tSame as
declarebut the callback receives the location of the name of the attribute.
val name : (_, _) t -> Ppxlib__.Import.stringval context : ('a, _) t -> 'a Context.tval get : ('a, 'b) t -> ?mark_as_seen:Ppxlib__.Import.bool -> 'a -> 'b Ppxlib__.Import.optionGets the associated attribute value. Marks the attribute as seen unless
mark_as_seen=false.
val consume : ('a, 'b) t -> 'a -> ('a * 'b) Ppxlib__.Import.optionconsume t xreturns the value associated to attributetonxif present as well asxwithtremoved.
val remove_seen : 'a Context.t -> packed Ppxlib__.Import.list -> 'a -> 'aremove_seen x attrsremoves the set of attributes matched by elements ofattrs. Only remove them if they where seen bygetorconsume.
module Floating : sig ... endval explicitly_drop : Ppxlib.Ast_traverse.iterCode that is voluntarily dropped by a rewriter needs to be given to this object. All attributes inside will be marked as handled.
val check_unused : Ppxlib.Ast_traverse.iterRaise if there are unused attributes
val collect : Ppxlib.Ast_traverse.iterCollect all attribute names. To be used in conjuction with
check_all_seen.
val check_all_seen : Ppxlib__.Import.unit -> Ppxlib__.Import.unitCheck that all attributes collected by
freshen_and_collecthave been:- matched at least once by one of:
get,consumeorFloating.convert - seen by
check_unused(to allow white-listed attributed to pass through)
This helps with faulty ppx rewriters that silently drop attributes.
- matched at least once by one of:
val mark_as_handled_manually : Ppxlib__.Import.attribute -> Ppxlib__.Import.unitMark an attribute as seen and handled. This is only to make ppx rewriters that don't use ppxlib works well with the ones that do use it.
val dropped_so_far_structure : Ppxlib__.Import.structure -> Ppxlib__.Import.string Ppxlib.Loc.t Ppxlib__.Import.listReturn the list of attributes that have been dropped so far: attributes that haven't been marked and are not present in the given AST. This is used to debug extensions that drop attributes.
val dropped_so_far_signature : Ppxlib__.Import.signature -> Ppxlib__.Import.string Ppxlib.Loc.t Ppxlib__.Import.listval reset_checks : Ppxlib__.Import.unit -> Ppxlib__.Import.unitval pattern : ('a, 'b) t -> ('a, 'c, 'd) Ppxlib.Ast_pattern.t -> ('a, 'b Ppxlib__.Import.option -> 'c, 'd) Ppxlib.Ast_pattern.t