From 7449faaa76a5b4008fd51a6562cca2e0a852ea6b Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Fri, 1 May 2020 17:33:13 +0200 Subject: Clean up code and improve documentation This switches the code documentation genarator (we're now using phpdoc instead of NaturalDoc). Also various small code cleanup tasks: - Remove unused code - Get rid of `and` / `or`, we're using `&&` / `||` now - Adding missing return values - Helping PhpStorm to detect some dynamically called functions (mark_builtin_callable in Transcompiler) - Reword transcompiling => compiling in documentation --- docu/language_definition.html | 80 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) (limited to 'docu/language_definition.html') diff --git a/docu/language_definition.html b/docu/language_definition.html index a296395..c99a4b9 100644 --- a/docu/language_definition.html +++ b/docu/language_definition.html @@ -24,12 +24,12 @@ background: #eee; } - +

The STE Template Language

This is the documentation of the Template Language of the STE Template Engine.

- +

TOC

  1. @@ -84,10 +84,10 @@
- +

Basic Elements

The STE Template Language consists of four basic elements:

- +

Text

Everything that is not a Variable, a Tag or a Pseudotag is Text.

Also everything that is wrapped in the ste:rawtext pseudotag will be Text, whereby all Tags and Variables will not be parsed.

@@ -98,14 +98,14 @@
Foo <ste:bar>$baz[herpdederp]</ste:baz>
will result in one text-element and one tag-element containing one variable-element.

- +

Variable

Variables start with a $ or can be wrapped within ${ and }, so you can write this: ${foo}ish

Variable have names, these names can consist of letters (english alphabet; upper and lower case), numbers and underscores (_). As a regex: [a-zA-Z0-9_]+

A variable can also be an array. To access an array, wrap the desired fieldname within [ and ]. A fieldname can be constructed of Text and other Variables. So you can dynamically access fields: $foo[$bar]. These fieldnames can also be nested or concatenated: $foo[$bar[baz]][herp][$de[derp]]

If you want a literal $ char, you can escape it: \$

Variables in STE are typeless, everything is text. In a boolean context, empty text usually represents false, else true.

- +

Tag

A Tag can be compared to a function. A Tag can have parameters and children elements.

@@ -124,14 +124,14 @@ When using variables in parameter values, they will be "replaced" by their value. Because many tags need the variable and not its content, they expect only the variable's name. If you then write foo="$bar", the tag will not operate on the bar variable but on the Variable with the name stored in $bar! So read the instructions to the tag carefully!

Example: <ste:foo bar="baz" herp="literal quote sign: \"">de <ste:derp hehe="hoho$wtf[xd]" /></ste:foo>

- +

Pseudotag

Pseudotags look like normal tags, but they perform special tasks. There are currently two pseudotags:

ste:comment

With the ste:comment pseudotag you can comment your template/code. Everything between <ste:comment> and </ste:comment> will be ignored, before the real tokenization of the code starts.

ste:rawtext

The ste:rawtext pseudotag will output a Text element with its wrapped content. It will prevent parsing of the content. Useful if you are embedding another script language, which uses the $ char or also has a XML-Like syntax. No escape sequences will be translated! Can not be used in Tag parameter values!

- +

Escaping special chars

To get a literal $, " or other special chars, STE gives you the following escape sequences:

@@ -201,10 +201,10 @@

Escape sequences are not translated in Pseudotags

- +

Builtin Tags

STE has some builtin Tags, that makes programming in STE possible.

- +

ste:if

The ste:if Tag provides an if-clause to STE.

ste:if can have the subtags ste:then and ste:else. Everything between <ste:if> and </ste:if>, that is not an ste:then or ste:else tag, will be used as the condition.

@@ -223,7 +223,7 @@

<ste:if>condition<ste:then>then</ste:then><ste:else>else</ste:else></ste:if>

?, {, | and } can be escaped

In this variant, the else part is not optional!

- +

ste:cmp

