No matching definitions.

template/parse

src/template/parse.tur
defn

parse

(parse [tokens : int] :)

consume a token chain and return the root node.

tokenstoken chain handle returned by `lex`

A handle to the first node, or 0 if the template was empty. Walk the chain via node-next; free with nodes-free.

(let [tk (lex "<%= name %>") nd (parse tk)] (node-tag nd))  ; => 1

Since: 0.1.0

defn

node-tag

(node-tag [n : int] :)

read a node's tag.

nnode handle

0 = Literal, 1 = Emit, 2 = IfNode, 3 = ForNode, 4 = LetNode, -1 if n is 0.

(node-tag (parse (lex "<%= x %>")))  ; => 1

Since: 0.1.0

defn

node-name

(node-name [n : int] :)

read a node's name slot.

nnode handle

The variable name for Emit/If/For/Let nodes; "" for Literal or null nodes.

(node-name (parse (lex "<%= title %>")))  ; => "title"

Since: 0.1.0

defn

node-value

(node-value [n : int] :)

read a node's value slot.

nnode handle

For Literal nodes: the emitted text. For ForNode: the collection variable name. For LetNode: the literal value, or "@key" for an env-ref binding. "" for Emit/If or null nodes.

(node-value (parse (lex "hello")))  ; => "hello"

Since: 0.1.0

defn

node-then

(node-then [n : int] :)

read the then-body of an If/For/Let node.

nnode handle

The first child node of the then-branch, or 0 if empty/not applicable.

(node-then (parse (lex "<% if x %>y<% end %>")))  ; => Literal "y"

Since: 0.1.0

defn

node-else

(node-else [n : int] :)

read the else-body of an If node.

nnode handle

The first child node of the else-branch, or 0 if no else clause.

(node-else (parse (lex "<% if x %>a<% else %>b<% end %>")))  ; => Literal "b"

Since: 0.1.0

defn

node-next

(node-next [n : int] :)

read the next sibling node in the chain.

nnode handle

The next sibling node, or 0 if this was the last in its body.

(node-next first-node)

Since: 0.1.0

defn

nodes-free

(nodes-free [n : int] :)

recursively release a node chain and its children.

nnode chain head (may be 0)
(nodes-free (parse (lex "<%= x %>")))

Since: 0.1.0