No matching definitions.

template/token

src/template/token.tur
defn

lex

(lex [src : cstr] :)

tokenize a template source string.

srcNUL-terminated template text

A handle to the first token cell, or 0 if the template is empty. Walk the chain via token-next; free with tokens-free.

(let [t (lex "Hi <%= name %>!")] (token-tag t))  ; => 0 (TextChunk)

Since: 0.1.0

defn

token-tag

(token-tag [t : int] :)

read the tag of a token.

ttoken cell handle

0 = TextChunk, 1 = CodeBlock, 2 = ExprBlock, 3 = Comment, -1 if t is 0.

(token-tag (lex "<%= x %>"))  ; => 2 (ExprBlock first token? no, here it's the only token)

Since: 0.1.0

defn

token-text

(token-text [t : int] :)

read the NUL-terminated payload of a token.

ttoken cell handle

The token's text content (interior of <% %> for tag tokens, verbatim slice for TextChunk). The empty string if t is 0.

(token-text (lex "<%= x %>"))  ; => " x "

Since: 0.1.0

defn

token-len

(token-len [t : int] :)

payload length in bytes.

ttoken cell handle

Byte length of the token text, 0 if t is 0.

(token-len (lex "hi"))  ; => 2

Since: 0.1.0

defn

token-next

(token-next [t : int] :)

read the next token in the chain.

ttoken cell handle

The next token handle, or 0 if this was the last cell.

(token-next first-tok)

Since: 0.1.0

defn

tokens-free

(tokens-free [t : int] :)

release every cell in a token chain.

thead token cell handle (may be 0)
(tokens-free (lex "hello"))

Since: 0.1.0