2012-09-04 13:37:29 -05:00
|
|
|
use codemap::span;
|
|
|
|
use ext::base::ext_ctxt;
|
|
|
|
use ast::tt_delim;
|
|
|
|
use parse::lexer::{new_tt_reader, reader};
|
2012-11-18 17:55:03 -06:00
|
|
|
use parse::parser::Parser;
|
2012-08-15 12:45:10 -05:00
|
|
|
|
|
|
|
fn expand_trace_macros(cx: ext_ctxt, sp: span,
|
|
|
|
tt: ~[ast::token_tree]) -> base::mac_result
|
|
|
|
{
|
|
|
|
let sess = cx.parse_sess();
|
|
|
|
let cfg = cx.cfg();
|
|
|
|
let tt_rdr = new_tt_reader(cx.parse_sess().span_diagnostic,
|
2012-08-20 14:23:37 -05:00
|
|
|
cx.parse_sess().interner, None, tt);
|
2012-08-15 12:45:10 -05:00
|
|
|
let rdr = tt_rdr as reader;
|
2012-11-18 17:55:03 -06:00
|
|
|
let rust_parser = Parser(sess, cfg, rdr.dup());
|
2012-08-15 12:45:10 -05:00
|
|
|
|
2012-11-26 21:12:31 -06:00
|
|
|
if rust_parser.is_keyword(~"true") {
|
|
|
|
cx.set_trace_macros(true);
|
|
|
|
} else if rust_parser.is_keyword(~"false") {
|
|
|
|
cx.set_trace_macros(false);
|
|
|
|
} else {
|
|
|
|
cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`")
|
2012-08-15 12:45:10 -05:00
|
|
|
}
|
2012-11-26 21:12:31 -06:00
|
|
|
|
|
|
|
rust_parser.bump();
|
|
|
|
|
2012-11-18 17:55:03 -06:00
|
|
|
let rust_parser = Parser(sess, cfg, rdr.dup());
|
2012-08-15 12:45:10 -05:00
|
|
|
let result = rust_parser.parse_expr();
|
|
|
|
base::mr_expr(result)
|
|
|
|
}
|