Extension:Expressions

The Expressions extension enhances the wikitext parser with boolean algebra.

Usage
This extension introduces the parser function #expression. It evaluates an expression and returns one of two strings depending on the result:



The available operators are listed below, in order of precedence. The extension makes use of type conversion when comparing two values. Non-empty strings are converted to, zero is converted to  , and any integers that are not zero get converted to.


 * → 1
 * → 1
 * → 1
 * → 1
 * → 0

Two values can be compared before type juggling using the strict equality operator :


 * → 1
 * → 0

Operator associativity
Operator associativity determines how operators of the same precedence are grouped in the absence of parentheses. If a value (operand) is both preceded and followed by operators of the same precedence (for example ), then the value can be applied to two different operations. Operator associativity determines which of those operations gets chosen.

All operators in the Expressions extension are left-associative. This means that all operators are grouped from left to right.


 * →  →   →   → 1
 * →  →   → 0

The resulting behaviour might not be what you expect at first, therefore it is important to keep it in mind.

Type operators
Some operators are strictly typed and require their operand(s) to be of a certain type or else an error will occur. The table below lists all typed operators with their required type(s).

When something other than the required type is used, the evaluator will throw an exception.

Operators
The table below lists all operators, in order of precedence from highest to lowest. Operands of the same type have identical precedence. Operations applied by operators of higher precedence will be evaluated first.