1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Nicolas Ojeda Bar, LexiFi *)
6 (* *)
7 (* Copyright 2012 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (** {!iterator} enables AST inspection using open recursion. A
17 typical mapper would be based on {!default_iterator}, a trivial iterator,
18 and will fall back on it for handling the syntax it does not modify.
19
20 {b Warning:} this module is unstable and part of
21 {{!Compiler_libs}compiler-libs}.
22
23 *)
24
25 open Parsetree
26
27 (** {1 A generic Parsetree iterator} *)
28
29 type iterator = {
30 attribute: iterator -> attribute -> unit;
31 attributes: iterator -> attribute list -> unit;
32 binding_op: iterator -> binding_op -> unit;
33 case: iterator -> case -> unit;
34 cases: iterator -> case list -> unit;
35 class_declaration: iterator -> class_declaration -> unit;
36 class_description: iterator -> class_description -> unit;
37 class_expr: iterator -> class_expr -> unit;
38 class_field: iterator -> class_field -> unit;
39 class_signature: iterator -> class_signature -> unit;
40 class_structure: iterator -> class_structure -> unit;
41 class_type: iterator -> class_type -> unit;
42 class_type_declaration: iterator -> class_type_declaration -> unit;
43 class_type_field: iterator -> class_type_field -> unit;
44 constructor_declaration: iterator -> constructor_declaration -> unit;
45 expr: iterator -> expression -> unit;
46 extension: iterator -> extension -> unit;
47 extension_constructor: iterator -> extension_constructor -> unit;
48 include_declaration: iterator -> include_declaration -> unit;
49 include_description: iterator -> include_description -> unit;
50 label_declaration: iterator -> label_declaration -> unit;
51 location: iterator -> Location.t -> unit;
52 module_binding: iterator -> module_binding -> unit;
53 module_declaration: iterator -> module_declaration -> unit;
54 module_substitution: iterator -> module_substitution -> unit;
55 module_expr: iterator -> module_expr -> unit;
56 module_type: iterator -> module_type -> unit;
57 module_type_declaration: iterator -> module_type_declaration -> unit;
58 open_declaration: iterator -> open_declaration -> unit;
59 open_description: iterator -> open_description -> unit;
60 pat: iterator -> pattern -> unit;
61 payload: iterator -> payload -> unit;
62 signature: iterator -> signature -> unit;
63 signature_item: iterator -> signature_item -> unit;
64 structure: iterator -> structure -> unit;
65 structure_item: iterator -> structure_item -> unit;
66 typ: iterator -> core_type -> unit;
67 row_field: iterator -> row_field -> unit;
68 object_field: iterator -> object_field -> unit;
69 type_declaration: iterator -> type_declaration -> unit;
70 type_extension: iterator -> type_extension -> unit;
71 type_exception: iterator -> type_exception -> unit;
72 type_kind: iterator -> type_kind -> unit;
73 value_binding: iterator -> value_binding -> unit;
74 value_description: iterator -> value_description -> unit;
75 with_constraint: iterator -> with_constraint -> unit;
76 }
77 (** A [iterator] record implements one "method" per syntactic category,
78 using an open recursion style: each method takes as its first
79 argument the iterator to be applied to children in the syntax
80 tree. *)
81
82 val default_iterator: iterator
83 (** A default iterator, which implements a "do not do anything" mapping. *)
84