Parser

The rule validation parser file, "RuleValidationParser.g4" defines the parsing hierarchy that makes up the rule syntax. Note, order is important. The order of the parsing definitions below define precedence. Changing the order without expert knowledge of how the lexer-parser syntax is defined can and probably will break the rule validation.

Root level, note the lexer parser uses recursion to traverse the tree

exp
    : orExp
	| collectionExp
    ;

Logical Operations

orExp
    : andExp (OR andExp)*
    ;


andExp
    : notExp (AND notExp)*
    ;


notExp
    : NOT notExp
    | eqExp
    ;

Equality Operations

eqExp
    : cmpExp
    | cmpExp EQ cmpExp
    | cmpExp NE cmpExp
    ;

cmpExp
    : cntExp
    | cntExp LTE cntExp
    | cntExp GTE cntExp
    | cntExp LT cntExp
    | cntExp GT cntExp
    ;	

List and Collection Operations

cntExp
    : sumExp
    | sumExp CONTAINS sumExp
    | sumExp IN list
    | sumExp IN collectionExp
    ;

Arithmatic Operations

sumExp
    : prodExp ((PLUS|MINUS|CONCAT) prodExp)*
    ;

prodExp
    : atomExp ((TIMES|DIV|MOD) atomExp)*
    ;

Atomic Expressions

atomExp
    : LPAREN exp RPAREN
	| LPAREN comment exp RPAREN
    | list
    | funcExp
    | value
    ;

Function Expressions

funcExp
    : RETSNAME LPAREN (param (COMMA param)*)? RPAREN
    ;

Collection Expressions

collectionExp
  : (LIST | SET) LPAREN (exp (COMMA exp)*)? RPAREN
  | (UNION | INTERSECTION | DIFFERENCE) LPAREN (collectionExp COMMA collectionExp (COMMA collectionExp)*)? RPAREN
  | ARRAY LPAREN sumExp RPAREN
  ;

List Expressions

list
    : LPAREN (exp (COMMA exp)*)? RPAREN
    ;

Date / Time definitions

dateTimeValue : HASH dateTime HASH;


dateTime: RETS_DATETIME;

Parameters

param
    : exp
    ;

Values

value
    : specValue
    | charValue
    | intValue
    | floatValue
	| dateTimeValue
    | dateValue
	| timeValue
	| fieldName
    ;

specValue : DOT RETSNAME DOT;
charValue : QUOTED_TERM;

fieldName
     : (LAST)? FIELD_NAME
     | OPEN_BRACKET (LAST)? FIELD_NAME CLOSE_BRACKET
     ;

intValue : (PLUS|MINUS)? DIGIT+ ;
floatValue : intValue DOT DIGIT+;
timeValue : HASH RETSTIME HASH;
dateValue : HASH RETSDATE HASH;

Comments

ALPHA: ('a'..'z' | 'A'..'Z');
DIGIT: ('0'..'9');
ALPHANUM: ALPHA (ALPHA|DIGIT)*;
QUOTED_TERM
    :   QUOTE (~[\\"])*? QUOTE
    |   SQUOTE (~[\'])*? SQUOTE
    ;

Comments

comment : SLASH_STAR_COMMENT;
//lineComment : SLASH_SLASH_COMMENT;

Whitespace

WS : [ \t\n\r]+ -> skip ;