statement body parsing

This commit is contained in:
2026-05-24 12:55:33 +02:00
parent 6551aee03b
commit f4fe38140a
3 changed files with 48 additions and 11 deletions
+20 -5
View File
@@ -8,27 +8,33 @@ pub struct Block(
pub Option<Spanned<Expression>>,
);
#[derive(Debug, Clone, Serialize)]
pub enum StatementBody {
Statement(Box<Statement>),
Expression(Expression),
}
#[derive(Debug, Clone, Serialize)]
pub enum Statement {
Block(Block),
If {
initial: StatementBranch,
else_if: Vec<StatementBranch>,
else_branch: Option<Expression>,
else_branch: Option<StatementBody>,
},
Loop(Expression),
Loop(StatementBody),
While(StatementBranch),
CStyleFor {
init: Expression,
condition: Expression,
update: Expression,
body: Expression,
body: StatementBody,
},
For {
mutable: bool,
pattern: Pattern,
iterator: Expression,
body: Expression,
body: StatementBody,
},
Match(Expression, Vec<(Vec<Pattern>, Expression)>),
@@ -54,7 +60,7 @@ pub struct VarDeclStmt {
#[derive(Debug, Clone, Serialize)]
pub struct StatementBranch {
pub condition: Expression,
pub body: Box<Expression>,
pub body: Box<StatementBody>,
}
impl Statement {
@@ -84,3 +90,12 @@ impl Statement {
}
}
}
impl StatementBody {
pub fn is_block(&self) -> bool {
match self {
Self::Expression(_) => false,
_ => true,
}
}
}