rule_file : package? import* expander* global* funtion* query* rule* ; package : 'package' WS ID WS? ';'? ; import : 'import' WS class WS? ';'? ; expander: 'expander' WS ID '.dsl' WS? ';'? ; global : 'global' WS class WS ID WS? ';'? ; function: (function_import|function_declaration) ; query : 'query' WS ID WS? ('(' arguments ')')? WS LHS WS 'end' ; rule : 'rule' WS ID WS atributes WS 'when' WS LHS WS 'then' WS RHS WS 'end' ; function_import : 'import' WS 'function' WS class WS? ';'? ; function_declaration : ('function' WS ID WS ID '(' (WS|arguments)? ')' '{' java_code '}') ; arguments : WS? (ID WS ID ',' WS?)* (ID WS ID) WS? ; class : (ID '.')* ID ; java_code : //załączenie innej gramatyki ; atributes : ('no-loop' WS BOOLEAN WS? ';'?)? ('lock-on-active' WS BOOLEAN WS? ';'?)? ('salience' WS INTEGER WS? ';'?)? ('agenda-group' WS STRING WS? ';'?)? ('auto-focus' WS BOOLEAN WS? ';'?)? ('ruleflow-group' WS STRING WS? ';'?)? ('activation-group' WS STRING WS? ';'?)? ('dialect' WS STRING WS? ';'?)? ('date-effective' WS STRING WS? ';'?)? ('date-expires' WS STRING WS? ';'?)? ('enabled' WS BOOLEAN WS? ';'?)? ('duration' WS INTEGER)? ; LHS : conditionals|(conditional_element*) ; conditionals : prefix_and|infix_and|prefix_or|eval|not|exists|forall|from|collect|accumulate|conditionals_group|conditional_element WS? ; prefix_and : '(' WS? 'and' WS conditionals (WS? conditionals)* WS? ')' ; infix_and : ('(' WS? conditionals (WS 'and' WS conditionals)* WS? ')')|(WS? conditionals (WS 'and' WS conditionals)* WS?) ; prefix_or : binding? '(' WS? 'or' WS conditionals (WS? conditionals)* WS? ')' ; infix_or: binding? ('(' WS? conditionals (WS 'or' WS conditionals)* WS? ')')|(WS? conditionals (WS 'or' WS conditionals)* WS?) ; eval : 'eval(' WS? expression WS? ')' ; not : 'not' (WS? '(' WS? conditionals WS? ')')|(WS conditionals) ; exists : 'exists' (WS? '(' WS? conditionals WS? ')')|(WS conditionals) ; forall : 'forall' WS? '(' WS? (pattern)* ')' ; from : pattern 'from' WS expression ; collect : patter 'from' WS 'collect' WS? '(' WS? pattern|from|collect|accumulate WS? ')' ; accumulate : patter 'from' WS 'collect' WS? '(' WS? pattern|from|collect|accumulate WS? ',' WS? (accumulate_function)|(init WS? ',' WS? action WS? ',' WS? (reverse WS? ',' WS? )? result) WS? ')' ; accumulate_function : 'average'|'min'|'max'|'count'|'sum' '(' WS? expression WS? ')' ; init : 'init(' WS? java_code WS? ')' ; action : 'action(' WS? java_code WS? ')' ; reverse : 'reverse(' WS? java_code WS? ')' ; result : 'result(' WS? expression WS? ')' ; conditionals_group : '(' WS? conditionals WS? ')' ; conditional_element : pattern ; pattern : binding? ID WS? '(' WS? constraints? WS? ')' WS? ; binding : '$'? ID WS? ':' WS? ; constraints : constraint (WS? constraint_connective WS? constraint WS?)* ; constraint_connective : ','|'&&'|'||' ; constraint : field_constraint|inline_eval_constraint|constraint_group ; constraint_group : '(' WS? constraints WS? ')' ; inline_eval_constraint : eval ; field_constraint : binding? ID WS? restriction ; restriction : single_value_restriction|compound_value_restriction|multi_restriction ; single_value_restriction : literal_restriction|variable_restriction|return_value_restriction|qualified_identifier_restriction ; literal_restriction : WS? operator WS? literal ; variable_restriction : WS? operator WS? '$'? ID ; return_value_restriction : WS? operator WS? '(' WS? return_value WS? ')' ; qualified_identifier_restriction : WS? operator WS? class ; literal : INTEGER|DATE|STRING|BOOLEAN ; operator: '<'|'<='|'>'|'>='|'=='|'!='|(WS 'contains'|'not contains'|'memberof'|'not memberof'|'matches'|'not matches' WS) ; return_value : '(' WS? expression WS? ')' ; expression : //dopisac ; compound_value_restriction : WS 'in'|not in' WS? '(' WS? literal|('$'? ID)|return_value|class (WS? ',' WS? literal|('$'? ID)|return_value|class)* WS? ')' ; multi_restriction : WS? restriction|group_restriction (WS? '&&'|'||' restriction|group_restriction)* WS? ; group_restriction : '(' multi_restriction ')' ; RHS : java_code ; WS : (' '|'\r'|'\n'|'\t')+ ; ID : ('a'..'z'|'A'..'Z'|'0'..'9'|'_')+ ; COMMENT : '/*' ( . )* '*/' ; LINE_COMMENT : ('//'|'#') ~('\n'|'\r')* EOL ; EOL : '\r'? '\n' ; BOOLEAN : ('true'|'false') ; INTEGER : ('0'..'9')+ ; STRING : '"' ~('"')* '"' ; DATE : '"' DZIEN '-' MIESIAC '-' ROK '"' ; CYFRA : '0'..'9' ; LITERA : 'a'..'z'|'A'..'Z' ; DZIEN : '1'|'2'|'3'|'4'|'5'|'6'|'7'|'8'|'9'|'10'|'11'|'12'|'13'|'14'|'15'|'16'|'17'|'18'|'19'|'20'|'21'|'22'|'23'|'24'|'25'|'26'|'27'|'28'|'29'|'30'|'31' ; MIESIAC : 'Jan'|'Feb'|'Mar'|'Apr'|'May'|'Jun'|'Jul'|'Aug'|'Sep'|'Oct'|'Nov'|'Dec' ; ROK : CYFRA CYFRA CYFRA CYFRA ;