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); } } }
recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
@Override public void recover(RecognitionException ex) { throw new RuntimeException(ex.getMessage()); }
@Override public void recover(RecognitionException ex) { throw new RuntimeException(ex.getMessage()); }
@Override public void recover(RecognitionException e) { throw new RuntimeException("Error in grammer - " + e.getMessage()); }
@Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException re) { addMessage(new ParseError(line, charPositionInLine, charPositionInLine, msg, re == null ? null : re.getMessage())); }
@Override public void reportError(Parser recognizer, RecognitionException e) { if (!(e instanceof BatfishRecognitionException)) { recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e); } }
if (e.getMessage().equals("NoViableAlternative")) { type = SyntaxError.NOVIABLEALTERNATIVE; reportError(type, pos, offendingTokenText, expectedtokens); } else if (e.getMessage().equals("InputMismatch")) { type = SyntaxError.INPUTMISMATCH; reportError(type, pos, offendingTokenText, expectedtokens); } else if (e.getMessage().equals("FailedPredicate")) { type = SyntaxError.FAILEDPREDICATE; reportError(type, pos, offendingTokenText, expectedtokens); } else if (e.getMessage().equals("UnwantedToken")) { type = SyntaxError.UNWANTEDTOKEN; reportError(type, pos, offendingTokenText); } else if (e.getMessage().equals("MissingToken")) { type = SyntaxError.MISSINGTOKEN; reportError(type, pos, expectedtokens);
@Override public Map<ConstructId, Construct> getConstructs() throws FileAnalysisException { if(this.constructs==null) { try { this.constructs = new TreeMap<ConstructId, Construct>(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (final InputStream is2 = new BufferedInputStream(new FileInputStream(this.file))) { int cc = -1; while ((cc = is2.read()) >= 0) baos.write(cc); } baos.flush(); this.input = new ANTLRInputStream(new ByteArrayInputStream(baos.toByteArray())); JavaLexer lexer = new JavaLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JavaParser parser = new JavaParser(tokens); CompilationUnitContext ctx = parser.compilationUnit(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(this, ctx); } catch (FileNotFoundException e) { throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("I/O exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (Exception e) { throw new FileAnalysisException("Exception of type [" + e.getClass().getSimpleName() + "] while analyzing file [" + this.file.toPath().toAbsolutePath() + "]: " + e.getMessage(), e); } } return this.constructs; }
throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("IO exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e);
if (e.getMessage().equals("NoViableAlternative")) { this.errors.add(new ParserException( ParserErrorMessages.FOUND_BUT_NEED.toReadableString(offendingTokenText, expectedtokens), pos)); } else if (e.getMessage().equals("InputMismatch")) { this.errors.add(new ParserException( ParserErrorMessages.FOUND_BUT_NEED.toReadableString(offendingTokenText, expectedtokens), pos)); } else if (e.getMessage().equals("FailedPredicate")) { this.errors.add(new ParserException(ParserErrorMessages.FAILED_PREDICATE.toReadableString(), pos)); } else if (e.getMessage().equals("UnwantedToken")) { this.errors .add(new ParserException(ParserErrorMessages.TOKEN_BAD.toReadableString(offendingTokenText), pos)); } else if (e.getMessage().equals("MissingToken")) { this.errors .add(new ParserException(ParserErrorMessages.TOKEN_MISSING.toReadableString(expectedtokens), pos));
throw new FileAnalysisException(e.getMessage(), e); } catch (RecognitionException e) { throw new FileAnalysisException("ANTLR exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e); } catch (IOException e) { throw new FileAnalysisException("IO exception while analysing class file [" + this.file.getName() + "]: " + e.getMessage(), e);
@Override public void reportError(IntStream input, RecognitionException re, org.antlr.runtime.BitSet follow) { // System.out.println("Token line:" + re.token.getLine()); // System.out.println("Token text:" + re.token.getText()); addMessage(new ParseError(re.getOffendingToken().getLine(), re.getOffendingToken().getCharPositionInLine(), re.getOffendingToken().getCharPositionInLine(), re.getMessage(), re.getMessage())); // System.err.println(re.getMessage()); }
@Override public void reportError(RecognitionException re) { if (re.getOffendingToken() != null) { // System.out.println("Token line:" + re.token.getLine()); // System.out.println("Token text:" + re.token.getText()); } // re.printStackTrace(); // System.err.println(re.getMessage()); addMessage(new ParseError(re.getOffendingToken().getLine(), re.getOffendingToken().getCharPositionInLine(), re.getOffendingToken().getCharPositionInLine(), re.getMessage(), re.getMessage())); }
logger.error("Error parsing {} as a FieldPath: {}.", fieldPath, e.getMessage()); throw new IllegalArgumentException( "Unable to parse '" + fieldPath + "' as a FieldPath.", e);
if(e.getOffendingToken() != null) String message = ColorMessage.bold(getTokenErrorDisplay(e.getOffendingToken()) + " ") + e.getMessage(); recognizer.notifyErrorListeners(e.getOffendingToken(), message, e); recognizer.notifyErrorListeners(e.getMessage()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
if(e.getOffendingToken() != null) String message = ColorMessage.bold(getTokenErrorDisplay(e.getOffendingToken()) + " ") + e.getMessage(); recognizer.notifyErrorListeners(e.getOffendingToken(), message, e); recognizer.notifyErrorListeners(e.getMessage()); recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
@Override public void reportError(String[] tokenNames, RecognitionException re) { // System.out.println("Token line:" + re.token.getLine()); // System.out.println("Token text:" + re.token.getText()); // System.err.println(tokenNames); // System.err.println(re.getMessage()); addMessage(new ParseError(re.getOffendingToken().getLine(), re.getOffendingToken().getCharPositionInLine(), re.getOffendingToken().getCharPositionInLine(), tokenNames.toString(), re.getMessage())); // re.printStackTrace(); }
recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
public void reportError(Parser parser, RecognitionException e) { if (inErrorRecoveryMode(parser)) { return; } beginErrorCondition(parser); if (e instanceof NoViableAltException) { reportNoViableAlternative(parser, (NoViableAltException) e); } else if (e instanceof InputMismatchException) { reportInputMismatch(parser, (InputMismatchException) e); } else if (e instanceof FailedPredicateException) { reportFailedPredicate(parser, (FailedPredicateException) e); } else { setErrorState(parser); DiagnosticPos pos = getPosition(getMissingSymbol(parser)); dlog.error(pos, DiagnosticCode.INVALID_TOKEN, e.getMessage()); } }