Expression language¶
Description¶
OnSphere provides a simple expression language as a way to easily express conditions and transformations.
Usage¶
Syntax¶
Literals¶
true
orfalse
for booleans42
,31.4
or-1
for numbers'hello world'
for textvariable-name
for literal variables
Functions¶
function(argA)
for unary functionsfunction(argA, argB)
for binary functionsfunction(argA, argB, ..., argN)
for n-ary functions
Functions and literals can be combined to express complex expressions¶
concat('abc', 'def', 'ghi')
cond(and(true, true), 'abcdef', '')
len(substr('test', 0, sub(len('test'), 1)))
Available functions¶
Name |
Signature |
Description |
Examples |
---|---|---|---|
not |
|
logical NOT |
|
and |
|
logical AND between 1 to N booleans |
|
or |
|
logical OR between 1 to N booleans |
|
add |
|
addition between 1 to N booleans |
|
sub |
|
subtraction between 1 to N numbers |
|
mul |
|
multiplication between 1 to N numbers |
|
div |
|
division between 2 numbers |
|
mod |
|
modulus division between 2 numbers |
|
starts |
|
textual starts with check |
|
ends |
|
textual ends with check |
|
in |
|
textual contains check |
|
substr |
|
textual sub-string extraction based on indexes |
|
substrl |
|
textual sub-string extraction based on index and length |
|
concat |
|
textual concatenation |
|
len |
|
textual length |
|
eq |
|
equality check |
|
neq |
|
inequality check |
|
lt |
|
less than check |
|
lte |
|
less than or equal to check |
|
gt |
|
greater than check |
|
gte |
|
greater than or equal to check |
|
min |
|
minimum of given numbers |
|
max |
|
maximum of given numbers |
|
var |
|
accesses the content of a variable |
|
cond |
|
conditional selection between two expressions |
|
debug |
|
reports the result of the execution as a labeled debug layer and transparently forwards the result to the caller |
|
asBoolean |
|
converts the expression to a boolean. |
|
asInteger |
|
converts the expression to a integer. |
|
asDecimal |
|
converts the expression to a decimal. |
|
asText |
|
converts the expression to text. |
|
Accessing variables¶
Variables can either be accessed using var('variable-name')
function or by using literal variable like variable-name
. For example and(var('variable-name'), true)
and and(variable-name, true)
are equivalent.
Warning
Literal variables must start with a letter and only allow the characters a-z
, A-Z
, 0-9
, .
, _
and -
when used without '
.
However, accessing a dynamically named variable (i.e. a variable whose name is built from sub-expressions) can only be accessed using var()
function. For example var(concat('constant-prefix.', variable-part))
.