Parser

parser grammar model;

options { tokenVocab=modelLexer; }

 

// Parser

model: MODEL model_name LBRACE partitions? modelRule* RBRACE EOF;

 

model_name: QUOTEDSTRING ;

partitions: PARTITIONS LBRACE partition* RBRACE ;

 

partition: PARTITION partition_name LBRACE feature_spec* RBRACE ;

partition_name: QUOTEDSTRING ;

 

feature_spec: feature_name feature_version amount vendor_match? ;

feature_name: QUOTEDSTRING ;

feature_version: major_version ( DOT minor_version )? ;

major_version: DIGIT+ ;

minor_version: DIGIT+ ;

amount: integer_amount | percentage_amount | REMAINDER ;

integer_amount: DIGIT+ ;

percentage_amount: DIGIT+ PERCENT ;

 

vendor_match: VENDOR STRING MATCHES match_string;

match_string: QUOTEDSTRING ;

 

modelRule: ON compound_matcher LBRACE rule_body RBRACE ;

 

compound_matcher: negatable_matcher compound_rhs* ;

 

compound_rhs: compound_and_rhs | compound_or_rhs ;

 

compound_and_rhs: (AND | C_AND) negatable_matcher ;

compound_or_rhs: (OR | C_OR) negatable_matcher ;

 

negatable_matcher: negated_matcher | simple_matcher ;

 

negated_matcher: (NOT | C_NOT) simple_matcher ;

 

simple_matcher: hostid_matcher | hostname_matcher | hosttype_matcher | vendor_dictionary_matcher | any_matcher ;

 

hostid_matcher: HOSTID LPAREN parameter_list RPAREN ;

hostname_matcher: HOSTNAME LPAREN parameter_list RPAREN ;

hosttype_matcher: HOSTTYPE LPAREN parameter_list RPAREN ;

vendor_dictionary_matcher: DICTIONARY LPAREN keyword_parameter_list RPAREN ;

any_matcher: ANY LPAREN RPAREN ;

 

parameter_list: parameter (COMMA parameter)* ;

parameter: QUOTEDSTRING ;

keyword_parameter_list: keyword_parameter (COMMA keyword_parameter)* ;

 

keyword_parameter: keyword_key COLON keyword_value ;

keyword_key: QUOTEDSTRING ;

keyword_value: WILDCARD | QUOTEDSTRING ;

 

rule_body: use_statement? server_specified? action? ;

use_statement: USE partition_name_list ;

 

server_specified: WITHOUT REQUESTED FEATURES LBRACE partition_server_specified | feature_server_specified RBRACE ;

 

partition_server_specified: ALL FROM partition_name_list ;

feature_server_specified: feature_spec* ;

 

partition_name_list: partition_name (COMMA partition_name)* ;

 

action: ACCEPT | DENY | CONTINUE ;