Ast\_iterator(3) OCaml library Ast\_iterator(3)

# [NAME](#NAME)

Ast\_iterator - Ast\_iterator.iterator enables AST inspection using open recursion.

# [Module](#Module)

Module Ast\_iterator

# [Documentation](#Documentation)

Module **Ast\_iterator**  
: **sig end**

**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](#A_generic_Parsetree_iterator)

*type iterator* = {  
attribute : **iterator -&gt; Parsetree.attribute -&gt; unit** ;  
attributes : **iterator -&gt; Parsetree.attribute list -&gt; unit** ;  
binding\_op : **iterator -&gt; Parsetree.binding\_op -&gt; unit** ;  
case : **iterator -&gt; Parsetree.case -&gt; unit** ;  
cases : **iterator -&gt; Parsetree.case list -&gt; unit** ;  
class\_declaration : **iterator -&gt; Parsetree.class\_declaration -&gt; unit** ;  
class\_description : **iterator -&gt; Parsetree.class\_description -&gt; unit** ;  
class\_expr : **iterator -&gt; Parsetree.class\_expr -&gt; unit** ;  
class\_field : **iterator -&gt; Parsetree.class\_field -&gt; unit** ;  
class\_signature : **iterator -&gt; Parsetree.class\_signature -&gt; unit** ;  
class\_structure : **iterator -&gt; Parsetree.class\_structure -&gt; unit** ;  
class\_type : **iterator -&gt; Parsetree.class\_type -&gt; unit** ;  
class\_type\_declaration : **iterator -&gt; Parsetree.class\_type\_declaration -&gt; unit** ;  
class\_type\_field : **iterator -&gt; Parsetree.class\_type\_field -&gt; unit** ;  
constructor\_declaration : **iterator -&gt; Parsetree.constructor\_declaration -&gt; unit** ;  
directive\_argument : **iterator -&gt; Parsetree.directive\_argument -&gt; unit** ;  
expr : **iterator -&gt; Parsetree.expression -&gt; unit** ;  
extension : **iterator -&gt; Parsetree.extension -&gt; unit** ;  
extension\_constructor : **iterator -&gt; Parsetree.extension\_constructor -&gt; unit** ;  
include\_declaration : **iterator -&gt; Parsetree.include\_declaration -&gt; unit** ;  
include\_description : **iterator -&gt; Parsetree.include\_description -&gt; unit** ;  
label\_declaration : **iterator -&gt; Parsetree.label\_declaration -&gt; unit** ;  
location : **iterator -&gt; Location.t -&gt; unit** ;  
module\_binding : **iterator -&gt; Parsetree.module\_binding -&gt; unit** ;  
module\_declaration : **iterator -&gt; Parsetree.module\_declaration -&gt; unit** ;  
module\_substitution : **iterator -&gt; Parsetree.module\_substitution -&gt; unit** ;  
module\_expr : **iterator -&gt; Parsetree.module\_expr -&gt; unit** ;  
module\_type : **iterator -&gt; Parsetree.module\_type -&gt; unit** ;  
module\_type\_declaration : **iterator -&gt; Parsetree.module\_type\_declaration -&gt; unit** ;  
open\_declaration : **iterator -&gt; Parsetree.open\_declaration -&gt; unit** ;  
open\_description : **iterator -&gt; Parsetree.open\_description -&gt; unit** ;  
package\_type : **iterator -&gt; Parsetree.package\_type -&gt; unit** ;  
pat : **iterator -&gt; Parsetree.pattern -&gt; unit** ;  
payload : **iterator -&gt; Parsetree.payload -&gt; unit** ;  
signature : **iterator -&gt; Parsetree.signature -&gt; unit** ;  
signature\_item : **iterator -&gt; Parsetree.signature\_item -&gt; unit** ;  
structure : **iterator -&gt; Parsetree.structure -&gt; unit** ;  
structure\_item : **iterator -&gt; Parsetree.structure\_item -&gt; unit** ;  
toplevel\_directive : **iterator -&gt; Parsetree.toplevel\_directive -&gt; unit** ;  
toplevel\_phrase : **iterator -&gt; Parsetree.toplevel\_phrase -&gt; unit** ;  
typ : **iterator -&gt; Parsetree.core\_type -&gt; unit** ;  
row\_field : **iterator -&gt; Parsetree.row\_field -&gt; unit** ;  
object\_field : **iterator -&gt; Parsetree.object\_field -&gt; unit** ;  
type\_declaration : **iterator -&gt; Parsetree.type\_declaration -&gt; unit** ;  
type\_extension : **iterator -&gt; Parsetree.type\_extension -&gt; unit** ;  
type\_exception : **iterator -&gt; Parsetree.type\_exception -&gt; unit** ;  
type\_kind : **iterator -&gt; Parsetree.type\_kind -&gt; unit** ;  
value\_binding : **iterator -&gt; Parsetree.value\_binding -&gt; unit** ;  
value\_description : **iterator -&gt; Parsetree.value\_description -&gt; unit** ;  
with\_constraint : **iterator -&gt; Parsetree.with\_constraint -&gt; 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.

2026-09-04 OCamldoc

---

Document: Ast_iterator(3o) from ocaml 5.5.1-r0 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
