statement body parsing
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user