From 028eeb1664026b8149b2cc906eb5eaf4063e3eb8 Mon Sep 17 00:00:00 2001 From: Paul Stansifer Date: Mon, 26 Nov 2012 22:34:01 -0500 Subject: [PATCH] Properly sync macro_parser.rs after it escapes out to the Rust parser. Closes #3201. --- src/libsyntax/ext/expand.rs | 12 ++++++++---- src/libsyntax/ext/tt/macro_parser.rs | 6 +----- src/libsyntax/parse/parser.rs | 3 +++ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 443a937d4eb7a..f07706bf7497d 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -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),+ )) )) }"; } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 86218acb5a196..13d9e87f26e26 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -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(); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 925934d165f68..0b1f3b3ae3035 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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(), @@ -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, @@ -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;