@@ -2,7 +2,7 @@ import driver::session;
2
2
3
3
import option :: { none, some} ;
4
4
5
- import syntax:: ast:: { crate, expr_, expr_mac, mac_invoc, mac_qq} ;
5
+ import syntax:: ast:: { crate, expr_, expr_mac, mac_invoc, mac_qq, mac_var } ;
6
6
import syntax:: fold:: * ;
7
7
import syntax:: ext:: base:: * ;
8
8
import syntax:: ext:: build:: * ;
@@ -29,6 +29,28 @@ fn expand_qquote(cx: ext_ctxt, sp: span, _e: @ast::expr) -> ast::expr_ {
29
29
ret call. node ;
30
30
}
31
31
32
+ fn replace ( e : @ast:: expr , repls : [ @ast:: expr ] ) -> @ast:: expr {
33
+ let aft = default_ast_fold ( ) ;
34
+ let f_pre = { fold_expr: bind replace_expr ( repls, _, _, _,
35
+ aft. fold_expr )
36
+ with * aft} ;
37
+ let f = make_fold ( f_pre) ;
38
+ ret f. fold_expr ( e) ;
39
+ }
40
+
41
+ fn replace_expr ( repls : [ @ast:: expr ] ,
42
+ e : ast:: expr_ , s : span , fld : ast_fold ,
43
+ orig : fn @( ast:: expr_ , span , ast_fold ) ->( ast:: expr_ , span ) )
44
+ -> ( ast:: expr_ , span )
45
+ {
46
+ // note: nested enum matching will be really nice here so I can jusy say
47
+ // expr_mac(mac_var(i))
48
+ alt e {
49
+ expr_mac( { node : mac_var ( i) , _} ) { let r = repls[ i] ; ( r. node , r. span ) }
50
+ _ { orig( e, s, fld) }
51
+ }
52
+ }
53
+
32
54
// Local Variables:
33
55
// mode: rust
34
56
// fill-column: 78;
0 commit comments