Rule 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 Data Type

Compatible Python Types

ARRAY

list, tuple

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

The following keywords are reserved and can not be used as the names of symbols.

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

Membership Operators

in

Checks member is in the container

Literal Values

STRING and DATETIME literal values are specified in a very similar manner by defining the value as a string of characters enclosed in either single or double quotes. The difference comes in an optional leading character before the opening quote. Either no leading character or a single s will specify a standard STRING value, while a single d will specify a DATETIME value.

DATETIME literals must be specified in ISO-8601 format. The underlying parsing logic is provided by dateutil.parser.isoparse(). DATETIME values with no time specified (e.g. d"2019-09-23") will evaluate to a DATETIME of the specified day at exactly midnight.

Example rules showing equivalent literal expressions:

  • "foobar" == s"foobar"

  • d"2019-09-23" == d"2019-09-23 00:00:00"

FLOAT literals may be expressed in either binary, octal, decimal, or hexadecimal formats. The binary, octal and hexadecimal formats use the 0b, 0o, and 0x prefixes respectively. Values in the decimal format require no prefix and is the default base in which values are represented. Only base-10, decimal values may include a decimal place component.

Example rules showing equivalent literal expressions:

  • 0b10 == 2

  • 0o10 == 8

  • 10.0 == 10

  • 0x10 == 16

FLOAT literals may also be expressed in scientific notation using the letter e.

Example rules show equivalent literal expressions:

  • 1E0 == 1

  • 1e0 == 1

  • 1.0e0 == 1