From 56e49fdc38fd838d468ef60cdffeef212f2bdc3d Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Tue, 26 Mar 2013 15:39:22 -0500 Subject: [PATCH] ANTLRErrorStrategy.sync and recover can throw a RecognitionException, but not reportError --- .../src/org/antlr/v4/runtime/ANTLRErrorStrategy.java | 9 +++++---- .../src/org/antlr/v4/runtime/DefaultErrorStrategy.java | 6 +----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/ANTLRErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/ANTLRErrorStrategy.java index c45285b18..fbcc3239d 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/ANTLRErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/ANTLRErrorStrategy.java @@ -87,7 +87,8 @@ public interface ANTLRErrorStrategy { * use to recover better. */ void recover(@NotNull Parser recognizer, - @NotNull RecognitionException e); + @NotNull RecognitionException e) + throws RecognitionException; /** Make sure that the current lookahead symbol is consistent with * what were expecting at this point in the ATN. You can call this @@ -116,7 +117,8 @@ public interface ANTLRErrorStrategy { * turn off this functionality by simply overriding this method as * a blank { }. */ - void sync(@NotNull Parser recognizer); + void sync(@NotNull Parser recognizer) + throws RecognitionException; /** Is the parser in the process of recovering from an error? Upon * a syntax error, the parser enters recovery mode and stays there until @@ -136,6 +138,5 @@ public interface ANTLRErrorStrategy { /** Report any kind of RecognitionException. */ void reportError(@NotNull Parser recognizer, - @NotNull RecognitionException e) - throws RecognitionException; + @NotNull RecognitionException e); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java index 9dfa5d0eb..12be5122c 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java +++ b/runtime/Java/src/org/antlr/v4/runtime/DefaultErrorStrategy.java @@ -114,7 +114,6 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { @Override public void reportError(Parser recognizer, RecognitionException e) - throws RecognitionException { // if we've already reported an error and have not matched a token // yet successfully, don't report any errors. @@ -185,7 +184,7 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { * We opt to stay in the loop as long as possible. */ @Override - public void sync(Parser recognizer) { + public void sync(Parser recognizer) throws RecognitionException { ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState()); // System.err.println("sync @ "+s.stateNumber+"="+s.getClass().getSimpleName()); // If already recovering, don't try to sync @@ -232,7 +231,6 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) - throws RecognitionException { TokenStream tokens = recognizer.getInputStream(); String input; @@ -249,7 +247,6 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { public void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e) - throws RecognitionException { String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+ " expecting "+e.getExpectedTokens().toString(recognizer.getTokenNames()); @@ -258,7 +255,6 @@ public class DefaultErrorStrategy implements ANTLRErrorStrategy { public void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e) - throws RecognitionException { String ruleName = recognizer.getRuleNames()[recognizer._ctx.getRuleIndex()]; String msg = "rule "+ruleName+" "+e.getMessage();