Refactored ast structure

This commit is contained in:
2026-05-16 23:04:05 +02:00
parent b802c51369
commit 95f253c0ce
5 changed files with 298 additions and 282 deletions
+65
View File
@@ -0,0 +1,65 @@
use serde::Serialize;
use super::*;
#[derive(Debug, Clone, Serialize, Default)]
pub struct Block(pub Vec<Statement>);
#[derive(Debug, Clone, Serialize)]
pub enum Statement {
Expression(Expression),
Block(Block),
VarDecl(VarDeclStmt),
Assign {
target: Expression,
value: Expression,
},
CompoundAssign {
target: Expression,
compound: String,
value: Expression,
},
If {
initial: StatementBranch,
else_if: Vec<StatementBranch>,
else_branch: Option<Box<Statement>>,
},
While(StatementBranch),
CStyleFor {
init: Box<Statement>,
condition: Expression,
update: Box<Statement>,
body: Box<Statement>,
},
For {
mutable: bool,
pattern: Pattern,
iterator: Expression,
body: Box<Statement>,
},
Match(Expression, Vec<(Pattern, Block)>),
Return(Option<Expression>),
Break,
Continue,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarDecl {
pub mutable: bool,
pub name: Pattern,
pub type_: Option<TypeExpr>,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarDeclStmt {
pub decl: VarDecl,
pub init: Option<Expression>,
}
#[derive(Debug, Clone, Serialize)]
pub struct StatementBranch {
pub condition: Expression,
pub body: Box<Statement>,
}