conlang: Add unconditional loop expression, for desugaring
This commit is contained in:
@@ -103,6 +103,7 @@ pub enum Parsing {
|
||||
Block,
|
||||
Group,
|
||||
Tuple,
|
||||
Loop,
|
||||
While,
|
||||
If,
|
||||
For,
|
||||
@@ -204,6 +205,7 @@ impl Display for Parsing {
|
||||
Parsing::Block => "a block",
|
||||
Parsing::Group => "a grouped expression",
|
||||
Parsing::Tuple => "a tuple",
|
||||
Parsing::Loop => "an unconditional loop expression",
|
||||
Parsing::While => "a while expression",
|
||||
Parsing::If => "an if expression",
|
||||
Parsing::For => "a for expression",
|
||||
|
||||
@@ -809,6 +809,7 @@ impl<'t> Parser<'t> {
|
||||
self.consume_peeked();
|
||||
Unary { kind, tail: self.exprkind(after)?.into() }.into()
|
||||
}
|
||||
TokenKind::Loop => ExprKind::Loop(self.parse_loop()?),
|
||||
TokenKind::While => ExprKind::While(self.parse_while()?),
|
||||
TokenKind::If => ExprKind::If(self.parse_if()?),
|
||||
TokenKind::For => ExprKind::For(self.parse_for()?),
|
||||
@@ -1010,6 +1011,12 @@ impl<'t> Parser<'t> {
|
||||
}
|
||||
/// ## Control flow subexpressions
|
||||
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]?
|
||||
pub fn parse_while(&mut self) -> PResult<While> {
|
||||
self.match_type(TokenKind::While, Parsing::While)?;
|
||||
|
||||
Reference in New Issue
Block a user