Skip to content

Commit b7c0512

Browse files
committed
refactor so tt_fold only requires an ident->ident fn
1 parent 93337f0 commit b7c0512

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/libsyntax/fold.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,35 +118,37 @@ fn fold_mac_(m: &mac, fld: @ast_fold) -> mac {
118118
node: match m.node {
119119
mac_invoc_tt(ref p,ref tts) =>
120120
mac_invoc_tt(fld.fold_path(p),
121-
fold_tts(*tts,fld))
121+
fold_tts(*tts,|id|{fld.fold_ident(id)}))
122122
},
123123
span: fld.new_span(m.span)
124124
}
125125
}
126126

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] {
128130
do tts.map |tt| {
129131
match *tt {
130132
tt_tok(span, ref tok) =>
131-
tt_tok(span,maybe_fold_ident(tok,fld)),
133+
tt_tok(span,maybe_fold_ident(tok,f)),
132134
tt_delim(ref tts) =>
133-
tt_delim(@mut fold_tts(**tts, fld)),
135+
tt_delim(@mut fold_tts(**tts, f)),
134136
tt_seq(span, ref pattern, ref sep, is_optional) =>
135137
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)),
138140
is_optional),
139141
tt_nonterminal(sp,ref ident) =>
140-
tt_nonterminal(sp,fld.fold_ident(*ident))
142+
tt_nonterminal(sp,f(*ident))
141143
}
142144
}
143145
}
144146

145147
// 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 {
147149
match *t {
148150
token::IDENT(id,followed_by_colons) =>
149-
token::IDENT(fld.fold_ident(id),followed_by_colons),
151+
token::IDENT(f(id),followed_by_colons),
150152
_ => (*t).clone()
151153
}
152154
}

0 commit comments

Comments
 (0)