if, while, scopes

This commit is contained in:
2025-05-30 17:31:20 +02:00
parent da1102714a
commit f72e8a4149
4 changed files with 103 additions and 32 deletions

View File

@@ -15,7 +15,7 @@ pub enum Stmt {
If {
condition: Expr,
then_branch: Box<Stmt>,
else_branch: Option<Box<Stmt>>,
else_branch: Box<Stmt>,
},
While {
condition: Expr,
@@ -111,12 +111,12 @@ impl Parser {
let then_branch = self.block()?;
let else_branch = if self.match_token(&[TokenType::KeywordElse]) {
if self.match_token(&[TokenType::KeywordIf]) {
Some(Box::new(self.if_statement()?))
Box::new(self.if_statement()?)
} else {
Some(Box::new(self.block()?))
Box::new(self.block()?)
}
} else {
None
Box::new(Stmt::Block(vec![]))
};
Ok(Stmt::If {
condition,