With the ste:cmp tag you can compare two values.

ste:cmp is selfclosing, the compared values are passed by parameters.

@@ -285,7 +285,7 @@

This is equivalent to:

<ste:cmp text_a="a" op="operator" text_b="b" />

~, {, | and } can be escaped.

- +

ste:not

The ste:not Tag will logically invert its content. If it is an empty text (i.e. false), it will return a non-empty text (i.e. true) and vice versa.

@@ -293,10 +293,10 @@

<ste:if>
<ste:not>$foo</ste:not>
<ste:then>:-)</ste:then>
<ste:else>:-(</ste:else>
</ste:if>
If the variable foo is empty (i.e. false), :-) will be returned, :-( otherwise.

- +

ste:even

If the enclosed text is a number, and the number is even, this tag will return a non-empty text (i.e. true), an empty text (i.e. false) otherwise.

- +

ste:for

ste:for provides a counter loop.

@@ -338,7 +338,7 @@

<ste:for start="10" stop="0" step="-1" counter="i">
$i<br />
</ste:for>
Will count from 10 down to 0 and output the number followed by an HTML line break.

- +

ste:foreach

ste:foreach will loop through an array.

@@ -388,7 +388,7 @@

<ste:foreach array="foo" value="v">
<p>$v</p>
<ste:else>
Array \$foo is empty.
</ste:else>
</ste:foreach>
This code will list all array elements or will display Array $foo is empty if the array $foo is empty.

- +

ste:infloop

Creates an infinitive loop. You can get out of the loop using the ste:break tag. Can be used to emulate other loop constructs like while loops.

@@ -396,16 +396,16 @@

<ste:infloop>
<ste:if>
<ste:foo />
<ste:then><ste:break /></ste:then>
</ste:if>
...
<ste:infloop>
This code will return ... while <ste:foo /> returns an empty text (i.e. false).

- +

ste:break

When this self-closing tag is called, the current loop (ste:for, ste:foreach, ste:infloop) will be aborted.

- +

ste:continue

When this self-closing tag is called, the current loop(ste:for, ste:foreach, ste:infloop) will go to the next iteration, aborting the current iteration.

- +

ste:load

This self-closing tag loads and executes another template. The name parameter (mandatory) defines the template to load.

-

Because each template must be parseable and transcompilable by itself, this is not a inclusion of another template. So you can not do this:

+

Because each template must be parseable and compilable by itself, this is not a inclusion of another template. So you can not do this:

slave.tpl:

<ste:foo>
bla
@@ -419,7 +419,7 @@ master.tpl
<ste:baz>
<ste:load name="slave.tpl" />
</ste:baz>

- +

ste:block

ste:block provides an easy way for writing master templates. Every block has a name. When a block is defined twice, the second one will overwrite the first one.

The name can be set with the name parameter.

@@ -432,7 +432,7 @@ When executing slave.tpl, master.tpl will be loaded and its content block will be replaced with the new one (Much cooler content :-)) but leave the original sidebar block.

Blocks can not be nested.

- +

ste:set

ste:set will set a variable. The parameter var takes the name of the variable to set. The content of the Tag will be the new content of the variable.

@@ -444,10 +444,10 @@ Tag parameter values can not contain Tags. ste:set can be used to bypass this:

<ste:set var="temp"><ste:foo /></ste:set>
<ste:bar baz="$temp" />

- +

ste:set

ste:setlocal is used like ste:set, but only a local variable will be set (ste:set would overwrite a variable, if it was declared in a parent scope). - +

ste:get

ste:get will return the content of a variable. The parameter var takes the name of the variable to get. Useful, if you want to get a variable which name is stored in a variable.

@@ -455,30 +455,30 @@

<ste:get var="$foo" />
This will get the variable with the name that is stored in the variable foo.

- +

ste:calc

