use crate::{AstPath, Box, BoxSlice, DocComments, Lit, StrLit};
use solar_interface::{Ident, Span};
#[derive(Debug)]
pub struct Block<'ast> {
pub span: Span,
pub stmts: BoxSlice<'ast, Stmt<'ast>>,
}
impl<'ast> std::ops::Deref for Block<'ast> {
type Target = [Stmt<'ast>];
fn deref(&self) -> &Self::Target {
self.stmts
}
}
impl<'ast> std::ops::DerefMut for Block<'ast> {
fn deref_mut(&mut self) -> &mut Self::Target {
self.stmts
}
}
#[derive(Debug)]
pub struct Object<'ast> {
pub docs: DocComments<'ast>,
pub span: Span,
pub name: StrLit,
pub code: CodeBlock<'ast>,
pub children: BoxSlice<'ast, Self>,
pub data: BoxSlice<'ast, Data<'ast>>,
}
#[derive(Debug)]
pub struct CodeBlock<'ast> {
pub span: Span,
pub code: Block<'ast>,
}
#[derive(Debug)]
pub struct Data<'ast> {
pub span: Span,
pub name: StrLit,
pub data: Lit<'ast>,
}
#[derive(Debug)]
pub struct Stmt<'ast> {
pub docs: DocComments<'ast>,
pub span: Span,
pub kind: StmtKind<'ast>,
}
#[derive(Debug)]
pub enum StmtKind<'ast> {
Block(Block<'ast>),
AssignSingle(AstPath<'ast>, Expr<'ast>),
AssignMulti(BoxSlice<'ast, AstPath<'ast>>, Expr<'ast>),
Expr(Expr<'ast>),
If(Expr<'ast>, Block<'ast>),
For(Box<'ast, StmtFor<'ast>>),
Switch(StmtSwitch<'ast>),
Leave,
Break,
Continue,
FunctionDef(Function<'ast>),
VarDecl(BoxSlice<'ast, Ident>, Option<Expr<'ast>>),
}
#[derive(Debug)]
pub struct StmtFor<'ast> {
pub init: Block<'ast>,
pub cond: Expr<'ast>,
pub step: Block<'ast>,
pub body: Block<'ast>,
}
#[derive(Debug)]
pub struct StmtSwitch<'ast> {
pub selector: Expr<'ast>,
pub cases: BoxSlice<'ast, StmtSwitchCase<'ast>>,
}
impl<'ast> StmtSwitch<'ast> {
pub fn default_case(&self) -> Option<&StmtSwitchCase<'ast>> {
self.cases.last().filter(|case| case.constant.is_none())
}
}
#[derive(Debug)]
pub struct StmtSwitchCase<'ast> {
pub span: Span,
pub constant: Option<Lit<'ast>>,
pub body: Block<'ast>,
}
#[derive(Debug)]
pub struct Function<'ast> {
pub name: Ident,
pub parameters: BoxSlice<'ast, Ident>,
pub returns: BoxSlice<'ast, Ident>,
pub body: Block<'ast>,
}
#[derive(Debug)]
pub struct Expr<'ast> {
pub span: Span,
pub kind: ExprKind<'ast>,
}
#[derive(Debug)]
pub enum ExprKind<'ast> {
Path(AstPath<'ast>),
Call(ExprCall<'ast>),
Lit(Box<'ast, Lit<'ast>>),
}
#[derive(Debug)]
pub struct ExprCall<'ast> {
pub name: Ident,
pub arguments: BoxSlice<'ast, Expr<'ast>>,
}