Parse macro-expanded statements like ordinary statements.

This commit is contained in:
Jeffrey Seyfried 2016-07-02 09:32:23 +00:00
parent 6189e6cdba
commit 57c56dd7e0
2 changed files with 9 additions and 3 deletions

View File

@ -118,12 +118,18 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
fn make_stmts(self: Box<ParserAnyMacro<'a>>)
-> Option<SmallVector<ast::Stmt>> {
let parse_stmt = |parser: &mut Parser<'a>| -> ::parse::PResult<'a, _> {
Ok(match parser.parse_stmt()? {
Some(stmt) => Some(parser.finish_parsing_statement(stmt)?),
None => None,
})
};
let mut ret = SmallVector::zero();
loop {
let mut parser = self.parser.borrow_mut();
match parser.token {
token::Eof => break,
_ => match parser.parse_stmt() {
_ => match parse_stmt(&mut parser) {
Ok(maybe_stmt) => match maybe_stmt {
Some(stmt) => ret.push(stmt),
None => (),

View File

@ -4064,7 +4064,7 @@ impl<'a> Parser<'a> {
/// Finish parsing expressions that start with macros and handle trailing semicolons
/// (or the lack thereof) -- c.f. `parse_stmt`.
fn finish_parsing_statement(&mut self, mut stmt: Stmt) -> PResult<'a, Stmt> {
pub fn finish_parsing_statement(&mut self, mut stmt: Stmt) -> PResult<'a, Stmt> {
if let StmtKind::Mac(mac) = stmt.node {
if mac.1 != MacStmtStyle::NoBraces || self.token == token::Semi {
stmt.node = StmtKind::Mac(mac);
@ -4082,7 +4082,7 @@ impl<'a> Parser<'a> {
fn handle_trailing_semicolon(&mut self, mut stmt: Stmt) -> PResult<'a, Stmt> {
match stmt.node {
StmtKind::Expr(ref expr) => {
StmtKind::Expr(ref expr) if self.token != token::Eof => {
// expression without semicolon
if classify::expr_requires_semi_to_be_stmt(expr) {
// Just check for errors and recover; do not eat semicolon yet.