cl-ast: Change loop expression to take any expression as its argument, for later desugaring.
This commit is contained in:
parent
00d72b823a
commit
02b775259e
@ -666,6 +666,7 @@ mod convert {
|
|||||||
Block => ExprKind::Block,
|
Block => ExprKind::Block,
|
||||||
Group => ExprKind::Group,
|
Group => ExprKind::Group,
|
||||||
Tuple => ExprKind::Tuple,
|
Tuple => ExprKind::Tuple,
|
||||||
|
Loop => ExprKind::Loop,
|
||||||
While => ExprKind::While,
|
While => ExprKind::While,
|
||||||
If => ExprKind::If,
|
If => ExprKind::If,
|
||||||
For => ExprKind::For,
|
For => ExprKind::For,
|
||||||
|
@ -497,7 +497,7 @@ pub struct Tuple {
|
|||||||
/// A [Loop] expression: `loop` [`Block`]
|
/// A [Loop] expression: `loop` [`Block`]
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct Loop {
|
pub struct Loop {
|
||||||
pub body: Block,
|
pub body: Box<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||||
|
@ -809,7 +809,10 @@ impl<'t> Parser<'t> {
|
|||||||
self.consume_peeked();
|
self.consume_peeked();
|
||||||
Unary { kind, tail: self.exprkind(after)?.into() }.into()
|
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::While => ExprKind::While(self.parse_while()?),
|
||||||
TokenKind::If => ExprKind::If(self.parse_if()?),
|
TokenKind::If => ExprKind::If(self.parse_if()?),
|
||||||
TokenKind::For => ExprKind::For(self.parse_for()?),
|
TokenKind::For => ExprKind::For(self.parse_for()?),
|
||||||
@ -1011,12 +1014,6 @@ impl<'t> Parser<'t> {
|
|||||||
}
|
}
|
||||||
/// ## Control flow subexpressions
|
/// ## Control flow subexpressions
|
||||||
impl<'t> Parser<'t> {
|
impl<'t> Parser<'t> {
|
||||||
/// [Loop] = `loop` [Block]
|
|
||||||
pub fn parse_loop(&mut self) -> PResult<Loop> {
|
|
||||||
self.match_type(TokenKind::Loop, Parsing::Loop)?;
|
|
||||||
Ok(Loop { body: self.block()? })
|
|
||||||
}
|
|
||||||
|
|
||||||
/// [While] = `while` [Expr] [Block] [Else]?
|
/// [While] = `while` [Expr] [Block] [Else]?
|
||||||
pub fn parse_while(&mut self) -> PResult<While> {
|
pub fn parse_while(&mut self) -> PResult<While> {
|
||||||
self.match_type(TokenKind::While, Parsing::While)?;
|
self.match_type(TokenKind::While, Parsing::While)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user