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
+40 -38
View File
@@ -56,53 +56,55 @@ pub enum Postfix {
#[derive(Debug, Clone, Serialize)]
pub enum Statement {
// expr;
Expression(Expression),
// { ... }
Block(Block),
// let/const/var x = ...
VarDecl {
mutable: bool,
name: String,
init: Option<Expression>,
type_: Option<TypeExpr>,
},
VarDecl(VarDeclStmt),
VarAssign(VarAssignStmt),
If(IfStmt),
While(WhileStmt),
For(ForStmt),
VarAssign {
target: Expression,
value: Expression,
},
// if (...) stmt else stmt
If {
condition: Expression,
then_branch: Box<Statement>,
else_branch: Option<Box<Statement>>,
},
// while (...) stmt
While {
condition: Expression,
body: Box<Statement>,
},
// for (...) stmt
For {
init: (bool, String, Option<Expression>),
condition: Option<Expression>,
update: Option<Box<Statement>>,
body: Box<Statement>,
},
// return expr?;
Return(Option<Expression>),
Break,
Continue,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarDeclStmt {
pub mutable: bool,
pub name: String,
pub init: Option<Expression>,
pub type_: Option<TypeExpr>,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarAssignStmt {
pub target: Expression,
pub value: Expression,
}
#[derive(Debug, Clone, Serialize)]
pub struct IfStmt {
pub condition: Expression,
pub then_branch: Box<Statement>,
pub else_branch: Option<Box<Statement>>,
}
#[derive(Debug, Clone, Serialize)]
pub struct WhileStmt {
pub condition: Expression,
pub body: Box<Statement>,
}
#[derive(Debug, Clone, Serialize)]
pub struct ForStmt {
pub init: (bool, String, Option<Expression>),
pub condition: Option<Expression>,
pub update: Option<Box<Statement>>,
pub body: Box<Statement>,
}
#[derive(Debug, Clone, Serialize)]
pub enum Expression {
Identifier(String),