diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-01-28 21:01:05 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-01-28 21:01:36 +0100 |
| commit | 9c906f92c50d453822b12896d29b7883802ea567 (patch) | |
| tree | 78e2465a4fa805bbddc80407b7eea585b5ebb60c /src/parse | |
| parent | 3a07603b66fab6b343b34156f4a3a6015e2d69e1 (diff) | |
Parse `break`, `continue` and `return` expression
Diffstat (limited to 'src/parse')
| -rw-r--r-- | src/parse/incremental.rs | 5 | ||||
| -rw-r--r-- | src/parse/mod.rs | 30 |
2 files changed, 34 insertions, 1 deletions
diff --git a/src/parse/incremental.rs b/src/parse/incremental.rs index 2edb84ba..9dd5bec1 100644 --- a/src/parse/incremental.rs +++ b/src/parse/incremental.rs @@ -548,7 +548,10 @@ impl NodeKind { | Self::ShowExpr | Self::WrapExpr | Self::ImportExpr - | Self::IncludeExpr => SuccessionRule::AtomicPrimary, + | Self::IncludeExpr + | Self::BreakExpr + | Self::ContinueExpr + | Self::ReturnExpr => SuccessionRule::AtomicPrimary, // This element always has to remain in the same column so better // reparse the whole parent. diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 67e35a5a..a9839ed6 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -405,6 +405,9 @@ fn primary(p: &mut Parser, atomic: bool) -> ParseResult { Some(NodeKind::For) => for_expr(p), Some(NodeKind::Import) => import_expr(p), Some(NodeKind::Include) => include_expr(p), + Some(NodeKind::Break) => break_expr(p), + Some(NodeKind::Continue) => continue_expr(p), + Some(NodeKind::Return) => return_expr(p), Some(NodeKind::Error(_, _)) => { p.eat(); @@ -833,6 +836,33 @@ fn include_expr(p: &mut Parser) -> ParseResult { }) } +/// Parse a break expression. +fn break_expr(p: &mut Parser) -> ParseResult { + p.perform(NodeKind::BreakExpr, |p| { + p.eat_assert(&NodeKind::Break); + Ok(()) + }) +} + +/// Parse a continue expression. +fn continue_expr(p: &mut Parser) -> ParseResult { + p.perform(NodeKind::ContinueExpr, |p| { + p.eat_assert(&NodeKind::Continue); + Ok(()) + }) +} + +/// Parse a return expression. +fn return_expr(p: &mut Parser) -> ParseResult { + p.perform(NodeKind::ReturnExpr, |p| { + p.eat_assert(&NodeKind::Return); + if !p.eof() { + expr(p)?; + } + Ok(()) + }) +} + /// Parse an identifier. fn ident(p: &mut Parser) -> ParseResult { match p.peek() { |
