My grammar looks like this (simplified to show the issue):
parse
: block EOF
;
block
: TYPE1 OPAR STRING CPAR type1_statement_block
| TYPE2 OPAR STRING CPAR type2_statement_block
;
type1_statement_block
: OBRACE function1+ CBRACE
;
function1
: FUNCTIONNAME1 OPAR (parameter (',' parameter)*)? CPAR
;
FUNCTIONNAME1 : 'COMMAND1';
type2_statement_block
: OBRACE function2+ CBRACE
;
function2
: FUNCTIONNAME2 OPAR (parameter (',' parameter)*)? CPAR
;
FUNCTIONNAME2 : 'COMMAND1' | 'COMMAND2'
parameter
: INT
;
OPAR : '(';
CPAR : ')';
OBRACE : '{';
CBRACE : '}';
TYPE1 : 'TYPE1';
TYPE2 : 'TYPE2';
INT
: [0-9]+
;
STRING
: '"' (~["\r\n] | '""')* '"'
;
SPACE
: [ \t\r\n] -> skip
;
ErrChar
: .
;
Parsing the following strings works fine:
TYPE1 ("abc") { COMMAND1(0) }
TYPE2 ("abc") { COMMAND2(0) }
However parsing the following string results in an error
TYPE2 ("abc") { COMMAND1(0) }
I get "mismatched input 'COMMAND1' expecting FUNCTIONNAME2"
How can I get this scenario to work? I.e. that both code block can contain the same function name?