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 juggling when comparing two values. Therefore, non-empty strings are converted to, zero is converted to  , et cetera:


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

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


 * → 1
 * → 0
 * → 0

You can read more about type juggling here.

Associativity
All binary operators in Expressions are left-associative. This means the left part of the expression will be evaluated first:


 * →  → 1
 * →  → 0

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

Type operators
Some operators in Expressions are strictly typed. This means they 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:

I got stuck at the following expression:

1| "foo" > 420 ^^^^^ I was expecting to see a `double` at the highlighted token, but instead I got a `string`.

Operators
The table below lists all operators, in order of precedence.