package ocaml-base-compiler

  1. Overview
  2. Docs

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

A generic Parsetree iterator

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

OCaml

Innovation. Community. Security.