##### Commons Jexl

- Overview
- 1.0 Javadoc
- Latest Javadoc
- Examples
- Releases and Builds
- Jar Downloads
- Reference
- Building
- JEXL Wiki

##### Project Documentation

- About
- Downloads
- Project Info
- Project Reports
- Development Process

##### Commons

- Home
- Components
- Sandbox
- Dormant
- Volunteering
- Contributing Patches
- Building Components
- Releasing Components
- Wiki

##### Legend

- External Link
- Opens in a new window

## Overview

This reference is split up into the following sections:

1. Language Elements
2. Literals
3. Functions
4. Operators
5. Conditional Statements

For more technical information about the JEXL Grammar, you can find the JavaCC grammar for JEXL here: Parser.jj

## Language Elements

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. Valid: `var1`,`_a99`,`$1` Invalid: `9v`,`!a99`,`1$` JEXL also supports `ant-style` variables, e.g.
    my.dotted.var
is a valid variable name. NOTE: JEXL does not support variables with hyphens in them, e.g.
    commons-logging
is not a valid variable, but instead is treated as a subtraction of the variable `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 (`{, }`).

## Literals

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"
and
    'Hello world'
are equivalent.
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

## Functions

Function | Description
--- | ---
empty | Returns true if the expression following is either: `null` An empty string An array of length zero A collection of size zero An empty map
    empty(var1)
size | Returns the information about the expression: Length of an array Size of a List Size of a Map Size of a Set Length of a string
    size("Hello")
returns 5.

## Operators

Operator | Description
--- | ---
Boolean `and` | The usual `&&` operator can be used as well as the word `and`, e.g.
    cond1 and cond2
and
    cond1 && cond2
are equivalent
Boolean `or` | The usual `||` operator can be used as well as the word `or`, e.g.
    cond1 or cond2
and
    cond1 || cond2
are equivalent
Boolean `not` | The usual `!` operator can be used as well as the word `not`, e.g.
    !cond1
and
    not cond1
are equivalent
Bitwise `and` | The usual `&` operator is used, e.g.
    33 & 4
, 0010 0001 & 0000 0100 = 0.
Bitwise `or` | The usual `|` operator is used, e.g.
    33 | 4
, 0010 0001 | 0000 0100 = 0010 0101 = 37.
Bitwise `xor` | The usual `^` operator is used, e.g.
    33 ^ 4
, 0010 0001 ^ 0000 0100 = 0010 0100 = 37.
Bitwise `complement` | The usual `~` operator is used, e.g.
    ~33
, ~0010 0001 = 1101 1110 = -34.
Equality | The usual `==` operator can be used as well as the abbreviation `eq`. For example
    val1 == val2
and
    val1 eq val2
are equivalent. `null` is only ever equal to null, that is if you compare null to any non-null value, the result is false. Equality uses the java `equals` method
Inequality | The usual `!=` operator can be used as well as the abbreviation `ne`. For example
    val1 != val2
and
    val1 ne val2
are equivalent.
Less Than | The usual `<` operator can be used as well as the abbreviation `lt`. For example
    val1 < val2
and
    val1 lt val2
are equivalent.
Less Than Or Equal To | The usual `<=` operator can be used as well as the abbreviation `le`. For example
    val1 <= val2
and
    val1 le val2
are equivalent.
Greater Than | The usual `>` operator can be used as well as the abbreviation `gt`. For example
    val1 > val2
and
    val1 gt val2
are equivalent.
Greater Than Or Equal To | The usual `>=` operator can be used as well as the abbreviation `ge`. For example
    val1 >= val2
and
    val1 ge val2
are equivalent.
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
gives 1.
Modulus (or remainder) | The `%` operator is used. An alternative is the `mod` operator. For example
    5 mod 2
gives 1 and is equivalent to
    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]
and
    arr1.0
are equivalent

## Conditional

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; }`