Expressions
Expressions in Jayvee are arbitrarily nested statements. They consist of:
- literals (e.g., numbers 5or strings"Example")
- variables (e.g., declared by fromproperties in Transforms)
- operators (e.g., *orsqrt)
Expressions get evaluated at runtime by the interpreter to a built-in value type.
Example
The following expression is evaluated to the integer 10: (2 + 3) * 2
The following expression is evaluated to the boolean true: "Example" == "Example"
The following expression is evaluated to the text I love Datypus: "I love platypuses" replace /platypuses/ with "Datypus"
List of Operators
Arithmetics (binary operators)
- +for addition, e.g.,- 5 + 3evaluates to- 8
- -for subtraction, e.g.,- 5 - 3evaluates to- 2
- *for multiplication, e.g.,- 5 * 3evaluates to- 15
- /for division, e.g.,- 6 / 3evaluates to- 2
- %for modulo, e.g.,- 5 % 3evaluates to- 2
- powfor power, e.g.,- 2 pow 3evaluates to- 8
- rootfor root, e.g.,- 27 root 3evaluates to- 3
Arithmetics (unary operators)
- +for positive signing, e.g.,- +5evaluates to- 5
- -for negative signing, e.g.,- -5evaluates to- -5
- sqrtfor square root, e.g.,- sqrt 9evaluates to- 3
- foorfor flooring a number, e.g.,- floor 5.3evaluates to- 5
- ceilfor ceiling a number, e.g.,- floor 5.3evaluates to- 6
- roundfor rounding a number, e.g.,- floor 5.3evaluates to- 5
Relational (binary operators)
- <for smaller, e.g.,- 3 < 3evaluates to- false
- <=for smaller or equal, e.g.,- 3 <= 3evaluates to- true
- >for greater, e.g.,- 3 > 3evaluates to- false
- >=for greater or equal, e.g.,- 3 >= 3evaluates to- true
- ==for equal, e.g.,- 3 == 3evaluates to- true
- !=for not equal, e.g.,- 3 != 3evaluates to- false
Logical (binary operators)
- andfor a logical and (both need to be true to evaluate to true)
- orfor a logical or (at least left or right needs to be true to evaluate to true)
- xorfor a logical xor (either left or right needs to be true to evaluate to true)
Logical (unary operators)
- notfor logical negation,- not trueevaluates to- false
Others (binary operators)
- matchesfor a regex match, e.g.,- "A07" matches /^[A-Z0-9]*$/evaluates to- true
- infor inclusion in an array, e.g.,- "a" in ["a", "b", "c"]evaluates to- true
Text manipulation (unary operators)
- lowercaseconverts all alphabetic characters in a text to lowercase
- uppercaseconverts all alphabetic characters in a text to uppercase
Text manipulation (ternary operators)
- replace [...] with [...]replaces regex matches in a text with a string
Operator Details
in Operator
The in operator checks whether a value is included in a collection of values. For example:
4.5 in [3, 6.5] // evaluates to false
3 in [3.0, 6.5] // evaluates to true
"a" in ["a", "b", "c"] // evaluates to true
The operator supports text, integer and decimal values as operands. The compatibility of left and right operand types follows these rules:
- For the inoperator we have a type for the needle (left operand) and a type for the elements in the haystack (right operand).
- There is an automated type conversion as long as it is lossless and clearly defined (integer to decimal as of now).
- We allow any combination of operands that has either: (i) An automated type conversion from needle type (left operand) to the type of the elements in the haystack (right operand), or (ii) the other way around.
Further reading
For a deeper documentation of how expressions and operators work internally, refer to the developer docs.