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); } } }
currentState = atn.states.get(e.getOffendingState()); currentToken = e.getOffendingToken(); context = e.getCtx();
final Interval sourceInterval = exception.getCtx().getSourceInterval(); final List<Token> tokenList = ((BufferedTokenStream) exception.getInputStream()) .getTokens(sourceInterval.a, sourceInterval.b); final Deque<Token> stack = new ArrayDeque<>();
@Override public List<SuggestToken> visitIdentifierArrayExpr(PrepRuleParser.IdentifierArrayExprContext ctx) { List<SuggestToken> suggest = Lists.newArrayList(); if(0==suggest.size() && null!=ctx.exception) {// && false==(ctx.exception instanceof NoViableAltException)) { Token offendingToken = ctx.exception.getOffendingToken(); String offendingSource = offendingToken.getText(); int offendingStart = offendingToken.getStartIndex(); int offendingStop = offendingToken.getStopIndex(); IntervalSet intervalSet = ctx.exception.getExpectedTokens(); if (null != intervalSet) { for (Interval expected : intervalSet.getIntervals()) { for (int token_num = expected.a; token_num <= expected.b; token_num++) { SuggestToken suggestToken = new SuggestToken(); suggestToken.setStart(offendingStart); suggestToken.setStop(offendingStop); suggestToken.setTokenNum(token_num); suggestToken.setTokenSource(offendingSource); suggest.add(suggestToken); } } } } return suggest; }
/** What is the error header, normally line/character position information? */ public String getErrorHeader(RecognitionException e) { int line = e.getOffendingToken().getLine(); int charPositionInLine = e.getOffendingToken().getCharPositionInLine(); return "line "+line+":"+charPositionInLine; }
@Override public void recover(Parser recognizer, RecognitionException e) { Token ot = e.getOffendingToken(); System.out.println("offending token:" + ot.getText()); IntervalSet exceptedTokens = e.getExpectedTokens(); RuleContext ctx = e.getCtx(); if(ctx!=null){ System.out.println("context:" + ctx.getClass().getName()); } System.out.println("offending state:" + e.getOffendingState()); String excTks = exceptedTokens.toString(KalangLexer.VOCABULARY); System.out.println("excepted:" + excTks); super.recover(recognizer, e); }
@Override public void recover(RecognitionException ex) { throw new RuntimeException(ex.getMessage()); }
@Override public void reportError(Parser recognizer, RecognitionException e) { String messagePrefix = ""; if (e.getCtx() instanceof CypherParser.OC_RelationshipPatternContext) { messagePrefix = "InvalidRelationshipPattern: "; } throw new VertexiumCypherSyntaxErrorException( String.format( "%sCould not parse (%d:%d): %s", messagePrefix, e.getOffendingToken().getLine(), e.getOffendingToken().getCharPositionInLine(), code ), e); } }
if (e.getCtx() instanceof ParserRuleContext) { ParserRuleContext ctx = (ParserRuleContext) e.getCtx(); throw new ConfigException(e.getMessage(), e.getInputStream().getSourceName(), ctx.start, e); } else { throw e;
private static String createMessage(RecognitionException e) { Token offendingToken = e.getOffendingToken(); String[] inputLines = e.getInputStream().toString().split("\r?\n|\r"); String errorLine = inputLines[offendingToken.getLine() - 1]; StringBuilder message = new StringBuilder(String.format("\nError on line %s, column %s:\n", offendingToken.getLine(), offendingToken.getCharPositionInLine())); message.append(errorLine).append("\n"); for (int i = 0; i < offendingToken.getCharPositionInLine(); i++) { message.append(" "); } message.append("^"); if (e instanceof InputMismatchException) { InputMismatchException ime = (InputMismatchException)e; return String.format("%s\nmatched '%s' as token <%s>, expecting token <%s>", message, offendingToken.getText(), tokenName(offendingToken.getType()), tokenNames(ime.getExpectedTokens())); } if (e instanceof FailedPredicateException) { FailedPredicateException fpe = (FailedPredicateException)e; return String.format("%s\nfailed predicate '%s' after position %s", message, fpe.getPredicate(), offendingToken.getCharPositionInLine()); } if (e instanceof NoViableAltException || e instanceof LexerNoViableAltException) { return String.format("%s\ncould not decide what path to take, at position %s", message, offendingToken.getCharPositionInLine()); } return message + "\nAn unknown error occurred!"; }
if (pce.getCause() instanceof RecognitionException) { RecognitionException re = (RecognitionException)pce.getCause(); ParserRuleContext context = (ParserRuleContext)re.getCtx(); }
@Override public CharStream getInputStream() { return (CharStream)super.getInputStream(); }
charPositionInLine, offendingSymbol); } else if( "}".equals( token.getText() ) && e != null && e.getRecognizer() instanceof Parser && ((Parser)e.getRecognizer()).getRuleInvocationStack().contains( "key" ) ) { return new SyntaxErrorEvent(FEELEvent.Severity.ERROR, Msg.createMessage(Msg.MISSING_EXPRESSION, e.getCtx().getText()), e, line,
ObjectWrapped<Object> getObject(String qualifiedName, ParserRuleContext ctx) { try { logger.debug("Load ing {} with {}", qualifiedName, classLoader); Class<?> objectClass = classLoader.loadClass(qualifiedName); AbstractBuilder<?> builder = AbstractBuilder.resolve(objectClass); return new ObjectWrapped<Object>(builder != null ? builder: objectClass.newInstance()); } catch (ClassNotFoundException e) { throw new RecognitionException("Unknown class " + qualifiedName, parser, stream, ctx); } catch (InstantiationException | IllegalAccessException e) { throw new RecognitionException("Unsuable class " + qualifiedName, parser, stream, ctx); } }
@Override public List<SuggestToken> visitDoubleArrayExpr(PrepRuleParser.DoubleArrayExprContext ctx) { List<SuggestToken> suggest = Lists.newArrayList(); if(0==suggest.size() && null!=ctx.exception) {// && false==(ctx.exception instanceof NoViableAltException)) { Token offendingToken = ctx.exception.getOffendingToken(); String offendingSource = offendingToken.getText(); int offendingStart = offendingToken.getStartIndex(); int offendingStop = offendingToken.getStopIndex(); IntervalSet intervalSet = ctx.exception.getExpectedTokens(); if (null != intervalSet) { for (Interval expected : intervalSet.getIntervals()) { for (int token_num = expected.a; token_num <= expected.b; token_num++) { SuggestToken suggestToken = new SuggestToken(); suggestToken.setStart(offendingStart); suggestToken.setStop(offendingStop); suggestToken.setTokenNum(token_num); suggestToken.setTokenSource(offendingSource); suggest.add(suggestToken); } } } } return suggest; }
Token tok = e.getOffendingToken(); int expectedTokenType = Token.INVALID_TYPE; if ( !ime.getExpectedTokens().isNil() ) { Token tok = e.getOffendingToken(); Token errToken = getTokenFactory().create(new Pair<TokenSource, CharStream>(tok.getTokenSource(), tok.getTokenSource().getInputStream()),
@Override public void recover(RecognitionException ex) { throw new RuntimeException(ex.getMessage()); }
@Override public void reportError(Parser recognizer, RecognitionException e) { String msg = AntlrErrorString.exceptionString(recognizer, e); Token end = e.getOffendingToken(); Token start; RuleContext ctx = e.getCtx(); if(ctx instanceof ParserRuleContext){ start = ((ParserRuleContext) ctx).getStart(); }else{ start = end; } sp.getDiagnosisReporter().report(Diagnosis.Kind.ERROR, msg,start,end); } });
final int ruleIndex = ex.getCtx().getRuleIndex(); final String ruleName = recognizer.getRuleNames()[ruleIndex]; final String upperCaseRuleName = CaseFormat.UPPER_CAMEL.to(
@Override public CharStream getInputStream() { return (CharStream)super.getInputStream(); }