Expression Pattern Language (eXPL)

eXPL Exressions

Expressions are the means for specifying relationships and transforming data.

Operators

All the Java operators are supported except for shift operators and the ternary operator. Java precedence also applies along with the use of parentheses to override precedence. A new type of operation called "short circuiting" is also introduced which forces an exit from unification based on evaluation of a binary expression. The Java ternary symbols "?" and ":" are reassigned for short circuiting with operator ? used for "short circuit on false" and operator : (colon) "short circuit on true".

Types

eXPL Type Example
string "Australia"
integer 16498
double 11230.9845
boolean true
decimal 2.00
currency $1234.56

Text literals are represented by type string and used to match axiom strings to tempate strings.1

integer, double and boolean are the same as Java primitive types long, double and boolean respectively, and are implementented as Java Object-wrappers.

decimal and currency are an arbitrary-precision signed decimal numbers (implemented as Java class java.math.BigDecimal). The currency type is suited for financial transactions. For more details, go to Currency.

Following unification, a template term may contain an object of unknown type. Such a term cannot be used in expressions, except for assignment.

Literals

Literal terms are constants. Java literals are used for strings and numbers, but character literals are not supported. Single quotes are used to delimit formated numbers eg '1,234,567' for 1234567. Sets of literals can be placed in {} braces next to a template variable to indicate "match any any literal in the set". Also used in eXPL are "true", "false", "unkown" and "NaN" (not a number).2

Identifers

Most of the language components, including axioms, templates and variables need an identity for which the Java naming convention is applied: identifiers begin with an alpha character which is followed by any number of alpha or numeric characters or underscore. The convention used in the reference is to use all lower-case names, with words separated by underscores. This gives the eXPL scripts a look which is distinctively and deliberately different from Java.

  1. Strings - Backslash '\' is used as an escape character the same as in Java.
  2. Literals - "NaN" in any numeric calculation results in NaN.

Variables

A variable is an identifiable value container. It may be assigned an initial value by the script in which it is declared. A variable is expected to be assigned a value by the time it participates in expression evaluation and if found empty, the query will fail. A variable declared within a template is accessed from another template by using a two-part name, the first part being the template name and the second part being the variable name eg. "account.name".

Type Conversion

Caution is required when forming expressions containing incompatiple types. The compilier will attempt to resolve such conflicts using type convsersion during evaluation, but the result may be not as expected. The type conversion strategy minimises loss of information. For example, when a decimal is paired with an integer in an operation then the integer is converted to a decimal before performing the operation. Explicit type conversion can be achieved by assigning values to typed template terms. Type casting is not supported.

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 of regular expression "^in[^ ]+" used in a template to select words starting with in:

template in_words (
  word regex("^in[^ ]+"),
  string definition);

You can see that the regular expression is placed in parentheses and preceded with the keyword regex. The template generates a list of "in" words and and their definitions. For more information, refer Regular Expressions The above regular expression is demonstrated in the tutorial4 InWords code example.

Examples

To see a demonstration of some expressions run the tutorial4 Expressions code example. Here are the expressions being tested:

integer x = 1;
integer y = 2;
x + y == 3,
y - x == 1,
x * y == 2,
6 / y == 3,
(y + 1) * 2 > x * 5,
(y *= 3) == 6 && y == 6

You can add your own torturous expressions to put eXPL through it's paces.