BailErrorStrategy propagates the RecognitionException to the current rule context and it's parents

This commit is contained in:
Sam Harwell 2012-08-21 13:16:09 -05:00
parent 1155c40fc8
commit 4508f96ce4
1 changed files with 10 additions and 1 deletions

View File

@ -40,6 +40,10 @@ public class BailErrorStrategy extends DefaultErrorStrategy {
*/
@Override
public void recover(Parser recognizer, RecognitionException e) {
for (ParserRuleContext<?> context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new RuntimeException(e);
}
@ -50,7 +54,12 @@ public class BailErrorStrategy extends DefaultErrorStrategy {
public Token recoverInline(Parser recognizer)
throws RecognitionException
{
throw new RuntimeException(new InputMismatchException(recognizer));
InputMismatchException e = new InputMismatchException(recognizer);
for (ParserRuleContext<?> context = recognizer.getContext(); context != null; context = context.getParent()) {
context.exception = e;
}
throw new RuntimeException(e);
}
/** Make sure we don't attempt to recover from problems in subrules. */