2012-12-04 00:48:01 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 22:28:44 +00:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2012-12-23 22:41:37 +00:00
|
|
|
use ast;
|
2012-09-04 18:37:29 +00:00
|
|
|
use codemap::span;
|
2013-05-17 11:27:17 +00:00
|
|
|
use ext::base::ExtCtxt;
|
2013-01-09 03:37:25 +00:00
|
|
|
use ext::base;
|
2012-09-04 18:37:29 +00:00
|
|
|
use parse::lexer::{new_tt_reader, reader};
|
2012-11-18 23:55:03 +00:00
|
|
|
use parse::parser::Parser;
|
2012-08-15 17:45:10 +00:00
|
|
|
|
2013-05-17 11:27:17 +00:00
|
|
|
pub fn expand_trace_macros(cx: @ExtCtxt,
|
2013-03-12 20:00:50 +00:00
|
|
|
sp: span,
|
|
|
|
tt: &[ast::token_tree])
|
|
|
|
-> base::MacResult {
|
2012-08-15 17:45:10 +00:00
|
|
|
let sess = cx.parse_sess();
|
|
|
|
let cfg = cx.cfg();
|
2013-02-19 05:25:44 +00:00
|
|
|
let tt_rdr = new_tt_reader(
|
|
|
|
copy cx.parse_sess().span_diagnostic,
|
|
|
|
cx.parse_sess().interner,
|
|
|
|
None,
|
2013-05-10 09:38:54 +00:00
|
|
|
vec::to_owned(tt)
|
2013-02-19 05:25:44 +00:00
|
|
|
);
|
2013-03-12 20:00:50 +00:00
|
|
|
let rdr = tt_rdr as @reader;
|
2013-02-27 04:18:01 +00:00
|
|
|
let rust_parser = Parser(
|
|
|
|
sess,
|
|
|
|
copy cfg,
|
|
|
|
rdr.dup()
|
|
|
|
);
|
2012-08-15 17:45:10 +00:00
|
|
|
|
2013-05-11 15:42:59 +00:00
|
|
|
if rust_parser.is_keyword("true") {
|
2012-11-27 03:12:31 +00:00
|
|
|
cx.set_trace_macros(true);
|
2013-05-11 15:42:59 +00:00
|
|
|
} else if rust_parser.is_keyword("false") {
|
2012-11-27 03:12:31 +00:00
|
|
|
cx.set_trace_macros(false);
|
|
|
|
} else {
|
2013-05-19 05:07:44 +00:00
|
|
|
cx.span_fatal(sp, "trace_macros! only accepts `true` or `false`")
|
2012-08-15 17:45:10 +00:00
|
|
|
}
|
2012-11-27 03:12:31 +00:00
|
|
|
|
|
|
|
rust_parser.bump();
|
|
|
|
|
2012-11-18 23:55:03 +00:00
|
|
|
let rust_parser = Parser(sess, cfg, rdr.dup());
|
2012-08-15 17:45:10 +00:00
|
|
|
let result = rust_parser.parse_expr();
|
2013-01-23 00:45:27 +00:00
|
|
|
base::MRExpr(result)
|
2012-08-15 17:45:10 +00:00
|
|
|
}
|