This is essentially the same as the OGRE expression language, with the following changes:

  1. The reference tag $R has been eliminated, with variables and properties generalized to $.
  2. The index tag $I has been generalized to include keys to a Map.

TAG

TYPE

${...}

Reference

$C{...}

Constant

$E{...}

Logico-Arithmetic Expression

$G{...}

Global Reference

$I{...}

Index to Array-like Reference, or Key to Map

$L{...}

Literal

Except for restrictions on the placement of index tags (they must be inside a reference and cannot be nested inside other tags), all of these are nestable within one another and to an arbitrary depth. Some simpler examples:

  • Example 1 $E{ ${j} > ${currentValue_${k}} }

The value returned here would be of type java.lang.Boolean; the value of k would be appended to 'currentValue_' and this string used as the name of another reference which should correspond to a stored numerical value; the value of j would then be compared to it.

  • Example 2 $C{$E{ 1 + ${sizeOfVector} }}

The attribute with this value remains constant after the first evaluation.

  • Example 3 $L{$E{ 1 + ${sizeOfVector} }}

Evaluates to '$E{ 1 + ${sizeOfVector} }'.

  • Example 4 ${container$I{${i}}$I{${j}}}

${container} must represent some indexable object with two levels of indices; depending on what these objects actually dereference to, the two indices ${i} and ${j} could be numerical (implying an array-like structure) or keys (most commonly strings) to a map-like structure. Note that mixing of the two is possible; i.e., one could have an array of maps, a map with lists, etc.

Notice that if the string is a single reference or expression (i.e., '${ ........... }' or '$E{ ........... }'), then the value returned may be an object; otherwise, the value returned by any embedded reference or expression (e.g., '... ${ ... } ...') will be converted to a string, with all such substrings finally concatenated. Hence, composite tags at the top level (e.g., '${ ... }${ ... }$E{ ... }', etc.) will always return a string.

$E{...} denotes an infix-expression evaluating to either a java.lang.Long, a java.lang.Double or a java.lang.Boolean, and having the following constraints:

  1. all operators and operands must be white-space delimited (but unary -/+ should remain attached to its argument)
  2. any of the Java operators except: ternary condition ' ? : ', cast, instanceof, assignment (++ and - here are merely shorthand for + 1 and - 1, with no side-effecting implied)
  3. any of the functions available from java.lang.Math; parameters must be comma-delimited inside the parentheses
  4. any numeric operand
  5. pi, e
  6. true, false

The resulting string is not type-checked, but loose parenthesis matching is enforced (e.g., '( 1 * ( 2 - 3 )' or '( 1 * ( 2 - 3 ) ) )' will be rejected, but '( ) ( 1 * ( 2 - 3 ) )' will be accepted, with the empty parentheses simply ingored).

XML Escaped Characters

When coding expressions, the greater-than ('>') and less-than ('<') characters should be escaped to > and <.


An example, with output, of expressions, constants and literals, using a for container task:


<ogrescript strict="true">
	<for var="i" from="0" to="10">
	   <echo stdout="true" message="******************** ${i} ********************"/>
		<echo stdout="true" message="the expression value is $E{ 10 * ( ${i} + 1 ) }"/>
		<echo stdout="true" message="the constant value is $C{$E{ 10 * ( ${i} + 1 ) }}"/>
		<echo stdout="true" message="the literal value is '$L{$E{ 10 * ( ${i} + 1 ) }}'"/>
	</for>
	<echo stdout="true" message="********************************************"/>
</ogrescript>

OUTPUT:

******************* 0 *******************
the expression value is 10
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 1 *******************
the expression value is 20
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 2 *******************
the expression value is 30
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 3 *******************
the expression value is 40
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 4 *******************
the expression value is 50
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 5 *******************
the expression value is 60
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 6 *******************
the expression value is 70
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 7 *******************
the expression value is 80
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 8 *******************
the expression value is 90
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 9 *******************
the expression value is 100
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
******************* 10 *******************
the expression value is 110
the constant value is 10
the literal value is '$E{ 10 * ( ${i} + 1 ) }'
********************************************

  • No labels