use crate::Expression;
use crate::Span;
#[derive(Clone, Debug)]
pub struct Block {
pub statements: Vec<Statement>,
pub return_statement: Option<ReturnStatement>,
pub span: Span,
}
impl Block {
pub fn new(
statements: Vec<Statement>,
return_statement: Option<ReturnStatement>,
span: Span,
) -> Self {
Self {
statements,
return_statement,
span,
}
}
pub fn span(&self) -> Span {
self.span
}
}
#[derive(Clone, Debug)]
pub struct ReturnStatement {
pub values: Vec<Expression>,
pub span: Span,
}
impl ReturnStatement {
pub fn new(values: Vec<Expression>, span: Span) -> Self {
Self { values, span }
}
pub fn span(&self) -> Span {
self.span
}
}
#[non_exhaustive]
#[derive(Clone, Debug)]
pub enum Statement {
None(StmtNone),
Assignment(StmtAssignment),
Label(StmtLabel),
Break(StmtBreak),
Goto(StmtGoto),
Do(StmtDo),
While(StmtWhile),
Repeat(StmtRepeat),
If(StmtIf),
For(StmtFor),
ForGeneric(StmtForGeneric),
LocalDeclaration(StmtLocalDeclaration),
FunctionDefinition(StmtFunctionDefinition),
FunctionDefinitionLocal(StmtFunctionDefinitionLocal),
FunctionCall(StmtFunctionCall),
}
impl Statement {
pub fn span(&self) -> Span {
match self {
Self::None(v) => v.span(),
Self::Assignment(v) => v.span(),
Self::Label(v) => v.span(),
Self::Break(v) => v.span(),
Self::Goto(v) => v.span(),
Self::Do(v) => v.span(),
Self::While(v) => v.span(),
Self::Repeat(v) => v.span(),
Self::If(v) => v.span(),
Self::For(v) => v.span(),
Self::ForGeneric(v) => v.span(),
Self::LocalDeclaration(v) => v.span(),
Self::FunctionDefinition(v) => v.span(),
Self::FunctionDefinitionLocal(v) => v.span(),
Self::FunctionCall(v) => v.span(),
}
}
}
#[derive(Clone, Debug)]
pub struct StmtNone {
pub span: Span,
}
impl StmtNone {
pub fn new(span: Span) -> Self {
Self { span }
}
pub fn span(&self) -> Span {
self.span
}
}
mod assignment;
pub use assignment::StmtAssignment;
mod break_;
pub use break_::StmtBreak;
mod label;
pub use label::StmtLabel;
mod goto_;
pub use goto_::StmtGoto;
mod do_;
pub use do_::StmtDo;
mod while_;
pub use while_::StmtWhile;
mod repeat;
pub use repeat::StmtRepeat;
mod if_;
pub use if_::StmtElseIf;
pub use if_::StmtIf;
mod for_;
pub use for_::StmtFor;
pub use for_::StmtForGeneric;
mod localdecl;
pub use localdecl::AttName;
pub use localdecl::Attrib;
pub use localdecl::StmtLocalDeclaration;
mod functiondef;
pub use functiondef::FunctionName;
pub use functiondef::StmtFunctionDefinition;
pub use functiondef::StmtFunctionDefinitionLocal;
mod functioncall;
pub use functioncall::StmtFunctionCall;