To perform mathematical calculations, you can use ste:calc. ste:calc calculates the mathematical formula it is wrapped around and returns the result. The formula is in the usual infix-notation [ext. Link] and has these operators: +, -, *, / and ^. Numbers are always decimal, the decimal mark is . and numbers can be prefixed with an - to indicate a negative number. It is a good idea to wrap a negative number in brackets to prevent wrong evaluation (because - is also an operator). Calculations can be grouped with brackets: ( and ).

Real numbers are supported, complex numbers not.

-

Formulas are evaluated at runtime, not during transcompilation.

+

Formulas are evaluated at runtime, not during compilation.

Example:
<ste:calc>(2+3+4) * (1.5 - (-0.5))</ste:calc> will return 18.

-

This Tag is pretty slow, because the formula is not transcompiled and only evaluated at runtime. For some simple increment and decrement operations it is better to use the ste:inc and ste:dec Tags from the standard library.

- +

This Tag is pretty slow, because the formula is not compiled and only evaluated at runtime. For some simple increment and decrement operations it is better to use the ste:inc and ste:dec Tags from the standard library.

+

ste:mktag

ste:mktag allows you to define own Tags using the STE Template Language.

The parameter name (mandatory) expects the name of the new tag. If your tag requires some parameters, you can specify them using the optional mandatory parameter. Names of the mandatory parameters are separated by |.

The Variable _tag_parameters (associative array) will hold all given parameters and their values.

With the ste:tagcontent tag you can execute the tags content.

-

ste:mktag will be transcompiled like any other code. So your custom tag will be almost as fast as a plugin coded in PHP.

+

ste:mktag will be compiled like any other code. So your custom tag will be almost as fast as a plugin coded in PHP.

Example:

<ste:mktag name="countdown" mandatory="from|counter">
<ste:for start="$_tag_parameters[from]" stop="0" step="-1" counter="$_tag_parameters[counter]">
<ste:tagcontent />
</ste:for>
</ste:mktag>
<ste:mktag name="double">
<ste:calc><ste:tagcontent /> * 2</ste:calc>
</ste:mktag>
<ste:countdown from="5" counter="i">
<ste:double>$i</ste:double><br />
</ste:countdown>
Will output:
10<br/>
8<br />
6<br />
4<br />
2<br />
0<br />

- +

Standard Library

The Standard Library contains some useful tags, which are not builtin but still always available.

ste:escape

@@ -492,19 +492,19 @@

If the optional parameter lines is true (i.e. not empty), then additionally line breaks are converted to <br />.

- +

ste:strlen

Returns the length of then content.

- +

ste:arraylen

Returns the number of elements in the array (variable name given by parameter array).

- +

ste:inc

Increments (i.e. add 1) a variable (variable name given by parameter var).

- +

ste:dec

Decrements (i.e. subtract 1) a variable (variable name given by parameter var).

- +

ste:date

Formats a time using PHPs strftime format [ext. Link]. The format is given in the tag's content. You can specify a time (unix timestamp) using the timestamp parameter (defaults to the current time).

@@ -513,21 +513,21 @@ Result:

18. Sep. 2011, 16:49:20

- +

ste:in_array

Check, if a value is in an array. The tag takes the variable name of the array by parameter array.The value to test with will be taken from the tags content.

Returns empty text, if the value is not in the array, otherwise a non-empty text.

- +

ste:join

Join parts of an array together. The array's variable name goes to the array parameter. The tag's content will be used as the glue, i.e. this will be between two elements.

Returns the joined array

- +

ste:split

Split a text and write the parts to an array. The array parameter takes the variable name of the resulting array, the delim parameter the text to split by. The tag's content will be the text to split.

- +

ste:array_add

Adding an element to an array. The array parameter takes the variable name of the array. The key parameter takes the array key to map the value to, if omitted, the value will be appended to the end of the array. The value is the tag's content.

- +

ste:array_filter

Filter out array elements by multiple criterias.

All the parameters are names of array variables.

-- cgit v1.2.3-70-g09d2