_errHandler.sync(this); _alt = 1; do { _la = _input.LA(1); if ( !(_la==WS || _la==CHAR) ) { _errHandler.recoverInline(this); if ( _input.LA(1)==Token.EOF ) matchedEOF = true; _errHandler.reportMatch(this); consume(); _la = _input.LA(1); if ((_la != WS) && (_la != CHAR)) return _localctx; else if (_alt == 1) continue; throw new NoViableAltException(this); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,181,_ctx); } while ( _alt!=2 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER );
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); }
private ScriptParseException createScriptParseException(RobotParser parser, NoViableAltException nvae) { String desc = String.format("line %d:%d: ", nvae.getStartToken() .getLine(), nvae.getOffendingToken().getCharPositionInLine()); String msg = String.format("%sunexpected character: '%s'", desc, escapeChar(nvae.getOffendingToken().getText().charAt(0))); return new ScriptParseException(msg); }
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { Parser parser = (Parser) recognizer; String name = parser.getSourceName(); TokenStream tokens = parser.getInputStream(); Token offSymbol = (Token) offendingSymbol; int thisError = offSymbol.getTokenIndex(); String source = "<unknown>"; if (offSymbol != null) { String charstream = offSymbol.getTokenSource().getInputStream().toString(); String[] lines = charstream.split("\n"); source = lines[line - 1]; } if (offSymbol.getType() == -1 && thisError == tokens.size() - 1) { if (e != null) { if (e instanceof NoViableAltException) { msg = "unexpected token found '" + ((NoViableAltException) e).getStartToken().getText() + "'"; } } String message = "At line " + line + ":" + charPositionInLine + ": " + msg; errors.add(new SyntaxError(line, charPositionInLine, message, source)); return; } String offSymName = RulebookLexer.VOCABULARY.getDisplayName(offSymbol.getType()); String message = "At line " + line + ":" + charPositionInLine + " at " + offSymName.toLowerCase() + ": " + msg; lastError = thisError; errors.add(new SyntaxError(line, charPositionInLine, message, source)); }
currentToken = ((NoViableAltException) e).getStartToken();
private int tryToExecuteByID(final DFA dfa, final DFAState s0, final TokenStream input, final int startIndex, final ParserRuleContext outerContext, final NoViableAltException cause) { Token token = cause.getOffendingToken(); CommonToken commonToken; if (token instanceof CommonToken) { commonToken = (CommonToken) token; } else { throw cause; } int previousType = commonToken.getType(); if (previousType > identifierTokenIndex || Token.EOF == token.getType()) { throw cause; } commonToken.setType(identifierTokenIndex); try { return super.execATN(dfa, s0, input, startIndex, outerContext); } catch (NoViableAltException ex) { if (cause.getOffendingToken() == ex.getOffendingToken()) { throw cause; } return tryToExecuteByID(dfa, s0, input, startIndex, outerContext, ex); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON commonToken.setType(previousType); throw cause; } } }
@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) { setErrorState(parser); String offendingToken = e.getOffendingToken().getText(); DiagnosticPos pos = getPosition(e.getOffendingToken()); dlog.error(pos, DiagnosticCode.INVALID_TOKEN, escapeWSAndQuote(offendingToken)); }
private ScriptParseException createScriptParseException(RobotParser parser, NoViableAltException nvae) { String desc = String.format("line %d:%d: ", nvae.getStartToken() .getLine(), nvae.getOffendingToken().getCharPositionInLine()); String msg = String.format("%sunexpected character: '%s'", desc, escapeChar(nvae.getOffendingToken().getText().charAt(0))); return new ScriptParseException(msg); }
if (offSymbol.getType() == -1 && thisError == tokens.size() - 1) { if (e != null) { if (e instanceof NoViableAltException) { msg = "unexpected token found '" + ((NoViableAltException) e).getStartToken().getText() + "'";
public Token getOffendingSymbol() { if ( e instanceof NoViableAltException ) { // the error node in parse tree will have the start token as bad token // even if many lookahead tokens were matched before failing to find // a viable alt. return ((NoViableAltException) e).getStartToken(); } return offendingSymbol; }
@Override public void reportNoViableAlternative(Parser parser, NoViableAltException e) throws RecognitionException { parser.notifyErrorListeners(e.getOffendingToken(), getExpectationTxt((Parser) e.getRecognizer()), getException("NoViableAlternative", parser)); }
String offend = xx.getOffendingToken().getText(); throw new OrcaException(x, "Invalid SQL. Offending token: {}", offend);
_errHandler.sync(this); _alt = 1+1; do { throw new NoViableAltException(this); _errHandler.sync(this); _alt = getInterpreter().adaptivePredict(_input,241,_ctx); } while ( _alt!=1 && _alt!=org.antlr.v4.runtime.atn.ATN.INVALID_ALT_NUMBER ); _errHandler.reportError(this, re); _errHandler.recover(this, re);
/** * 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); }
/** * {@inheritDoc} */ @Override public void reportNoViableAlternative(@NotNull Parser recognizer, @NotNull NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input; if (tokens instanceof TokenStream) { if (e.getStartToken().getType() == Token.EOF) input = "<EOF>"; else input = getText(tokens, e.getStartToken(), e.getOffendingToken()); } else { input = "<unknown input>"; } String msg = "no viable alternative at input " + escapeWSAndQuote(input); recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e); }
currentToken = ((NoViableAltException) e).getStartToken();
try { setState(756); _errHandler.sync(this); switch (_input.LA(1)) { case NUMBER: enterOuterAlt(_localctx, 1); throw new NoViableAltException(this); _errHandler.reportError(this, re); _errHandler.recover(this, re);
public static String noViableAlt(Parser recognizer, NoViableAltException e) { TokenStream tokens = recognizer.getInputStream(); String input = null; if (tokens != null) { Token startToken = e.getStartToken(); if (startToken.getType() == Token.EOF) { input = "<EOF>"; } else { input = tokens.getText( startToken, e.getOffendingToken() ); } } return "syntax error at input:" + input; }
currentToken = ((NoViableAltException) e).getStartToken();