Skip to content

Commit bc8da53

Browse files
committed
---
yaml --- r: 22581 b: refs/heads/master c: f4ef0dc h: refs/heads/master i: 22579: e0a228e v: v3
1 parent 79d3670 commit bc8da53

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: db020ab63cd51dd4a25cba2d00117f016128762b
2+
refs/heads/master: f4ef0dc3d344bd704258ac4d395709f012b41bde
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/libsyntax/ext/base.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,43 @@ fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
244244
}
245245
}
246246

247+
fn tt_args_to_original_flavor(cx: ext_ctxt, sp: span, arg: ~[ast::token_tree])
248+
-> ast::mac_arg {
249+
import ast::{matcher, matcher_, mtc_tok, mtc_rep, mtc_bb};
250+
import parse::lexer::{new_tt_reader, tt_reader_as_reader, reader};
251+
import tt::earley_parser::{parse_or_else, seq, leaf};
252+
253+
// these spans won't matter, anyways
254+
fn ms(m: matcher_) -> matcher {
255+
{node: m, span: {lo: 0u, hi: 0u, expn_info: none}}
256+
}
257+
258+
let argument_gram = ~[ms(mtc_rep(~[
259+
ms(mtc_bb(@"arg",@"expr", 0u))
260+
], some(parse::token::COMMA), true))];
261+
262+
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
263+
cx.parse_sess().interner, none, arg);
264+
let args =
265+
alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
266+
argument_gram).get(@"arg") {
267+
@seq(s, _) {
268+
do s.map() |lf| {
269+
alt lf {
270+
@leaf(parse::token::w_expr(arg)) {
271+
arg /* whew! list of exprs, here we come! */
272+
}
273+
_ { fail "badly-structured parse result"; }
274+
}
275+
}
276+
}
277+
_ { fail "badly-structured parse result"; }
278+
};
279+
280+
ret some(@{id: parse::next_node_id(cx.parse_sess()),
281+
node: ast::expr_vec(args, ast::m_imm), span: sp});
282+
}
283+
247284
//
248285
// Local Variables:
249286
// mode: rust

trunk/src/libsyntax/ext/expand.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,20 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
8181
cx.bt_pop();
8282

8383
(fully_expanded, s)
84+
}
85+
some(normal({expander: exp, span: exp_sp})) {
86+
//convert the new-style invoc for the old-style macro
87+
let arg = base::tt_args_to_original_flavor(cx, pth.span,
88+
tts);
89+
let expanded = exp(cx, mac.span, arg, none);
8490

91+
cx.bt_push(expanded_from({call_site: s,
92+
callie: {name: *extname, span: exp_sp}}));
93+
//keep going, outside-in
94+
let fully_expanded = fld.fold_expr(expanded).node;
95+
cx.bt_pop();
96+
97+
(fully_expanded, s)
8598
}
8699
_ {
87100
cx.span_fatal(pth.span,

trunk/src/libsyntax/ext/tt/earley_parser.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ enum parse_result {
101101
failure(codemap::span, ~str)
102102
}
103103
104+
fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
105+
ms: ~[matcher]) -> hashmap<ident, @arb_depth> {
106+
alt parse(sess, cfg, rdr, ms) {
107+
success(m) { m }
108+
failure(sp, str) {
109+
sess.span_diagnostic.span_fatal(sp, str);
110+
}
111+
}
112+
}
113+
104114
fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
105115
-> parse_result {
106116
let mut cur_eis = ~[];

0 commit comments

Comments
 (0)