The following grammar does not work properly with Antlr4.5 and Java 1.8.45 (IDE: IntelliJ Ultimate 14.1.4):
grammar PlayerAIShots;
file : row row EOF ;
row : START (randomshot)? SPACE direction Dot (LineBreak | EOF);
randomshot: RANDOM ;
direction : DIRECTION ;
RANDOM : 'randomly' ;
DIRECTION : ('to the left'|'to the right'|'central') ;
START : 'The opponent shoots' ;
SPACE : ' ' ;
Dot : '.' ;
// line break
LineBreak : '\r'?'\n' | '\r';
WS : [\t\r\n]+ -> skip ; // skip tabs, newlines
Letting the generated lexer and parser being evaluated results to:
line 1:22 mismatched input 'randomly' expecting DIRECTION
In the used data (text file) the second line was properly processed, but as in the above stated error message not the first one. Here is the text file being used:
The opponent shoots randomly to the left.
The opponent shoots to the right.
Removing those SPACE within the definition of "row" the error does not occur. Why?