currentToken = parser.getCurrentToken(); context = parser.getContext();
private InvalidSyntaxException mkException(Parser recognizer, RecognitionException cause) { String sourcePreview = null; String offendingToken = null; SourceLocation sourceLocation = null; Token currentToken = recognizer.getCurrentToken(); if (currentToken != null) { int line = currentToken.getLine(); int column = currentToken.getCharPositionInLine(); offendingToken = currentToken.getText(); sourcePreview = mkPreview(line); sourceLocation = new SourceLocation(line, column, sourceName); } return new InvalidSyntaxException(sourceLocation, null, sourcePreview, offendingToken, cause); }
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); } }
/** * Get matched token by token type. * * @param tokenType token type * @return matched token * @throws RecognitionException mismatch throw exception */ public Token getMatchedToken(final int tokenType) throws RecognitionException { Token result = parser.getCurrentToken(); boolean isIdentifierCompatible = false; if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) { isIdentifierCompatible = true; } if (result.getType() == tokenType || isIdentifierCompatible) { if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) { ((CommonToken) result).setType(identifierTokenIndex); } parser.getErrorHandler().reportMatch(parser); parser.consume(); } else { result = parser.getErrorHandler().recoverInline(parser); if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) { parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result)); } } return result; } }
public NoViableAltException(Parser recognizer) { // LL(1) error this(recognizer, recognizer.getInputStream(), recognizer.getCurrentToken(), recognizer.getCurrentToken(), null, recognizer._ctx); }
public final void notifyErrorListeners(String msg) { notifyErrorListeners(getCurrentToken(), msg, null); }
public InputMismatchException(Parser recognizer) { super(recognizer, recognizer.getInputStream(), recognizer._ctx); this.setOffendingToken(recognizer.getCurrentToken()); }
public InputMismatchException(Parser recognizer, int state, ParserRuleContext ctx) { super(recognizer, recognizer.getInputStream(), ctx); this.setOffendingState(state); this.setOffendingToken(recognizer.getCurrentToken()); } }
public FailedPredicateException(Parser recognizer, String predicate, String message) { super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx); ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState()); AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0); if (trans instanceof PredicateTransition) { this.ruleIndex = ((PredicateTransition)trans).ruleIndex; this.predicateIndex = ((PredicateTransition)trans).predIndex; } else { this.ruleIndex = 0; this.predicateIndex = 0; } this.predicate = predicate; this.setOffendingToken(recognizer.getCurrentToken()); }
Token t = getCurrentToken(); if (t.getType() > 0) { _errHandler.reportMatch(this);
Token t = getCurrentToken(); if ( t.getType()==ttype ) { if ( ttype==Token.EOF ) {
Token matchedSymbol = recognizer.getCurrentToken();
/** * 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); }
Token o = getCurrentToken(); if (o.getType() != EOF) { getInputStream().consume();
public NoViableAltException(Parser recognizer) { // LL(1) error this(recognizer, recognizer.getInputStream(), recognizer.getCurrentToken(), recognizer.getCurrentToken(), null, recognizer._ctx); }
Token currentSymbol = recognizer.getCurrentToken(); IntervalSet expecting = getExpectedTokens(recognizer); int expectedTokenType = Token.INVALID_TYPE;
private boolean isInFirstTokenOfCursorLine(Parser recognizer) { Token currentToken = recognizer.getCurrentToken(); if (firstTokenOfCursorLine == null) { firstTokenOfCursorLine = getFirstTokenOfCursorLine(recognizer); } return firstTokenOfCursorLine != null && currentToken.getTokenIndex() == firstTokenOfCursorLine.getTokenIndex(); }
@Override public void reportUnwantedToken(Parser parser) { if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) { return; } beginErrorCondition(parser); setErrorState(parser); Token token = parser.getCurrentToken(); DiagnosticPos pos = getPosition(getMissingSymbol(parser)); dlog.error(pos, DiagnosticCode.EXTRANEOUS_INPUT, getTokenErrorDisplay(token)); }