From 42da26e9597443812da5a59b3fa48bdcbf619666 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 17 Nov 2020 20:02:46 +0100 Subject: parser,syntax: Add separate parser for stmt with optional semicolon Adjusting `grammar::fragments::stmt` to Optional or Yes will break original functionality and tests. --- crates/parser/src/grammar.rs | 4 ++++ crates/parser/src/lib.rs | 2 ++ 2 files changed, 6 insertions(+) (limited to 'crates/parser') diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 63cc90027..bb9ffea8b 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -66,6 +66,10 @@ pub(crate) mod fragments { expressions::stmt(p, expressions::StmtWithSemi::No) } + pub(crate) fn stmt_optional_semi(p: &mut Parser) { + expressions::stmt(p, expressions::StmtWithSemi::Optional) + } + pub(crate) fn opt_visibility(p: &mut Parser) { let _ = super::opt_visibility(p); } diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 811e740f9..9dfe63028 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -88,6 +88,7 @@ pub enum FragmentKind { Path, Expr, Statement, + StatementOptionalSemi, Type, Pattern, Item, @@ -118,6 +119,7 @@ pub fn parse_fragment( FragmentKind::Visibility => grammar::fragments::opt_visibility, FragmentKind::MetaItem => grammar::fragments::meta_item, FragmentKind::Statement => grammar::fragments::stmt, + FragmentKind::StatementOptionalSemi => grammar::fragments::stmt_optional_semi, FragmentKind::Items => grammar::fragments::macro_items, FragmentKind::Statements => grammar::fragments::macro_stmts, FragmentKind::Attr => grammar::fragments::attr, -- cgit v1.2.3