Skip to content

Predicate syntax

Maciej Klemarczyk edited this page Dec 15, 2024 · 8 revisions

Syntax tokens

  • { - 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]+ ']'
    ;

Available predicates

Binary predicates

  • HasFlag - checks that number contains binary flag (LeftArg & RightArg == RightArg)

Equality predicates

  • = - equals, two arguments are equal
  • != - unequal, two arguments are not equal (from 1.0.7)

Comparison predicates

  • < - 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

Conditional logical predicates

  • 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

Text predicates

  • IN - sub-text is part of text, second argument contains first argument

Predicate examples

  • {=, 31, 41} - Number 31 is equal to number 41
  • {=, $data, 12\,33\, 12} - Value of $data is equal to text 12,33, 12
  • {=, $data, 41} - Value of $data is equal to number 41
  • {AND, {=, $data, 42}, {=,$user,11}} - Value of $data is equal to number 42 and value of $user is equal to number 11
  • {OR, {=, $data, 42}, {=,$user,11}} - Value of $data is equal to number 42 or value of $user is equal to number 11

Variables

The variable syntax allows to inject value during evaluation

Array index

The array index syntax allows to access value from the array

Binary direct access

The array index syntax allows to access single bit from a numeric types

Variable examples

  • $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

Note

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.