@@ -118,35 +118,37 @@ fn fold_mac_(m: &mac, fld: @ast_fold) -> mac {
118
118
node : match m. node {
119
119
mac_invoc_tt( ref p, ref tts) =>
120
120
mac_invoc_tt ( fld. fold_path ( p) ,
121
- fold_tts ( * tts, fld) )
121
+ fold_tts ( * tts, |id| { fld. fold_ident ( id ) } ) )
122
122
} ,
123
123
span : fld. new_span ( m. span )
124
124
}
125
125
}
126
126
127
- fn fold_tts ( tts : & [ token_tree ] , fld : @ast_fold ) -> ~[ token_tree ] {
127
+ // build a new vector of tts by appling the given function to
128
+ // all of the identifiers in the token trees.
129
+ pub fn fold_tts ( tts : & [ token_tree ] , f : @fn ( ident ) ->ident ) -> ~[ token_tree ] {
128
130
do tts. map |tt| {
129
131
match * tt {
130
132
tt_tok( span, ref tok) =>
131
- tt_tok ( span, maybe_fold_ident ( tok, fld ) ) ,
133
+ tt_tok ( span, maybe_fold_ident ( tok, f ) ) ,
132
134
tt_delim( ref tts) =>
133
- tt_delim ( @mut fold_tts ( * * tts, fld ) ) ,
135
+ tt_delim ( @mut fold_tts ( * * tts, f ) ) ,
134
136
tt_seq( span, ref pattern, ref sep, is_optional) =>
135
137
tt_seq ( span,
136
- @mut fold_tts ( * * pattern, fld ) ,
137
- sep. map ( |tok|maybe_fold_ident ( tok, fld ) ) ,
138
+ @mut fold_tts ( * * pattern, f ) ,
139
+ sep. map ( |tok|maybe_fold_ident ( tok, f ) ) ,
138
140
is_optional) ,
139
141
tt_nonterminal( sp, ref ident) =>
140
- tt_nonterminal ( sp, fld . fold_ident ( * ident) )
142
+ tt_nonterminal ( sp, f ( * ident) )
141
143
}
142
144
}
143
145
}
144
146
145
147
// apply ident folder if it's an ident, otherwise leave it alone
146
- fn maybe_fold_ident ( t : & token:: Token , fld : @ast_fold ) -> token:: Token {
148
+ fn maybe_fold_ident ( t : & token:: Token , f : @fn ( ident ) -> ident ) -> token:: Token {
147
149
match * t {
148
150
token:: IDENT ( id, followed_by_colons) =>
149
- token:: IDENT ( fld . fold_ident ( id) , followed_by_colons) ,
151
+ token:: IDENT ( f ( id) , followed_by_colons) ,
150
152
_ => ( * t) . clone ( )
151
153
}
152
154
}
0 commit comments