Handle end of stream at the top-level rule
When we've reached the stop state of a top-level rule (invokingState = -1),
add EOF as a candidate token.
@@ -159,8 +159,13 @@ class ErrorHandler
if (parsingState.state instanceof RuleStopState) {
if (next != null) {
+ if (next.invokingState == -1) {
+ candidates.putAll(tokenIndex, getTokenNames(IntervalSet.of(Token.EOF)));
+ }
+ else {
process(((RuleTransition) atn.states.get(next.invokingState).transition(0)).followState, parsingState.tokenIndex, next.parent);
}
+ }
continue;
}
