From 8e07b23b84bff16c0decc6f2b80c27862eac6df1 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Tue, 16 Mar 2021 13:44:50 +0800 Subject: Fix macro expansion for statements w/o semicolon --- crates/parser/src/grammar.rs | 6 +++--- crates/parser/src/grammar/expressions.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/parser') diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 6c0e22722..cebb8f400 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -63,11 +63,11 @@ pub(crate) mod fragments { } pub(crate) fn stmt(p: &mut Parser) { - expressions::stmt(p, expressions::StmtWithSemi::No) + expressions::stmt(p, expressions::StmtWithSemi::No, true) } pub(crate) fn stmt_optional_semi(p: &mut Parser) { - expressions::stmt(p, expressions::StmtWithSemi::Optional) + expressions::stmt(p, expressions::StmtWithSemi::Optional, false) } pub(crate) fn opt_visibility(p: &mut Parser) { @@ -133,7 +133,7 @@ pub(crate) mod fragments { continue; } - expressions::stmt(p, expressions::StmtWithSemi::Optional); + expressions::stmt(p, expressions::StmtWithSemi::Optional, true); } m.complete(p, MACRO_STMTS); diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index 5f885edfd..0d9dc9348 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -54,7 +54,7 @@ fn is_expr_stmt_attr_allowed(kind: SyntaxKind) -> bool { !forbid } -pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) { +pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi, prefer_expr: bool) { let m = p.start(); // test attr_on_expr_stmt // fn foo() { @@ -90,7 +90,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) { p.error(format!("attributes are not allowed on {:?}", kind)); } - if p.at(T!['}']) { + if p.at(T!['}']) || (prefer_expr && p.at(EOF)) { // test attr_on_last_expr_in_block // fn foo() { // { #[A] bar!()? } @@ -198,7 +198,7 @@ pub(super) fn expr_block_contents(p: &mut Parser) { continue; } - stmt(p, StmtWithSemi::Yes) + stmt(p, StmtWithSemi::Yes, false) } } -- cgit v1.2.3