use super::expr::Expr;
use super::item::{Ident, Item};
use super::ty::Type;
#[derive(Debug, Clone, PartialEq)]
pub struct Block<'de> {
pub stmts: Vec<Stmt<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Stmt<'de> {
Local(StmtLocal<'de>),
Item(Item<'de>),
Expr(StmtExpr<'de>),
Return(StmtReturn<'de>),
Break(StmtBreak<'de>),
Continue(StmtContinue<'de>),
Goto(StmtGoto<'de>),
Label(StmtLabel<'de>),
If(StmtIf<'de>),
While(StmtWhile<'de>),
DoWhile(StmtDoWhile<'de>),
For(StmtFor<'de>),
ForRange(StmtForRange<'de>),
Switch(StmtSwitch<'de>),
Case(StmtCase<'de>),
Default(StmtDefault<'de>),
TryCatch(StmtTryCatch<'de>),
Block(Block<'de>),
Empty,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtLocal<'de> {
pub ty: Type<'de>,
pub ident: Ident<'de>,
pub init: Option<Expr<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtExpr<'de> {
pub expr: Expr<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtReturn<'de> {
pub expr: Option<Expr<'de>>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StmtBreak<'de> {
pub span: crate::SourceSpan<'de>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StmtContinue<'de> {
pub span: crate::SourceSpan<'de>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StmtGoto<'de> {
pub label: Ident<'de>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StmtLabel<'de> {
pub label: Ident<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtIf<'de> {
pub init: Option<Box<Stmt<'de>>>,
pub condition: Expr<'de>,
pub then_body: Box<Stmt<'de>>,
pub else_body: Option<Box<Stmt<'de>>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtWhile<'de> {
pub condition: Expr<'de>,
pub body: Box<Stmt<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtDoWhile<'de> {
pub body: Box<Stmt<'de>>,
pub condition: Expr<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtFor<'de> {
pub init: Option<Box<Stmt<'de>>>,
pub condition: Option<Expr<'de>>,
pub increment: Option<Expr<'de>>,
pub body: Box<Stmt<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtForRange<'de> {
pub ty: Type<'de>,
pub ident: Ident<'de>,
pub range: Expr<'de>,
pub body: Box<Stmt<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtSwitch<'de> {
pub expr: Expr<'de>,
pub body: Block<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtCase<'de> {
pub value: Expr<'de>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct StmtDefault<'de> {
pub span: crate::SourceSpan<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct StmtTryCatch<'de> {
pub try_body: Block<'de>,
pub catches: Vec<CatchClause<'de>>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct CatchClause<'de> {
pub param: CatchParam<'de>,
pub body: Block<'de>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CatchParam<'de> {
Typed {
ty: Type<'de>,
ident: Option<Ident<'de>>,
},
Ellipsis,
}