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); } }
@Override public String toString() { return set.toString(); } }
@Override public String toString() { return toString(false); }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { return toString(VocabularyImpl.fromTokenNames(tokenNames)); }
/** Used for debugging in adaptivePredict around execATN but I cut * it out for clarity now that alg. works well. We can leave this * "dead" code for a bit. */ public void dumpDeadEndConfigs(NoViableAltException nvae) { System.err.println("dead end configs: "); for (ATNConfig c : nvae.getDeadEndConfigs()) { String trans = "no edges"; if ( c.state.getNumberOfTransitions()>0 ) { Transition t = c.state.transition(0); if ( t instanceof AtomTransition) { AtomTransition at = (AtomTransition)t; trans = "Atom "+getTokenName(at.label); } else if ( t instanceof SetTransition ) { SetTransition st = (SetTransition)t; boolean not = st instanceof NotSetTransition; trans = (not?"~":"")+"Set "+st.set.toString(); } } System.err.println(c.toString(parser, true)+":"+trans); } }
/** * 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); }
@Override public String toString() { return set.toString(); } }
@Override public String toString() { return set.toString(); } }
/** * 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); }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { return toString(VocabularyImpl.fromTokenNames(tokenNames)); }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { return toString(VocabularyImpl.fromTokenNames(tokenNames)); }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { return toString(VocabularyImpl.fromTokenNames(tokenNames)); }
/** * @deprecated Use {@link #toString(Vocabulary)} instead. */ @Deprecated public String toString(String[] tokenNames) { return toString(VocabularyImpl.fromTokenNames(tokenNames)); }
@Override public Token recoverInline(final Parser recognizer) throws RecognitionException { final Token token = recognizer.getCurrentToken(); final String message = "unexpected token [" + getTokenErrorDisplay(token) + "]" + " was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "]."; Location location = new Location(sourceName, token.getStartIndex()); throw location.createError(new IllegalArgumentException(message)); }
@Override public void reportInputMismatch(Parser parser, InputMismatchException e) { setErrorState(parser); Token offendingToken = e.getOffendingToken(); String mismatchedToken = getTokenErrorDisplay(offendingToken); String expectedToken = e.getExpectedTokens().toString(parser.getVocabulary()); DiagnosticPos pos = getPosition(offendingToken); dlog.error(pos, DiagnosticCode.MISMATCHED_INPUT, mismatchedToken, expectedToken); }
protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e) { Token t1 = recognizer.getInputStream().LT(-1); String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 " + e.getExpectedTokens().toString(recognizer.getTokenNames()); BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e); // exception.token = this.getGrammarToken(e.getOffendingToken()); exception.pushToken(this.getGrammarToken(t1)); throw exception; }
protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e) { Token t1 = recognizer.getInputStream().LT(-1); String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 " + e.getExpectedTokens().toString(recognizer.getTokenNames()); BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e); // exception.token = this.getGrammarToken(e.getOffendingToken()); exception.pushToken(this.getGrammarToken(t1)); throw exception; }
@Override public void reportMissingToken(Parser parser) { if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) { return; } beginErrorCondition(parser); setErrorState(parser); Token token = parser.getCurrentToken(); IntervalSet expecting = getExpectedTokens(parser); String missingToken = expecting.toString(parser.getVocabulary()); DiagnosticPos pos = getPosition(getMissingSymbol(parser)); dlog.error(pos, DiagnosticCode.MISSING_TOKEN, missingToken, getTokenErrorDisplay(token)); }