Expressions are phrased using words, numbers and symbols to perform logical and functional operations. Expressions consist of identifiers, literals and operators. There is also one keyword, regex, which is introduced in Regular Expressions below.
Identifers
Identifiers in eXPL follow the Java naming syntax: identifiers begin with an alpha character which is followed by any number of alpha or numeric characters or underscore. You see in all the eXPL examples a naming convention different from Java's camelCase. The convention is intended to make eXPL look different from Java and uses all lower-case names, with underscore character used to separate words.
It is normal for an identifier to occupy a space isolated from all identifiers outside the space. Such name spaces avoids the difficulty of maintaining one global space where all names must be unique. There is, however, one global namespace accessible from all other name spaces. An eXPL name space is called a scope. A template is also a name space within a scope and thus there is a need to distiguish not only between scopes, but also between templates in the same scope. The answer is to have multi-part names consisting of identifiers separated by a period character eg. "freight.city" from a previous example.
Literals
Literals represent data values. Java syntax for literals is followed for strings and numbers, but character literals are not supported.
Sets of literals can be placed in {} braces next to a variable to indicate "match any any literal in the set".
Also used in eXPL are "true", "false", "unkown" and "NaN" (not a number).1
- Literals - "NaN" in any numeric calculation results in NaN.
Variables
A variable is set either at compilation of the eXPL script or during execution of a query. It's visibility depends on the context in which it is declared. Variables declared in the global scope are the most visible. A variable declared in one a template is visible in another template in the same scope by using a two-part name, the first part being the template name and the second part being the variable name eg. "account.name". Note that the topic of scopes appears toward the end of this reference because the majority of eXPL features can be demonstrated in the global scope.
Operators
eXPL follows Java's use of symbolic operators in expressions except the ternary operators ? : which still have a logic control role,
but are used separately and trigger a short circuit 1. Operator ? is
"short circuit on false" and operator : is "short circuit on true".
Java precedence also applies along with the use of parentheses to override precedence.
{} Set Selection
The {} operator is used to enclose a set of literals which defines the allowed values for an associated variable.
The logic is reversed by placing a ! character in front of the list.
See the EuropeanMegaCities application in tutorial 4 demonstrating the set operator used to select from
cities in continent Europe by eliminating all the other continents.
Regular Expressions
A regular expression matches text to a pattern and optionally collects portions of text referred to as groups. eXPL regular expressions are implemented using the Java Pattern class. Here is an example where a regular expression used with keyword regex to select words starting with "in":
regex word ? "^in[^ ]+", string definition);
The square brackets define a set of characters consisting of all characters except for a space. The pattern reads as "any sequence of characters which begin with "in" from the start of the input text up to the first space character". The above regular expression is demonstrated in the InWords application of tutorial4. The solution consists of a list of 54 "in" words and and their definitions. For more information, refer Regular Expressions
