ANTLRErrorStrategy.sync and recover can throw a RecognitionException, but not reportError
This commit is contained in:
parent
70452f7e4b
commit
56e49fdc38
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue