break and continue

This commit is contained in:
2025-07-02 13:56:30 +02:00
parent a0bee3f5ca
commit c53a7cd631
7 changed files with 48 additions and 16 deletions

View File

@@ -37,6 +37,8 @@ pub enum Stmt {
body: Box<Stmt>,
},
Return(Expr),
Break,
Continue,
}
#[derive(Debug, Clone)]
@@ -193,6 +195,10 @@ impl Parser {
self.for_statement()
} else if self.match_token(&[TokenType::KeywordReturn]) {
Ok(Stmt::Return(self.expression()?))
} else if self.match_token(&[TokenType::KeywordBreak]) {
Ok(Stmt::Break)
} else if self.match_token(&[TokenType::KeywordContinue]) {
Ok(Stmt::Continue)
} else {
Ok(Stmt::Expression(self.expression()?))
}