Version 1 (modified by ph3-der-loewe, 11 years ago) (diff)


uste parser syntax

This page describes the syntax of the parser module of libuste. This syntax is used within all templates (as parsed by libuste).


The parser reads the document and scans it for commands. uste commands start and end with 3 @s (@@@cmd@@@) while in "document" mode. with the pragma command you can switch into "uste" mode which will allow you to skip them. This is used to allow bigger blocks to be more easy to read.

Here is an example in document mode:

@@@set answer to 42@@@
Answer is: @@@var answer@@@

This is an example in uste mode:

@@@pragma code uste@@@
 set answer to 42
 literal: Answer is:
 var answer
 literal special newline

So software like web servers can detect the file to be a uste template there is the uste magic number. This magic is the special command TEMPLATE (@@@TEMPLATE@@@). This magic should be used at the begin of each template so it can be detected by such software. This special command is stripped while rendering and will not generate any output.

Basic command syntax

Each command is started and ended with @@@ if not in uste mode. The first word of the command is the command name. In addition command parameters can follow. After the parameters there can be the extra parameter which is always a string literal. So the basic syntax is:

@@@command[ ARG[ ARG[ ARG...]]][: extra]@@@

A simple example is setting a variable to a string:

@@@set var: string@@@

The number and type of arguments as well as the usage of extra depends on the command.

Block commands

There are some block commands. Those commands are control structures e.g. loops or scopes. Those blocks start with the block command and end with the special end command like this:

@@@if defined a@@@
a is: @@@var a@@@

It is also possible to end the block with a bang version of the command:

@@@if defined a@@@
a is: @@@var a@@@

However this syntax is more uncommon yet it may be useful when using complex nesting within the template (document mode) with only few or no line breaks.


Normal commands

Block commands