class map :This class is the base class for map traversal on the Ast. To make a custom traversal class one just extend it like that:object..end
This example swap pairs expression contents:
open Camlp4.PreCast;
class swap = object
inherit Ast.map as super;
method expr e =
match super#expr e with
[ <:expr@_loc< ($e1$, $e2$) >> -> <:expr< ($e2$, $e1$) >>
| e -> e ];
end;
value _loc = Loc.ghost;
value map = (new swap)#expr;
assert (map <:expr< fun x -> (x, 42) >> = <:expr< fun x -> (42, x) >>);
method string : string -> stringmethod list : 'a 'b.
((< binding : binding -> binding;
class_expr : class_expr -> class_expr;
class_sig_item : class_sig_item ->
class_sig_item;
class_str_item : class_str_item ->
class_str_item;
class_type : class_type -> class_type;
ctyp : ctyp -> ctyp;
direction_flag : direction_flag ->
direction_flag;
expr : expr -> expr;
ident : ident -> ident; list : 'a 'b. 'c;
loc : loc -> loc;
match_case : match_case -> match_case;
meta_bool : meta_bool -> meta_bool;
meta_list : 'e 'f.
('d -> 'e -> 'f) ->
'e meta_list ->
'f meta_list;
meta_option : 'g 'h.
('d -> 'g -> 'h) ->
'g meta_option ->
'h meta_option;
module_binding : module_binding ->
module_binding;
module_expr : module_expr -> module_expr;
module_type : module_type -> module_type;
mutable_flag : mutable_flag ->
mutable_flag;
override_flag : override_flag ->
override_flag;
patt : patt -> patt;
private_flag : private_flag ->
private_flag;
rec_binding : rec_binding -> rec_binding;
rec_flag : rec_flag -> rec_flag;
row_var_flag : row_var_flag ->
row_var_flag;
sig_item : sig_item -> sig_item;
str_item : str_item -> str_item;
string : string -> string; unknown : 'i. 'i -> 'i;
virtual_flag : virtual_flag ->
virtual_flag;
with_constr : with_constr -> with_constr;
.. >
as 'd) ->
'a -> 'b) ->
'a list -> 'b list as 'cmethod meta_bool : meta_bool -> meta_boolmethod meta_option : 'g 'h.
('d -> 'g -> 'h) ->
'g meta_option -> 'h meta_optionmethod meta_list : 'e 'f.
('d -> 'e -> 'f) ->
'e meta_list -> 'f meta_listmethod loc : loc -> locmethod expr : expr -> exprmethod patt : patt -> pattmethod ctyp : ctyp -> ctypmethod str_item : str_item -> str_itemmethod sig_item : sig_item -> sig_itemmethod module_expr : module_expr -> module_exprmethod module_type : module_type -> module_typemethod class_expr : class_expr -> class_exprmethod class_type : class_type -> class_typemethod class_sig_item : class_sig_item -> class_sig_itemmethod class_str_item : class_str_item -> class_str_itemmethod with_constr : with_constr -> with_constrmethod binding : binding -> bindingmethod rec_binding : rec_binding -> rec_bindingmethod module_binding : module_binding -> module_bindingmethod match_case : match_case -> match_casemethod ident : ident -> identmethod override_flag : override_flag -> override_flagmethod mutable_flag : mutable_flag -> mutable_flagmethod private_flag : private_flag -> private_flagmethod virtual_flag : virtual_flag -> virtual_flagmethod direction_flag : direction_flag -> direction_flagmethod rec_flag : rec_flag -> rec_flagmethod row_var_flag : row_var_flag -> row_var_flagmethod unknown : 'i. 'i -> 'i