Legend:
Library
Module
Module type
Parameter
Class
Class type
Helpers for build OCaml AST fragments
This module is similar to the Ast_helper module distrubuted with OCaml but uses different conventions.
Locations
Ast_helper uses a global variable for the default locations, we found that to it makes it quite easy to mess up locations. Instead this modules forces you to provide a location argument.
For building fragment using the same location everywhere, a functor is provided.
Naming
The names match the Parsetree names closely, which makes it easy to build AST fragments by just knowing the Parsetree.
For types of the form a wrapper record with a _desc field, helpers are generated for each constructor constructing the record directly. For instance for the type Parsetree.expression:
type expression =
{ pexp_desc : expression_desc
; pexp_loc : Location.t
; pexp_attributes : attributes
}
and expression_desc =
| Pexp_ident of Longident.t loc
| Pexp_constant of constant
| Pexp_let of rec_flag * value_binding list * expression
...
The following helpers are created:
val pexp_ident : loc:Location.t -> Longident.t Located.t -> expression
val pexp_constant : loc:Location.t -> constant -> expression
val pexp_let : loc:Location.t -> rec_flag -> value_binding list -> expression
...
For other record types, such as type_declaration, we have the following helper:
Attributes are always set to the empty list. If you want to set them you have to override the field with the { e with pexp_attributes = ... } notation.