protected void reportInputMismatch(final Parser recognizer, final InputMismatchException e) { final String msg = "Syntax error. There is a mismatch between the expected term and te term in the query. " + "Please check the line and column in the query."; recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
public void reportError(final Parser recognizer, final RecognitionException e) { if (!this.inErrorRecoveryMode(recognizer)) { this.beginErrorCondition(recognizer); if (e instanceof NoViableAltException) { this.reportNoViableAlternative(recognizer, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { this.reportInputMismatch(recognizer, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { this.reportFailedPredicate(recognizer, (FailedPredicateException) e); } else { System.err.println("unknown recognition error type: " + e.getClass().getName()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } } }
protected void reportMissingToken(final Parser recognizer) { if (!this.inErrorRecoveryMode(recognizer)) { this.beginErrorCondition(recognizer); final Token t = recognizer.getCurrentToken(); final IntervalSet expecting = this.getExpectedTokens(recognizer); final String msg = "missing " + expecting.toString(recognizer.getVocabulary()) + " at " + this .getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, (RecognitionException) null); } } }
protected void reportUnwantedToken(final Parser recognizer) { if (!this.inErrorRecoveryMode(recognizer)) { this.beginErrorCondition(recognizer); final Token t = recognizer.getCurrentToken(); final String tokenName = this.getTokenErrorDisplay(t); final IntervalSet expecting = this.getExpectedTokens(recognizer); final String msg = "extraneous input " + tokenName + " expecting " + expecting.toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(t, msg, (RecognitionException) null); } }
protected void reportNoViableAlternative(final Parser recognizer, final NoViableAltException e) { final TokenStream tokens = recognizer.getInputStream(); final String input; if (tokens != null) { if (e.getStartToken().getType() == -1) { input = "<EOF>"; } else { input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } } else { input = "<unknown input>"; } final String msg = "no viable alternative at input " + this.escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
public final void notifyErrorListeners(String msg) { notifyErrorListeners(getCurrentToken(), msg, null); }
@Override public void reportAttemptingFullContext(Parser recognizer, DFA dfa, int startIndex, int stopIndex, BitSet conflictingAlts, ATNConfigSet configs) { String format = "reportAttemptingFullContext d=%s, input='%s'"; String decision = getDecisionDescription(recognizer, dfa); String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)); String message = String.format(format, decision, text); recognizer.notifyErrorListeners(message); }
@Override public void reportContextSensitivity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, int prediction, ATNConfigSet configs) { String format = "reportContextSensitivity d=%s, input='%s'"; String decision = getDecisionDescription(recognizer, dfa); String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)); String message = String.format(format, decision, text); recognizer.notifyErrorListeners(message); }
@Override public void reportAmbiguity(Parser recognizer, DFA dfa, int startIndex, int stopIndex, boolean exact, BitSet ambigAlts, ATNConfigSet configs) { if (exactOnly && !exact) { return; } String format = "reportAmbiguity d=%s: ambigAlts=%s, input='%s'"; String decision = getDecisionDescription(recognizer, dfa); BitSet conflictingAlts = getConflictingAlts(ambigAlts, configs); String text = recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)); String message = String.format(format, decision, conflictingAlts, text); recognizer.notifyErrorListeners(message); }
/** * This is called by {@link #reportError} when the exception is a * {@link FailedPredicateException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportFailedPredicate(Parser recognizer, FailedPredicateException e) { String ruleName = recognizer.getRuleNames()[recognizer._ctx.getRuleIndex()]; String msg = "rule "+ruleName+" "+e.getMessage(); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
/** * This is called by {@link #reportError} when the exception is an * {@link InputMismatchException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportInputMismatch(Parser recognizer, InputMismatchException e) { String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+ " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
/** * This method is called to report a syntax error which requires the * insertion of a missing token into the input stream. At the time this * method is called, the missing token has not yet been inserted. When this * method returns, {@code recognizer} is in error recovery mode. * * <p>This method is called when {@link #singleTokenInsertion} identifies * single-token insertion as a viable recovery strategy for a mismatched * input error.</p> * * <p>The default implementation simply returns if the handler is already in * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to * enter error recovery mode, followed by calling * {@link Parser#notifyErrorListeners}.</p> * * @param recognizer the parser instance */ protected void reportMissingToken(Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "missing "+expecting.toString(recognizer.getVocabulary())+ " at "+getTokenErrorDisplay(t); recognizer.notifyErrorListeners(t, msg, null); }
/** * This method is called to report a syntax error which requires the removal * of a token from the input stream. At the time this method is called, the * erroneous symbol is current {@code LT(1)} symbol and has not yet been * removed from the input stream. When this method returns, * {@code recognizer} is in error recovery mode. * * <p>This method is called when {@link #singleTokenDeletion} identifies * single-token deletion as a viable recovery strategy for a mismatched * input error.</p> * * <p>The default implementation simply returns if the handler is already in * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to * enter error recovery mode, followed by calling * {@link Parser#notifyErrorListeners}.</p> * * @param recognizer the parser instance */ protected void reportUnwantedToken(Parser recognizer) { if (inErrorRecoveryMode(recognizer)) { return; } beginErrorCondition(recognizer); Token t = recognizer.getCurrentToken(); String tokenName = getTokenErrorDisplay(t); IntervalSet expecting = getExpectedTokens(recognizer); String msg = "extraneous input "+tokenName+" expecting "+ expecting.toString(recognizer.getVocabulary()); recognizer.notifyErrorListeners(t, msg, null); }
/** * This is called by {@link #reportError} when the exception is a * {@link NoViableAltException}. * * @see #reportError * * @param recognizer the parser instance * @param e the recognition exception */ protected void reportNoViableAlternative(Parser recognizer, NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input; if ( tokens!=null ) { if ( e.getStartToken().getType()==Token.EOF ) input = "<EOF>"; else input = tokens.getText(e.getStartToken(), e.getOffendingToken()); } else { input = "<unknown input>"; } String msg = "no viable alternative at input "+escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
@Override public void reportError(Parser recognizer, RecognitionException e) { if (!(e instanceof BatfishRecognitionException)) { recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }
@Override public void reportFailedPredicate(Parser parser, FailedPredicateException e) { parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()), getException("FailedPredicate", parser)); }
@Override public void reportNoViableAlternative(Parser parser, NoViableAltException e) throws RecognitionException { parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()), getException("NoViableAlternative", parser)); }
@Override public void reportNoViableAlternative(Parser parser, NoViableAltException e) throws RecognitionException { parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()), getException("NoViableAlternative", parser)); }
@Override public void reportInputMismatch(Parser parser, InputMismatchException e) { parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()), getException("InputMismatch", parser)); }