This reference is split up into the following sections:
For more technical information about the JEXL Grammar, you can find the JavaCC grammar for JEXL here: Parser.jj
| Item | Description |
|---|---|
| Comments |
Specified using ## and extend to the end of line, e.g.
## This is a comment |
| Identifiers / variables |
Must start with a-z, A-Z, _ or $.
Can then be followed by 0-9, a-z, A-Z, _ or $.
e.g.
JEXL also supports my.dotted.var NOTE: JEXL does not support variables with hyphens in them, e.g. commons-logging logging from the variable commons
|
| Scripts | A script in Jexl is made up of zero or more statements. Scripts can be read from a String, File or URL. |
| Statements |
A statement can be the empty statement, the semicolon (;) , block, assignment or an expression.
Statements are optionally terminated with a semicolon.
|
| Block |
A block is simply multiple statements inside curly braces ({, }).
|
| Item | Description |
|---|---|
| Integer Literals | 1 or more digits from 0 to 9 |
| Floating point Literals |
1 or more digits from 0 to 9, followed
by a decimal point and then one or more digits from
0 to 9.
|
| String literals |
Can start and end with either ' or ", e.g.
"Hello world" 'Hello world' |
| Boolean literals |
The literals true and false can be used, e.g.
val1 == true |
| Null literal |
The null value is represented as in java using the literal null, e.g.
val1 == null |
| Function | Description |
|---|---|
| empty |
Returns true if the expression following is either:
empty(var1) |
| size |
Returns the information about the expression:
size("Hello") |
| Operator | Description |
|---|---|
Boolean and |
The usual && operator can be used as well as the word and, e.g.
cond1 and cond2 cond1 && cond2 |
Boolean or |
The usual || operator can be used as well as the word or, e.g.
cond1 or cond2 cond1 || cond2 |
Boolean not |
The usual ! operator can be used as well as the word not, e.g.
!cond1 not cond1 |
Bitwise and |
The usual & operator is used, e.g.
33 & 4 |
Bitwise or |
The usual | operator is used, e.g.
33 | 4 |
Bitwise xor |
The usual ^ operator is used, e.g.
33 ^ 4 |
Bitwise complement |
The usual ~ operator is used, e.g.
~33 |
| Equality |
The usual == operator can be used as well as the abbreviation eq.
For example
val1 == val2 val1 eq val2
|
| Inequality |
The usual != operator can be used as well as the abbreviation ne.
For example
val1 != val2 val1 ne val2 |
| Less Than |
The usual < operator can be used as well as the abbreviation lt.
For example
val1 < val2 val1 lt val2 |
| Less Than Or Equal To |
The usual <= operator can be used as well as the abbreviation le.
For example
val1 <= val2 val1 le val2 |
| Greater Than |
The usual > operator can be used as well as the abbreviation gt.
For example
val1 > val2 val1 gt val2 |
| Greater Than Or Equal To |
The usual >= operator can be used as well as the abbreviation ge.
For example
val1 >= val2 val1 ge val2 |
| Addition |
The usual + operator is used.
For example
val1 + val2 |
| Subtraction |
The usual - operator is used.
For example
val1 - val2 |
| Multiplication |
The usual * operator is used.
For example
val1 * val2 |
| Division |
The usual / operator is used.
For example
val1 / val2 |
| Integer Division |
The div operator is used.
For example
4 div 3 |
| Modulus (or remainder) |
The % operator is used. An alternative is the mod
operator.
For example
5 mod 2 5 % 2 |
| Negation |
The unary - operator is used.
For example
-12 |
| Array access |
Array elements may be accessed using either square brackets or a dotted numeral, e.g.
arr1[0] arr1.0 |
| Operator | Description |
|---|---|
| if |
Classic, if/else statement, e.g.
if ((x * 2) == 5) {y = 1;} else {y = 2;}
|
| foreach |
Loop through items of an Array, Collection, Map, Iterator or Enumeration, e.g.
foreach (item in list) { x = x + item; }
Where item and list are variables.
|
| while |
Loop until a condition is satisfied, e.g.
while (x lt 10) { x = x + 2; }
|