Syntax¶
The syntax for creating rules is based off of logical expressions evaluating to either True (matching) or False (non-matching). Rules support a small set of data types which can be defined as constants or resolved using the Python object on which the rule is being applied.
Rule Engine Type | Compatible Python Types |
BOOLEAN |
bool |
DATETIME |
datetime.date ,
datetime.datetime |
FLOAT |
int ,
float |
NULL |
NoneType |
STRING |
str |
Not all supported operations work with all data types as noted in the table below. Rules follow a standard order of operations.
Grammar¶
The expression grammar supports a number of operations including basic arithmetic for numerical data and regular expressions for strings. Operations are type aware and will raise an exception when an incompatible type is used.
Supported Operations¶
Operation | Description | Compatible Data Types |
Arithmetic Operators | ||
+ |
Addition | FLOAT |
- |
Subtraction | FLOAT |
* |
Multiplication | FLOAT |
** |
Exponent | FLOAT |
/ |
True division | FLOAT |
// |
Floor division | FLOAT |
% |
Modulo | FLOAT |
Bitwise-Arithmetic Operators | ||
& |
Bitwise-and 1 | FLOAT |
| |
Bitwise-or 1 | FLOAT |
^ |
Bitwise-xor 1 | FLOAT |
>> |
Bitwise right shift 1 | FLOAT |
<< |
Bitwise left shift 1 | FLOAT |
Comparison Operators | ||
== |
Equal to | ANY |
!= |
Not equal to | ANY |
Arithmetic-Comparison Operators | ||
> |
Greater than | DATETIME ,
FLOAT |
>= |
Greater than or equal to | DATETIME ,
FLOAT |
< |
Less than | DATETIME ,
FLOAT |
<= |
Less than or equal to | DATETIME ,
FLOAT |
Fuzzy-Comparison Operators | ||
=~ |
Regex match 2 | NULL ,
STRING |
=~~ |
Regex search 2 | NULL ,
STRING |
!~ |
Regex match fails 2 | NULL ,
STRING |
!~~ |
Regex search fails 2 | NULL ,
STRING |
Logical Operators | ||
and |
Logical and | ANY |
not |
Logical not | ANY |
or |
Logical or | ANY |
1 Bitwise operations support floating point values, but if the value is
not a natural number, an EvaluationError
will be
raised.
2 When using regular expression operations, the expression on the left is the string to compare and the expression on the right is the regular expression to use for either the match or search operation.
Reserved Keywords¶
Keyword | Description |
null |
The NullExpression literal value |
Booleans (BooleanExpression Literals) |
|
true |
The “True” boolean value |
false |
The “False” boolean value |
Floats (FloatExpression Literals) |
|
inf |
Floating point value for infinity |
nan |
Floating point value for not-a-number |
Logical Operators | |
and |
Logical “and” operator |
not |
Logical “not” operator |
or |
Logical “or” operator |