-
Notifications
You must be signed in to change notification settings - Fork 0
Predicate syntax
Maciej Klemarczyk edited this page Dec 15, 2024
·
8 revisions
-
{- Predicate opening -
}- Predicate closing -
,- Argument separator -
$data- External variable -
\- Token escape, treats syntax characters as part of the text
Predicate_Expression
: Predicate | Predicate_Group
;
fragment Predicate_Group
: '{' Predicate '}'
;
fragment Predicate
: Predicate_Operand Predicate_Argument+
;
fragment Predicate_Operand
: 'HasFlag' | '=' | '<' | '<=' | '>' | '>=' | 'NOT' | 'OR' | 'AND' | 'IN'
;
fragment Predicate_Argument
: ',' (Constant | Variable | Predicate_Group)
;
fragment Constant
: (Constant_Text | Constant_Number)
;
fragment Constant_Text
: [a-zA-Z0-9]+
;
fragment Constant_Number
: [0-9\.]+
;
fragment Variable
: '$' Variable_Name Array_Index*
;
fragment Variable_Name
: [a-zA-Z0-9]+
;
fragment Array_Index
: '[' [0-9]+ ']'
;
-
HasFlag- checks that number contains binary flag(LeftArg & RightArg == RightArg)
-
=- equals, two arguments are equal -
!=- unequal, two arguments are not equal (from 1.0.7)
-
<- less than, first argument is less than second argument -
>- greater than, first argument is greater than second argument -
<=- less than or equal, first argument is less than or equal to second argument -
>=- greater than or equal, first argument is greater than or equal to second argument
-
NOT- inverts logical value, changes True to False, and False to True -
OR- combines two or more predicates, where one of predicates has to be True -
AND- combines two or more predicates, where all of predicates has to be True
-
IN- sub-text is part of text, second argument contains first argument
-
{=, 31, 41}- Number31is equal to number41 -
{=, $data, 12\,33\, 12}- Value of $data is equal to text12,33, 12 -
{=, $data, 41}- Value of $data is equal to number41 -
{AND, {=, $data, 42}, {=,$user,11}}- Value of $data is equal to number42and value of $user is equal to number11 -
{OR, {=, $data, 42}, {=,$user,11}}- Value of $data is equal to number42or value of $user is equal to number11
The variable syntax allows to inject value during evaluation
The array index syntax allows to access value from the array
The array index syntax allows to access single bit from a numeric types
-
$content- use value of content variable for evaluation -
$users[4]- access the user under index 4 and use it for evaluation -
$items[12][31]- access the items under index 31 of item under index 12 and use it for evaluation -
$permission[3]- access the 4th bit counting from the right, for number 43 (101011) it will return 1
All comparisons are done using string type. Next version expects to compare values using type specific methods. The comparison for the NOT operator ignores the case of characters.