Ppxlib.Ast_traverseSourceAST traversal classes
To use these classes, inherit from them and override the methods corresponding to the types from Parsetree you want to process. For instance to collect all the string constants in a structure:
let string_constants_of =
object
inherit [string list] Ast_traverse.fold as super
method! expression e acc =
let acc = super#expression e acc in
match e.pexp_desc with
| Pexp_constant (Const_string (s, _)) -> s :: acc
| _ -> acc
method! pattern p acc =
let acc = super#pattern p acc in
match p.ppat_desc with
| Ppat_constant (Const_string (s, _)) -> s :: acc
| _ -> acc
end
let string_constants_of_structure = string_constants_of#structureval enter_value :
(Astlib.Ast_500.Parsetree.expression, string Astlib.Location.loc) Attribute.tval enter_module :
(Astlib.Ast_500.Parsetree.module_expr, string Astlib.Location.loc)
Attribute.tval do_not_enter_value_description :
(Astlib.Ast_500.Parsetree.value_description, unit) Attribute.tval do_not_enter_module_declaration :
(Astlib.Ast_500.Parsetree.module_declaration, unit) Attribute.tval do_not_enter_module_type_declaration :
(Astlib.Ast_500.Parsetree.module_type_declaration, unit) Attribute.t