refactored AST statements

This commit is contained in:
2026-05-02 17:16:16 +02:00
parent 2a753e8af8
commit aae71f1d0e
3 changed files with 56 additions and 51 deletions
+6 -6
View File
@@ -197,12 +197,12 @@ impl From<pest::iterators::Pair<'_, Rule>> for Statement {
let name = var_decl.next().unwrap().as_str().to_string();
let init = inner.next().map(Expression::from);
Statement::VarDecl {
Statement::VarDecl(VarDeclStmt {
mutable,
name: name.as_str().to_string(),
init,
type_,
}
})
}
Rule::return_stmt => {
@@ -225,11 +225,11 @@ impl From<pest::iterators::Pair<'_, Rule>> for Statement {
let else_branch = inner.next().map(Statement::from);
Statement::If {
Statement::If(IfStmt {
condition,
then_branch: Box::new(then_branch),
else_branch: else_branch.map(Box::new),
}
})
}
Rule::while_stmt => {
@@ -238,10 +238,10 @@ impl From<pest::iterators::Pair<'_, Rule>> for Statement {
let condition = Expression::from(inner.next().unwrap());
let body = Statement::from(inner.next().unwrap());
Statement::While {
Statement::While(WhileStmt {
condition,
body: Box::new(body),
}
})
}
_ => unimplemented!(