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 ValueType.
Example
The following expression is evaluated to the integer 10: (2 + 3) * 2
The following expression is evaluated to the integer 3: floor (3.14)
The following expression is evaluated to the boolean true: "Example" == "Example"
List of Operators
Arithmetics (binary operators)
+for addition, e.g.,5 + 3evaluates to8-for subtraction, e.g.,5 - 3evaluates to2*for multiplication, e.g.,5 * 3evaluates to15/for division, e.g.,6 / 3evaluates to2%for modulo, e.g.,5 % 3evaluates to2powfor power, e.g.,2 pow 3evaluates to8rootfor root, e.g.,27 root 3evaluates to3
Arithmetics (unary operators)
+for positive signing, e.g.,+5evaluates to5-for negative signing, e.g.,-5evaluates to-5sqrtfor square root, e.g.,sqrt 9evaluates to3foorfor flooring a number, e.g.,floor 5.3evaluates to5ceilfor ceiling a number, e.g.,floor 5.3evaluates to6roundfor rounding a number, e.g.,floor 5.3evaluates to5
Relational (binary operators)
<for smaller, e.g.,3 < 3evaluates tofalse<=for smaller or equal, e.g.,3 <= 3evaluates totrue>for greater, e.g.,3 > 3evaluates tofalse>=for greater or equal, e.g.,3 >= 3evaluates totrue==for equal, e.g.,3 == 3evaluates totrue!=for not equal, e.g.,3 != 3evaluates tofalse
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 tofalse
Others (binary operators)
matchesfor a regex match, e.g.,"A07" matches /^[A-Z0-9]*$/evaluates totrueinfor inclusion in an array, e.g.,"a" in ["a", "b", "c"]evaluates totrue
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.