#[derive(Debug, Clone)]
pub struct Template {
pub nodes: Vec<Node>,
}
#[derive(Debug, Clone)]
pub enum Node {
RawText(String),
Comment(String),
ExprTag(ExprTag),
IfBlock(IfBlock),
EachBlock(EachBlock),
SnippetBlock(SnippetBlock),
RawBlock(String),
RenderTag(RenderTag),
ConstTag(ConstTag),
IncludeTag(IncludeTag),
DebugTag(DebugTag),
}
#[derive(Debug, Clone)]
pub struct ExprTag {
pub expr: Expr,
pub raw: bool,
}
#[derive(Debug, Clone)]
pub struct IfBlock {
pub branches: Vec<IfBranch>,
pub else_body: Option<Vec<Node>>,
}
#[derive(Debug, Clone)]
pub struct IfBranch {
pub condition: Expr,
pub body: Vec<Node>,
}
#[derive(Debug, Clone)]
pub struct EachBlock {
pub iterable: Expr,
pub pattern: Pattern,
pub index_binding: Option<String>,
pub loop_binding: Option<String>,
pub body: Vec<Node>,
pub else_body: Option<Vec<Node>>,
}
#[derive(Debug, Clone)]
pub struct SnippetBlock {
pub name: String,
pub params: Vec<String>,
pub body: Vec<Node>,
}
#[derive(Debug, Clone)]
pub struct RenderTag {
pub name: String,
pub args: Vec<Expr>,
}
#[derive(Debug, Clone)]
pub struct ConstTag {
pub name: String,
pub expr: Expr,
}
#[derive(Debug, Clone)]
pub struct IncludeTag {
pub path: String,
}
#[derive(Debug, Clone)]
pub struct DebugTag {
pub expr: Option<Expr>,
}
#[derive(Debug, Clone)]
pub enum Pattern {
Ident(String),
Destructure(Vec<String>),
}
#[derive(Debug, Clone)]
pub enum Expr {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Array(Vec<Expr>),
Ident(String),
MemberAccess {
object: Box<Expr>,
property: String,
},
IndexAccess {
object: Box<Expr>,
index: Box<Expr>,
},
Filter {
expr: Box<Expr>,
filters: Vec<FilterApplication>,
},
Ternary {
condition: Box<Expr>,
consequent: Box<Expr>,
alternate: Box<Expr>,
},
Binary {
op: BinaryOp,
left: Box<Expr>,
right: Box<Expr>,
},
Unary {
op: UnaryOp,
operand: Box<Expr>,
},
Test {
expr: Box<Expr>,
negated: bool,
test_name: String,
},
Membership {
expr: Box<Expr>,
negated: bool,
collection: Box<Expr>,
},
}
#[derive(Debug, Clone)]
pub struct FilterApplication {
pub name: String,
pub args: Vec<Expr>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BinaryOp {
NullCoalesce, Or, And, Eq, Neq, Lt, Gt, Lte, Gte, Add, Sub, Mul, Div, Mod, }
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UnaryOp {
Not, Neg, }