diff options
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 6732aa40..13c639f9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -231,6 +231,12 @@ pub enum Expr { Import(ImportExpr), /// An include expression: `include "chapter1.typ"`. Include(IncludeExpr), + /// A break expression: `break`. + Break(BreakExpr), + /// A continue expression: `continue`. + Continue(ContinueExpr), + /// A return expression: `return`. + Return(ReturnExpr), } impl TypedNode for Expr { @@ -256,6 +262,9 @@ impl TypedNode for Expr { NodeKind::ForExpr => node.cast().map(Self::For), NodeKind::ImportExpr => node.cast().map(Self::Import), NodeKind::IncludeExpr => node.cast().map(Self::Include), + NodeKind::BreakExpr => node.cast().map(Self::Break), + NodeKind::ContinueExpr => node.cast().map(Self::Continue), + NodeKind::ReturnExpr => node.cast().map(Self::Return), _ => node.cast().map(Self::Lit), } } @@ -283,6 +292,9 @@ impl TypedNode for Expr { Self::For(v) => v.as_red(), Self::Import(v) => v.as_red(), Self::Include(v) => v.as_red(), + Self::Break(v) => v.as_red(), + Self::Continue(v) => v.as_red(), + Self::Return(v) => v.as_red(), } } } @@ -1042,6 +1054,28 @@ impl IncludeExpr { } node! { + /// A break expression: `break`. + BreakExpr +} + +node! { + /// A continue expression: `continue`. + ContinueExpr +} + +node! { + /// A return expression: `return x + 1`. + ReturnExpr +} + +impl ReturnExpr { + /// The expression to return. + pub fn body(&self) -> Option<Expr> { + self.0.cast_last_child() + } +} + +node! { /// An identifier. Ident: NodeKind::Ident(_) } |
