1use std::rc::Rc;
3use syn::*;
4use tour_core::Delimiter;
5
6use crate::syntax::*;
7
8pub enum StmtTempl {
10 Scalar(Scalar),
12 Scope(Scope),
14}
15
16pub enum Scalar {
17 Static {
19 value: Rc<str>,
20 index: u32,
21 },
22 Use(UseTempl),
24 Render(RenderTempl),
26 Yield(YieldTempl),
28 Item(Rc<ItemTempl>),
30 Expr {
32 expr: Rc<Expr>,
33 delim: Delimiter,
34 },
35}
36
37pub enum Scope {
39 Root { stmts: Vec<StmtTempl> },
41 If {
43 templ: IfTempl,
44 stmts: Vec<StmtTempl>,
45 else_branch: Option<(Token![else],Box<Scope>)>
46 },
47 For {
49 templ: ForTempl,
50 stmts: Vec<StmtTempl>,
51 else_branch: Option<(Token![else],Box<Scope>)>
52 },
53 Block {
55 templ: BlockTempl,
56 stmts: Vec<StmtTempl>,
57 },
58}
59
60impl Scope {
61 pub(crate) fn stack_mut(&mut self) -> &mut Vec<StmtTempl> {
62 match self {
63 Self::Root { stmts } => stmts,
64 Self::Block { stmts, .. } => stmts,
65 Self::For { else_branch: Some(branch), .. } => branch.1.stack_mut(),
66 Self::For { stmts, .. } => stmts,
67 Self::If { else_branch: Some(branch), .. } => branch.1.stack_mut(),
68 Self::If { stmts, .. } => stmts,
69 }
70 }
71}
72