Skip to content

Bugfix for macros that call macros and for trace_macro! #4045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,14 @@ fn core_macros() -> ~str {
return
~"{
macro_rules! ignore (($($x:tt)*) => (()))
#macro[[#error[f, ...], log(core::error, #fmt[f, ...])]];
#macro[[#warn[f, ...], log(core::warn, #fmt[f, ...])]];
#macro[[#info[f, ...], log(core::info, #fmt[f, ...])]];
#macro[[#debug[f, ...], log(core::debug, #fmt[f, ...])]];
macro_rules! error ( ($( $arg:expr ),+) => (
log(core::error, fmt!( $($arg),+ )) ))
macro_rules! warn ( ($( $arg:expr ),+) => (
log(core::warn, fmt!( $($arg),+ )) ))
macro_rules! info ( ($( $arg:expr ),+) => (
log(core::info, fmt!( $($arg),+ )) ))
macro_rules! debug ( ($( $arg:expr ),+) => (
log(core::debug, fmt!( $($arg),+ )) ))
}";
}

Expand Down
14 changes: 9 additions & 5 deletions src/libsyntax/ext/trace_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ fn expand_trace_macros(cx: ext_ctxt, sp: span,
let rdr = tt_rdr as reader;
let rust_parser = Parser(sess, cfg, rdr.dup());

let arg = cx.str_of(rust_parser.parse_ident());
match arg {
~"true" => cx.set_trace_macros(true),
~"false" => cx.set_trace_macros(false),
_ => cx.span_fatal(sp, ~"trace_macros! only accepts `true` or `false`")
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`")
}

rust_parser.bump();

let rust_parser = Parser(sess, cfg, rdr.dup());
let result = rust_parser.parse_expr();
base::mr_expr(result)
Expand Down
6 changes: 1 addition & 5 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,7 @@ fn parse(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader, ms: ~[matcher])
}
cur_eis.push(move ei);

/* this would fail if zero-length tokens existed */
while rdr.peek().sp.lo < rust_parser.span.lo {
rdr.next_token();
} /* except for EOF... */
while rust_parser.token == EOF && rdr.peek().tok != EOF {
for rust_parser.tokens_consumed.times() || {
rdr.next_token();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ fn Parser(sess: parse_sess, cfg: ast::crate_cfg,
buffer: [mut {tok: tok0.tok, sp: span0}, ..4],
buffer_start: 0,
buffer_end: 0,
tokens_consumed: 0u,
restriction: UNRESTRICTED,
quote_depth: 0u,
keywords: token::keyword_table(),
Expand All @@ -210,6 +211,7 @@ struct Parser {
mut buffer: [mut {tok: token::Token, sp: span} * 4],
mut buffer_start: int,
mut buffer_end: int,
mut tokens_consumed: uint,
mut restriction: restriction,
mut quote_depth: uint, // not (yet) related to the quasiquoter
reader: reader,
Expand All @@ -236,6 +238,7 @@ impl Parser {
};
self.token = next.tok;
self.span = next.sp;
self.tokens_consumed += 1u;
}
fn swap(next: token::Token, +lo: BytePos, +hi: BytePos) {
self.token = next;
Expand Down