@@ -18,7 +18,8 @@ import codemap::span;
18
18
19
19
type aq_ctxt = @{ lo : uint ,
20
20
mutable gather: [ { lo : uint , hi : uint ,
21
- e : @ast:: expr , constr : str } ] } ;
21
+ e : @ast:: expr ,
22
+ constr : str } ] } ;
22
23
enum fragment {
23
24
from_expr( @ast:: expr ) ,
24
25
from_ty( @ast:: ty )
@@ -29,6 +30,7 @@ iface qq_helper {
29
30
fn visit ( aq_ctxt , vt < aq_ctxt > ) ;
30
31
fn extract_mac ( ) -> option < ast:: mac_ > ;
31
32
fn mk_parse_fn ( ext_ctxt , span ) -> @ast:: expr ;
33
+ fn get_fold_fn ( ) -> str ;
32
34
}
33
35
impl of qq_helper for @ast:: expr {
34
36
fn span ( ) -> span { self . span }
@@ -42,6 +44,7 @@ impl of qq_helper for @ast::expr {
42
44
fn mk_parse_fn ( cx : ext_ctxt , sp : span ) -> @ast:: expr {
43
45
mk_path ( cx, sp, [ "syntax" , "parse" , "parser" , "parse_expr" ] )
44
46
}
47
+ fn get_fold_fn ( ) -> str { "fold_expr" }
45
48
}
46
49
impl of qq_helper for @ast:: ty {
47
50
fn span ( ) -> span { self . span }
@@ -55,6 +58,7 @@ impl of qq_helper for @ast::ty {
55
58
fn mk_parse_fn ( cx : ext_ctxt , sp : span ) -> @ast:: expr {
56
59
mk_path ( cx, sp, [ "syntax" , "ext" , "qquote" , "parse_ty" ] )
57
60
}
61
+ fn get_fold_fn ( ) -> str { "fold_ty" }
58
62
}
59
63
impl of qq_helper for @ast:: item {
60
64
fn span ( ) -> span { self . span }
@@ -63,6 +67,7 @@ impl of qq_helper for @ast::item {
63
67
fn mk_parse_fn ( cx : ext_ctxt , sp : span ) -> @ast:: expr {
64
68
mk_path ( cx, sp, [ "syntax" , "ext" , "qquote" , "parse_item" ] )
65
69
}
70
+ fn get_fold_fn ( ) -> str { "fold_item" }
66
71
}
67
72
impl of qq_helper for @ast:: stmt {
68
73
fn span ( ) -> span { self . span }
@@ -71,6 +76,7 @@ impl of qq_helper for @ast::stmt {
71
76
fn mk_parse_fn ( cx : ext_ctxt , sp : span ) -> @ast:: expr {
72
77
mk_path ( cx, sp, [ "syntax" , "ext" , "qquote" , "parse_stmt" ] )
73
78
}
79
+ fn get_fold_fn ( ) -> str { "fold_stmt" }
74
80
}
75
81
impl of qq_helper for @ast:: pat {
76
82
fn span ( ) -> span { self . span }
@@ -79,6 +85,7 @@ impl of qq_helper for @ast::pat {
79
85
fn mk_parse_fn ( cx : ext_ctxt , sp : span ) -> @ast:: expr {
80
86
mk_path ( cx, sp, [ "syntax" , "parse" , "parser" , "parse_pat" ] )
81
87
}
88
+ fn get_fold_fn ( ) -> str { "fold_pat" }
82
89
}
83
90
84
91
fn gather_anti_quotes < N : qq_helper > ( lo : uint , node : N ) -> aq_ctxt
@@ -244,23 +251,30 @@ fn expand_qquote<N: qq_helper>
244
251
mk_vec_e ( cx, sp, vec:: map ( qcx. gather ) { |g|
245
252
mk_call ( cx, sp,
246
253
[ "syntax" , "ext" , "qquote" , g. constr ] ,
247
- [ g. e ] )
248
- } ) ] ) ;
254
+ [ g. e ] ) } ) ,
255
+ mk_path ( cx, sp,
256
+ [ "syntax" , "ext" , "qquote" ,
257
+ node. get_fold_fn ( ) ] ) ] ) ;
249
258
}
250
-
251
259
ret rcall;
252
260
}
253
261
254
- fn replace ( e : @ast:: expr , repls : [ fragment ] ) -> @ast:: expr {
262
+ fn replace < T > ( node : T , repls : [ fragment ] , ff : fn ( ast_fold , T ) -> T )
263
+ -> T
264
+ {
255
265
let aft = default_ast_fold ( ) ;
256
266
let f_pre = { fold_expr: bind replace_expr ( repls, _, _, _,
257
267
aft. fold_expr ) ,
258
268
fold_ty: bind replace_ty ( repls, _, _, _,
259
269
aft. fold_ty )
260
270
with * aft} ;
261
- let f = make_fold ( f_pre) ;
262
- ret f. fold_expr ( e) ;
271
+ ret ff( make_fold ( f_pre) , node) ;
263
272
}
273
+ fn fold_expr ( f : ast_fold , & & n: @ast:: expr ) -> @ast:: expr { f. fold_expr ( n) }
274
+ fn fold_ty ( f : ast_fold , & & n: @ast:: ty ) -> @ast:: ty { f. fold_ty ( n) }
275
+ fn fold_item ( f : ast_fold , & & n: @ast:: item ) -> @ast:: item { f. fold_item ( n) }
276
+ fn fold_stmt ( f : ast_fold , & & n: @ast:: stmt ) -> @ast:: stmt { f. fold_stmt ( n) }
277
+ fn fold_pat ( f : ast_fold , & & n: @ast:: pat ) -> @ast:: pat { f. fold_pat ( n) }
264
278
265
279
fn replace_expr ( repls : [ fragment ] ,
266
280
e : ast:: expr_ , s : span , fld : ast_fold ,
0 commit comments