use std::rc::Rc;
use syn::*;
use tour_core::Delimiter;
use crate::syntax::*;
pub enum StmtTempl {
Scalar(Scalar),
Scope(Scope),
}
pub enum Scalar {
Static {
value: Rc<str>,
index: u32,
},
Use(UseTempl),
Render(RenderTempl),
Yield(YieldTempl),
Item(Rc<ItemTempl>),
Expr {
expr: Rc<Expr>,
delim: Delimiter,
},
}
pub enum Scope {
Root { stmts: Vec<StmtTempl> },
If {
templ: IfTempl,
stmts: Vec<StmtTempl>,
else_branch: Option<(Token![else],Box<Scope>)>
},
For {
templ: ForTempl,
stmts: Vec<StmtTempl>,
else_branch: Option<(Token![else],Box<Scope>)>
},
Block {
templ: BlockTempl,
stmts: Vec<StmtTempl>,
},
}
impl Scope {
pub(crate) fn stack_mut(&mut self) -> &mut Vec<StmtTempl> {
match self {
Self::Root { stmts } => stmts,
Self::Block { stmts, .. } => stmts,
Self::For { else_branch: Some(branch), .. } => branch.1.stack_mut(),
Self::For { stmts, .. } => stmts,
Self::If { else_branch: Some(branch), .. } => branch.1.stack_mut(),
Self::If { stmts, .. } => stmts,
}
}
}