rust/src/libsyntax/ext/trace_macros.rs

28 lines
982 B
Rust
Raw Normal View History

2012-08-15 12:45:10 -05:00
import codemap::span;
import ext::base::ext_ctxt;
import ast::tt_delim;
import parse::lexer::{new_tt_reader, reader};
import parse::parser::{parser, SOURCE_FILE};
import parse::common::parser_common;
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;
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
2012-07-18 18:18:02 -05:00
let arg = cx.str_of(rust_parser.parse_ident());
2012-08-15 12:45:10 -05:00
match arg {
2012-07-18 18:18:02 -05:00
~"true" => cx.set_trace_macros(true),
~"false" => cx.set_trace_macros(false),
2012-08-15 12:45:10 -05:00
_ => cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`")
}
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let result = rust_parser.parse_expr();
base::mr_expr(result)
}