Module
tuck/ast
src/tuck/ast.pookaA template, understood: the shape the parser builds and the renderer walks.
A template is a list of nodes: text, values to print, and the tags that choose, repeat or borrow other templates. Inside tags live expressions: names, paths into them, literals, comparisons and filters.
API reference
class Expr
A value to compute.
class Literal(value: Json) is Expr
A value written in the template: a string, a number, true, false or
nil.
value: Json
$package/pooka_json/pooka/json.Json
fn($package/pooka_json/pooka/json.Json) -> tuck/ast.Literalclass Variable(name: String, at: Pos) is Expr
A name looked up in the data, or a loop variable: user.
name: String
Stringat: Pos
tuck/error.Pos
fn(String, tuck/error.Pos) -> tuck/ast.Variableclass Field(target: Expr, name: String, at: Pos) is Expr
A field of an object: user.name.
target: Expr
tuck/ast.Exprname: String
Stringat: Pos
tuck/error.Pos
fn(tuck/ast.Expr, String, tuck/error.Pos) -> tuck/ast.Fieldclass Item(target: Expr, key: Expr, at: Pos) is Expr
A list position or an object key: posts[0], scores["ada"].
target: Expr
tuck/ast.Exprkey: Expr
tuck/ast.Exprat: Pos
tuck/error.Pos
fn(tuck/ast.Expr, tuck/ast.Expr, tuck/error.Pos) -> tuck/ast.Itemclass Filtered(target: Expr, name: String, arguments: List(Expr), at: Pos) is Expr
A value passed through a filter: name | upper, items | join(", ").
target: Expr
tuck/ast.Exprname: String
Stringarguments: List(Expr)
List(tuck/ast.Expr)at: Pos
tuck/error.Pos
fn(tuck/ast.Expr, String, List(tuck/ast.Expr), tuck/error.Pos) -> tuck/ast.Filteredclass Negated(operand: Expr) is Expr
not value
operand: Expr
tuck/ast.Expr
fn(tuck/ast.Expr) -> tuck/ast.Negatedclass Both(left: Expr, right: Expr) is Expr
left and right
left: Expr
tuck/ast.Exprright: Expr
tuck/ast.Expr
fn(tuck/ast.Expr, tuck/ast.Expr) -> tuck/ast.Bothclass Either(left: Expr, right: Expr) is Expr
left or right
left: Expr
tuck/ast.Exprright: Expr
tuck/ast.Expr
fn(tuck/ast.Expr, tuck/ast.Expr) -> tuck/ast.Eitherclass Compared(operator: String, left: Expr, right: Expr, at: Pos) is Expr
==, !=, <, <=, >, >= or in.
operator: String
Stringleft: Expr
tuck/ast.Exprright: Expr
tuck/ast.Exprat: Pos
tuck/error.Pos
fn(String, tuck/ast.Expr, tuck/ast.Expr, tuck/error.Pos) -> tuck/ast.Comparedclass Node
A part of a template.
class Text(value: String) is Node
Text, printed as it is.
value: String
String
fn(String) -> tuck/ast.Textclass Print(value: Expr, at: Pos) is Node
{{ value }}
value: Expr
tuck/ast.Exprat: Pos
tuck/error.Pos
fn(tuck/ast.Expr, tuck/error.Pos) -> tuck/ast.Printclass Branches(choices: List(#(Expr, List(Node))), otherwise: List(Node)) is Node
{% if %}, any {% elif %}s, and an optional {% else %}.
choices: List(#(Expr, List(Node)))
List(#(tuck/ast.Expr, List(tuck/ast.Node)))otherwise: List(Node)
List(tuck/ast.Node)
fn(List(#(tuck/ast.Expr, List(tuck/ast.Node))), List(tuck/ast.Node)) -> tuck/ast.Branchesclass Loop(
key: Option(String),
name: String,
items: Expr,
body: List(Node),
empty: List(Node),
at: Pos
) is Node
{% for name in items %} or {% for key, name in object %}, with an
optional {% else %} for when there is nothing to repeat.
key: Option(String)
Option(String)name: String
Stringitems: Expr
tuck/ast.Exprbody: List(Node)
List(tuck/ast.Node)empty: List(Node)
List(tuck/ast.Node)at: Pos
tuck/error.Pos
fn(Option(String), String, tuck/ast.Expr, List(tuck/ast.Node), List(tuck/ast.Node), tuck/error.Pos) -> tuck/ast.Loopclass Include(
name: String,
bindings: List(#(String, Expr)),
only: Bool,
at: Pos
) is Node
{% include "name" %}
name: String
Stringbindings: List(#(String, Expr))
List(#(String, tuck/ast.Expr))only: Bool
Boolat: Pos
tuck/error.Pos
fn(String, List(#(String, tuck/ast.Expr)), Bool, tuck/error.Pos) -> tuck/ast.Includeclass Block(name: String, body: List(Node), at: Pos) is Node
{% block name %} … {% endblock %}
name: String
Stringbody: List(Node)
List(tuck/ast.Node)at: Pos
tuck/error.Pos
fn(String, List(tuck/ast.Node), tuck/error.Pos) -> tuck/ast.Blockclass Extends(name: String, at: Pos) is Node
{% extends "name" %} while it is being read. A finished Document
holds it as extends instead.
name: String
Stringat: Pos
tuck/error.Pos
fn(String, tuck/error.Pos) -> tuck/ast.Extendsclass Document(extends: Option(#(String, Pos)), nodes: List(Node))
A whole template: the template it extends, if any, and its nodes.
extends: Option(#(String, Pos))
Option(#(String, tuck/error.Pos))nodes: List(Node)
List(tuck/ast.Node)
fn(Option(#(String, tuck/error.Pos)), List(tuck/ast.Node)) -> tuck/ast.Documentclass Call(name: String, arguments: List(Expr), at: Pos) is Expr
An explicit registered call, including a dotted namespace such as time.now.
name: String
Stringarguments: List(Expr)
List(tuck/ast.Expr)at: Pos
tuck/error.Pos
fn(String, List(tuck/ast.Expr), tuck/error.Pos) -> tuck/ast.Callclass Set(name: String, value: Expr, at: Pos) is Node
Bind a name for following nodes in the current lexical scope.
name: String
Stringvalue: Expr
tuck/ast.Exprat: Pos
tuck/error.Pos
fn(String, tuck/ast.Expr, tuck/error.Pos) -> tuck/ast.Setclass With(bindings: List(#(String, Expr)), body: List(Node), at: Pos) is Node
A lexical scope whose bindings are evaluated in the enclosing scope.
bindings: List(#(String, Expr))
List(#(String, tuck/ast.Expr))body: List(Node)
List(tuck/ast.Node)at: Pos
tuck/error.Pos
fn(List(#(String, tuck/ast.Expr)), List(tuck/ast.Node), tuck/error.Pos) -> tuck/ast.With