Switch on result of getStateType

This commit is contained in:
Sam Harwell 2012-12-20 16:49:35 -06:00
parent f3f8b425c3
commit 1894017eb7
1 changed files with 17 additions and 10 deletions

View File

@ -179,25 +179,32 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy {
return;
}
if ( s instanceof PlusBlockStartState ||
s instanceof StarLoopEntryState ||
s instanceof BlockStartState )
{
switch (s.getStateType()) {
case ATNState.BLOCK_START:
case ATNState.STAR_BLOCK_START:
case ATNState.PLUS_BLOCK_START:
case ATNState.STAR_LOOP_ENTRY:
// report error and recover if possible
if ( singleTokenDeletion(recognizer)!=null ) return;
if ( singleTokenDeletion(recognizer)!=null ) {
return;
}
throw new InputMismatchException(recognizer);
}
if ( s instanceof PlusLoopbackState ||
s instanceof StarLoopbackState )
{
case ATNState.PLUS_LOOP_BACK:
case ATNState.STAR_LOOP_BACK:
// System.err.println("at loop back: "+s.getClass().getSimpleName());
reportUnwantedToken(recognizer);
IntervalSet expecting = recognizer.getExpectedTokens();
IntervalSet whatFollowsLoopIterationOrRule =
expecting.or(getErrorRecoverySet(recognizer));
consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
break;
default:
// do nothing if we can't identify the exact kind of ATN state
break;
}
// do nothing if we can't identify the exact kind of ATN state
}
public void reportNoViableAlternative(Parser recognizer,