diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-28 20:17:30 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-28 20:17:30 +0100 |
| commit | 3a07603b66fab6b343b34156f4a3a6015e2d69e1 (patch) | |
| tree | 8abfbc80d3d5ceaf8921f64e7b358afe85a63421 /src/parse | |
| parent | 76b1d4a93f6d045901f17db46d82a97c9f407703 (diff) | |
Remove unnecessary group
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/mod.rs | 27 | ||||
| -rw-r--r-- | src/parse/parser.rs | 10 |
2 files changed, 17 insertions, 20 deletions
diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 72d38b46..67e35a5a 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -276,24 +276,25 @@ fn enum_node(p: &mut Parser, at_start: bool) { /// Parse an expression within markup mode. fn markup_expr(p: &mut Parser) { - if let Some(token) = p.peek() { - let stmt = matches!( - token, + // Does the expression need termination or can content follow directly? + let stmt = matches!( + p.peek(), + Some( NodeKind::Let | NodeKind::Set | NodeKind::Show | NodeKind::Wrap | NodeKind::Import - ); - let group = if stmt { Group::Stmt } else { Group::Expr }; - - p.start_group(group); - let res = expr_prec(p, true, 0); - if stmt && res.is_ok() && !p.eof() { - p.expected_at("semicolon or line break"); - } - p.end_group(); + | NodeKind::Include + ) + ); + + p.start_group(Group::Expr); + let res = expr_prec(p, true, 0); + if stmt && res.is_ok() && !p.eof() { + p.expected_at("semicolon or line break"); } + p.end_group(); } /// Parse an expression. @@ -626,7 +627,7 @@ fn block(p: &mut Parser) { p.perform(NodeKind::Block, |p| { p.start_group(Group::Brace); while !p.eof() { - p.start_group(Group::Stmt); + p.start_group(Group::Expr); if expr(p).is_ok() && !p.eof() { p.expected_at("semicolon or line break"); } diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 4e5b277d..0184c198 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -248,7 +248,6 @@ impl<'s> Parser<'s> { Group::Paren => self.eat_assert(&NodeKind::LeftParen), Group::Bracket => self.eat_assert(&NodeKind::LeftBracket), Group::Brace => self.eat_assert(&NodeKind::LeftBrace), - Group::Stmt => {} Group::Expr => {} Group::Imports => {} } @@ -274,8 +273,7 @@ impl<'s> Parser<'s> { Group::Paren => Some((NodeKind::RightParen, true)), Group::Bracket => Some((NodeKind::RightBracket, true)), Group::Brace => Some((NodeKind::RightBrace, true)), - Group::Stmt => Some((NodeKind::Semicolon, false)), - Group::Expr => None, + Group::Expr => Some((NodeKind::Semicolon, false)), Group::Imports => None, } { if self.current.as_ref() == Some(&end) { @@ -324,7 +322,7 @@ impl<'s> Parser<'s> { Some(NodeKind::RightParen) => self.inside(Group::Paren), Some(NodeKind::RightBracket) => self.inside(Group::Bracket), Some(NodeKind::RightBrace) => self.inside(Group::Brace), - Some(NodeKind::Semicolon) => self.inside(Group::Stmt), + Some(NodeKind::Semicolon) => self.inside(Group::Expr), Some(NodeKind::From) => self.inside(Group::Imports), Some(NodeKind::Space(n)) => *n >= 1 && self.stop_at_newline(), Some(_) => false, @@ -352,7 +350,7 @@ impl<'s> Parser<'s> { fn stop_at_newline(&self) -> bool { matches!( self.groups.last().map(|group| group.kind), - Some(Group::Stmt | Group::Expr | Group::Imports) + Some(Group::Expr | Group::Imports) ) } @@ -488,8 +486,6 @@ pub enum Group { /// A parenthesized group: `(...)`. Paren, /// A group ended by a semicolon or a line break: `;`, `\n`. - Stmt, - /// A group for a single expression, ended by a line break. Expr, /// A group for import items, ended by a semicolon, line break or `from`. Imports, |
