diff --git a/cl-ast/src/ast_impl.rs b/cl-ast/src/ast_impl.rs index 91ffafa..832aaa4 100644 --- a/cl-ast/src/ast_impl.rs +++ b/cl-ast/src/ast_impl.rs @@ -666,6 +666,7 @@ mod convert { Block => ExprKind::Block, Group => ExprKind::Group, Tuple => ExprKind::Tuple, + Loop => ExprKind::Loop, While => ExprKind::While, If => ExprKind::If, For => ExprKind::For, diff --git a/cl-ast/src/lib.rs b/cl-ast/src/lib.rs index 91ac61c..e74e026 100644 --- a/cl-ast/src/lib.rs +++ b/cl-ast/src/lib.rs @@ -497,7 +497,7 @@ pub struct Tuple { /// A [Loop] expression: `loop` [`Block`] #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct Loop { - pub body: Block, + pub body: Box, } /// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]? diff --git a/cl-parser/src/parser.rs b/cl-parser/src/parser.rs index 8fde066..e0aa23c 100644 --- a/cl-parser/src/parser.rs +++ b/cl-parser/src/parser.rs @@ -809,7 +809,10 @@ impl<'t> Parser<'t> { self.consume_peeked(); Unary { kind, tail: self.exprkind(after)?.into() }.into() } - TokenKind::Loop => ExprKind::Loop(self.parse_loop()?), + TokenKind::Loop => { + self.consume_peeked(); + Loop { body: self.expr()?.into() }.into() + } TokenKind::While => ExprKind::While(self.parse_while()?), TokenKind::If => ExprKind::If(self.parse_if()?), TokenKind::For => ExprKind::For(self.parse_for()?), @@ -1011,12 +1014,6 @@ impl<'t> Parser<'t> { } /// ## Control flow subexpressions impl<'t> Parser<'t> { - /// [Loop] = `loop` [Block] - pub fn parse_loop(&mut self) -> PResult { - self.match_type(TokenKind::Loop, Parsing::Loop)?; - Ok(Loop { body: self.block()? }) - } - /// [While] = `while` [Expr] [Block] [Else]? pub fn parse_while(&mut self) -> PResult { self.match_type(TokenKind::While, Parsing::While)?;