fragment EXEC : ('E' 'X' 'E' 'C');
fragment CMD : ('C' 'M' 'D');
fragment BEGIN : ('B' 'E' 'G' 'I' 'N');
fragment END : ('E' 'N' 'D');
fragment SEMICOLON : ';';
ExecCommand : EXEC Whitespace CMD Whitespace BEGIN WhiteSpace? SEMICOLON ( options {greedy=false;} : . )* END Whitespace EXEC;
Begin : BEGIN;
End : END;
Exec : EXEC;
The ExecCommand rule terminates the scan on the first 'E' following the Semicolon and then fails if the next characters are not 'END'. The scan should only terminate on 'END' and not for 'ELSE' or any other string beginning with 'E'.
The scan loop has a test for _LA(1) == 'E' instead of match('END').
Exec, Begin and End are also token rules. The ExecCommand rule is the first rule in the lexer grammar so it should have precedence.
How do I generate a rule that will accept any arbitrary text between the start and end symbols and not terminate until the end symbol is found?
I tried the following and it did not generate successfully: ExecCommand : EXEC Whitespace CMD Whitespace BEGIN WhiteSpace? SEMICOLON ( options {greedy=false;} : ~(END Whitespace EXEC) )* END Whitespace EXEC;