Module Ast_iterator

Ast_iterator.iterator enables AST inspection using open recursion. A typical mapper would be based on Ast_iterator.default_iterator, a trivial iterator, and will fall back on it for handling the syntax it does not modify.

Warning: this module is unstable and part of compiler-libs.

A generic Parsetree iterator

type iterator = {
  1. attribute : iterator -> Parsetree.attribute -> unit;
  2. attributes : iterator -> Parsetree.attribute list -> unit;
  3. binding_op : iterator -> Parsetree.binding_op -> unit;
  4. case : iterator -> Parsetree.case -> unit;
  5. cases : iterator -> Parsetree.case list -> unit;
  6. class_declaration : iterator -> Parsetree.class_declaration -> unit;
  7. class_description : iterator -> Parsetree.class_description -> unit;
  8. class_expr : iterator -> Parsetree.class_expr -> unit;
  9. class_field : iterator -> Parsetree.class_field -> unit;
  10. class_signature : iterator -> Parsetree.class_signature -> unit;
  11. class_structure : iterator -> Parsetree.class_structure -> unit;
  12. class_type : iterator -> Parsetree.class_type -> unit;
  13. class_type_declaration : iterator -> Parsetree.class_type_declaration -> unit;
  14. class_type_field : iterator -> Parsetree.class_type_field -> unit;
  15. constructor_declaration : iterator -> Parsetree.constructor_declaration -> unit;
  16. expr : iterator -> Parsetree.expression -> unit;
  17. extension : iterator -> Parsetree.extension -> unit;
  18. extension_constructor : iterator -> Parsetree.extension_constructor -> unit;
  19. include_declaration : iterator -> Parsetree.include_declaration -> unit;
  20. include_description : iterator -> Parsetree.include_description -> unit;
  21. label_declaration : iterator -> Parsetree.label_declaration -> unit;
  22. location : iterator -> Location.t -> unit;
  23. module_binding : iterator -> Parsetree.module_binding -> unit;
  24. module_declaration : iterator -> Parsetree.module_declaration -> unit;
  25. module_substitution : iterator -> Parsetree.module_substitution -> unit;
  26. module_expr : iterator -> Parsetree.module_expr -> unit;
  27. module_type : iterator -> Parsetree.module_type -> unit;
  28. module_type_declaration : iterator -> Parsetree.module_type_declaration -> unit;
  29. open_declaration : iterator -> Parsetree.open_declaration -> unit;
  30. open_description : iterator -> Parsetree.open_description -> unit;
  31. pat : iterator -> Parsetree.pattern -> unit;
  32. payload : iterator -> Parsetree.payload -> unit;
  33. signature : iterator -> Parsetree.signature -> unit;
  34. signature_item : iterator -> Parsetree.signature_item -> unit;
  35. structure : iterator -> Parsetree.structure -> unit;
  36. structure_item : iterator -> Parsetree.structure_item -> unit;
  37. typ : iterator -> Parsetree.core_type -> unit;
  38. row_field : iterator -> Parsetree.row_field -> unit;
  39. object_field : iterator -> Parsetree.object_field -> unit;
  40. type_declaration : iterator -> Parsetree.type_declaration -> unit;
  41. type_extension : iterator -> Parsetree.type_extension -> unit;
  42. type_exception : iterator -> Parsetree.type_exception -> unit;
  43. type_kind : iterator -> Parsetree.type_kind -> unit;
  44. value_binding : iterator -> Parsetree.value_binding -> unit;
  45. value_description : iterator -> Parsetree.value_description -> unit;
  46. with_constraint : iterator -> Parsetree.with_constraint -> unit;
}

A iterator record implements one "method" per syntactic category, using an open recursion style: each method takes as its first argument the iterator to be applied to children in the syntax tree.

val default_iterator : iterator

A default iterator, which implements a "do not do anything" mapping.