pub enum Node {
Show 19 variants
Root(Vec<Node>),
Text(Arc<str>),
Output(Vec<Expr>),
If {
branches: Vec<IfBranch>,
},
For {
vars: ForVars,
iter: Expr,
body: Vec<Node>,
else_body: Option<Vec<Node>>,
},
Set {
targets: Vec<String>,
value: Option<Expr>,
body: Option<Vec<Node>>,
},
Include {
template: Expr,
ignore_missing: bool,
with_context: Option<bool>,
},
Switch {
expr: Expr,
cases: Vec<SwitchCase>,
default_body: Option<Vec<Node>>,
},
Extends {
parent: Expr,
},
Block {
name: String,
body: Vec<Node>,
},
MacroDef(MacroDef),
Import {
template: Expr,
alias: String,
with_context: Option<bool>,
},
FromImport {
template: Expr,
names: Vec<(String, Option<String>)>,
with_context: Option<bool>,
},
FilterBlock {
name: String,
args: Vec<Expr>,
body: Vec<Node>,
},
CallBlock {
caller_params: Vec<MacroParam>,
callee: Expr,
body: Vec<Node>,
},
AsyncEach {
vars: ForVars,
iter: Expr,
body: Vec<Node>,
else_body: Option<Vec<Node>>,
},
AsyncAll {
vars: ForVars,
iter: Expr,
body: Vec<Node>,
else_body: Option<Vec<Node>>,
},
IfAsync {
branches: Vec<IfBranch>,
},
ExtensionTag {
extension_name: String,
tag: String,
args: String,
body: Option<Vec<Node>>,
},
}Expand description
Template structure produced by the parser.
Node::Root: sequence of top-level fragments (text + outputs).Node::Text: literal characters from the template.Node::Output: one or moreExprvalues to evaluate and concatenate (filters etc. are future work).
Variants§
Root(Vec<Node>)
Container for sibling template fragments.
Text(Arc<str>)
Raw text between (or outside) template tags (shared across clones of the AST).
Output(Vec<Expr>)
Content inside {{ … }} after expression parsing.
If
{% if %}, optional {% elif %}, optional {% else %}, {% endif %}.
For
{% for var in iter %} … {% endfor %} (optional {% else %} before endfor).
Set
{% set a = expr %}, {% set a, b = expr %}, or {% set a %}…{% endset %}.
Include
{% include expr %} with optional ignore missing — template name from expression.
with_context: None / Some(true) — current frame stack; Some(false) — isolated root
context (template globals only; matches Jinja without context / Nunjucks-style isolation).
Switch
{% switch expr %}{% case c %}…{% default %}…{% endswitch %}.
Extends
{% extends expr %} — template name from any expression (e.g. quoted string or variable); must appear before meaningful child content.
Block
{% block name %}…{% endblock %} — default body when used in a base layout.
MacroDef(MacroDef)
{% macro name(a, b) %}…{% endmacro %} — emits no output; registers a macro for the current template.
Import
{% import expr as alias %} — loads a template and exposes its top-level macros under alias (alias.macro()).
Fields
FromImport
{% from expr import a, b as c %} — imports named macros into the current macro scope.
Fields
FilterBlock
{% filter name %}…{% endfilter %} — render body to a string, then apply a builtin filter.
CallBlock
{% call macro(args) %}…{% endcall %} — macro may invoke caller() to render this body.
Optional {% call(a, b) m() %} — caller(x, y) passes arguments into the call body scope.
AsyncEach
{% asyncEach var in iter %} … {% endeach %} — sequential async iteration.
Each iteration body is awaited sequentially; async filters/globals within the body can suspend.
AsyncAll
{% asyncAll var in iter %} … {% endall %} — parallel async iteration.
All iteration bodies are rendered concurrently; results are concatenated in iteration order.
IfAsync
{% ifAsync cond %} … {% endif %} — async condition evaluation.
ExtensionTag
Custom extension tag (addExtension / Environment::register_extension).