Skip to main content

Expression Syntax

Whenever specifying placeholders, binding variables, using structural attributes or binding dynamic values to the attributes of tags, expressions are the means via which to describe the value used; they can be as simple as accessing a variable, stringing data together or computing a numeric value and may become as nuanced as using boolean logic, providing fallback-values or accessing members of a variable.

String Literals

A string represents a sequence of characters as-is, to be used in expressions; their contents are delimited by single-quotes (').

'this is a string-literal'

In order to include a literal single-quote, prepend it by a backslash (\) in order to avoid premature string termination.

'containing a \' single quote'
tip

When specifying string-literals inside of attribute-values which themselves use string-notation delimited by a double-quote ("), said double-quotes are to be marked by a preceding backslash (\) in order to avoid premature attribute-value termination.

<my-tag [my-attribute]="'my string literal containing a \" double-quote'">

Numbers

Numeric values are always expressed using the decimal system, i.e. digits 0 through 9.

8912

Fractional values may be depicted using the decimal-dot (.).

2.7182

Additionally, numbers may become negative simply by prepending a minus-sign (-).

-512

Concatenation Operator

Due to this syntax being dynamically typed, the addition-operator (+) cannot reliably be overloaded to concatenate values back-to-back into a resulting string; thus, the ampersand (&) is used to denote this intent.

Assuming that a holds 'Hello' and b holds 'World', the expression

a & ', ' & b & '!'

will result in

'Hello, World!'

Mathematical Operators

The following mathematical operators are available when formulae are to be expressed. The operator of highest precedence will be evaluated first - use parentheses when necessary.

OperationOperatorPrecedence
Additiona + b1
Subtractiona - b1
Multiplicationa * b2
Divisiona / b2
Moduloa % b2
Exponentiationa ^ b3

Immediate List

Whenever static lists of items are to be instantiated for further use, simply specify the desired items in a comma-separated (,) list, enclosed by square brackets ([]).

['first', 'second', 'third']

This notation may especially come in handy when combined with the structural *for- attribute:

<red *for-word="['first', 'second', 'third']">Hello, {{word}}!

Items may also once again be lists themselves, allowing for a tuple-style dataset.

[['apple', 'red'], ['banana', 'yellow']]

And thereby give rise to more advanced concepts of templating.

<color
*for-word="[['apple', 'red'], ['banana', 'yellow']]"
[value]="word[1]"
>Hello, {{word[0]}}!

Range Operator

In order to quickly generate a list containing a subsequent sequence of numbers, the range operator may be used, with both bounds being inclusive.

1..10

is thereby equivalent to

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

This operator may especially come in handy when combined with the structural *for- attribute.

<red *for-number="1..10">Hello, {{number}}!

Substring Operator

A substring represents a sub-sequence of characters within another string; it may span only a single character, a few or up to the whole input, based on the colon-separated (:) start- and end-indices, which are both inclusive and start at zero.

Given an input of 'ABCDEFGHIJ' with the following indices

Index0123456789
Letter'A''B''C''D''E''F''G''H''I''J'

these will be the results of a few substring-operations

OperationResult
input[0:9]'ABCDEFGHIJ'
input[2:]'CDEFGHIJ'
input[:8]'ABCDEFGHI'
input[:]'ABCDEFGHIJ'
input[4:6]'EFG'
input[-1:]'J'
input[:-2]'AB'
input[-1:-2]'JAB'
input[0:100]'ABCDEFGHIJ'
input[-100:]'JIHGFEDCBA'

As becomes apparent, both the start- and end-indices are omittable (up to bounds); also, negative indices will wrap around. Whenever an index is out of bounds, meaning that its absolute value is greater than or equal to the number of characters within the string, the operation will just stop right there.

Keywords

Keywords are reserved names, not able to be used as variables, holding a static value:

  • Boolean value of 1, i.e. "yes": true
  • Boolean value of 0, i.e. "no": false
  • The absence of a value: null

Accessing Variables

All variables used in expressions adhere to the convention of snake_case and simply by specifying their name, their corresponding value will be substituted at the stage of evaluation.

my_variable

Accessing Members

Variables are not required to hold mere scalar values, e.g. numbers, booleans, strings, etc., but may just as well be lists containing multiple items, maps containing multiple key-value pairs, or objects which contain named fields.

List-Items

Assuming that my_list is a collection of individual items, say 'first', 'second' and 'third', their indices are simply represented by an ascending numeric index starting at zero. The index may be derived by the value of a variable, interpreted as a number.

my_list[my_index]
my_indexResult
0'first'
1'second'
2'third'
3null

Indices can also be specified immediately, with

my_list[0]

resulting in 'first'.

Analogous to bounds on substrings, list-indices may also be negative, meaning that they access elements relative to the back of the sequence, with -1 being the last, -2 the second to last, etc.

my_indexResult
-1'third'
-2'second'
-3'first'
-4null

Map-Values

Assuming that my_map is assigning keys representing usernames to values being their statistics, say 'Notch' -> 384, 'Steve' -> 247 and 'Alex' -> 412, the value of each such key may be accessed by specifying it analogously to numeric indices on lists.

my_map[my_key]
my_keyResult
'Notch'384
'Steve'247
'Alex'412
'Herobrine'null

Keys may also be specified immediately, with

my_map['Alex']

resulting in 412.

Object-properties

Assuming that my_object is a Java-object containing a few members, say

{ effect: 'Regeneration', duration_ticks: 900, amplitude: 2 }

the value of each member may be accessed by appending a dot (.), followed by its name.

my_object.my_member
ExpressionResult
my_object.effect'Regeneration'
my_object.duration_ticks900
my_object.amplitude2

Analogously to maps, keys may also be specified dynamically, with

my_object[my_member_name]

or even immediately, using

my_object['duration_ticks']

resulting in 900.

info

When programming in Java, the established naming-convention regarding properties is camelCase; as to avoid programmers from being forced to employ snake_case on objects they want to make accessible within templates, name-conversion occurs automatically, e.g. myExampleVariable becomes my_example_variable.

Boolean Logic

Not (Invert)

By prepending an expression with a bang (!), it's value is interpreted as a boolean and will be inverted, meaning that true will become false and vice-versa.

!value
valueResult
falsetrue
truefalse

Or (Disjunction)

By stringing two expressions together using a double-pipe (||), both the left- and the right hand side will be interpreted as boolean values; given that any one of them is true, the result will be also - otherwise, false will be the result.

lhs || rhs
lhsrhsResult
falsefalsefalse
falsetruetrue
truefalsetrue
truetruetrue

And (Conjunction)

By stringing two expressions together using a double-ampersand (&&), both the left- and the right hand side will be interpreted as boolean values; given that both are true, the result will be also - otherwise, false will be the result.

lhs && rhs
lhsrhsResult
falsefalsefalse
falsetruefalse
truefalsefalse
truetruetrue

Ternary Operator

If an expression is to be selected out of two branches, one for true and one for false, given a boolean input, this will be the operator of choice.

input ? branch_true : branch_false
inputResult
falsebranch_false
truebranch_true

Comparison Operators

ComparisonOperatorTrue when
Greater Thana > ba is greater than b
Greater Than Or Equala >= ba is greater than or equal to b
Less Thana < ba is less than b
Less Than Or Equala <= ba is less than or equal to b
Equal Toa == ba is equal to b
Not Equal Toa != ba is not equal to b

Fallback Values

If a variable or an expression in general may return a null-value, a fallback can be provided by appending it with a double-questionmark (??), followed by the actual value.

input ?? fallback_variable
inputResult
nullfallback_variable
non-nullinput