@Override public String apply(ParseError input) { return String.format("%d, %d -> %s", input.getStartIndex(), input.getEndIndex(), input.getErrorMessage()); } }), "\n");
@Override public String apply(ParseError input) { return String.format("%d, %d -> %s", input.getStartIndex(), input.getEndIndex(), input.getErrorMessage()); } }), "\n");
protected String match(ParseError error) { return error.getInputBuffer().extract(error.getStartIndex(), error.getEndIndex()); }
document, document.createPosition(ibuf.getOriginalIndex(error.getStartIndex())), document.createPosition(ibuf.getOriginalIndex(error.getEndIndex())) ); errors.add(errDesc);
private void postProcess() { for (ParseError error : parsingResult.parseErrors) { int errStart = error.getStartIndex(); int errEnd = error.getEndIndex(); problems.add(new ParseProblem(new Position(mapPosition(errStart), mapPosition(errEnd)), error.toString())); } if (parsingResult.parseTreeRoot != null) { nodes.add(parsingResult.parseTreeRoot.getValue()); gatherComments(parsingResult.parseTreeRoot); } comments = Collections.unmodifiableList(comments); nodes = Collections.unmodifiableList(nodes); problems = Collections.unmodifiableList(problems); rtrimPositions(nodes, comments); //TODO Write test case with javadoc intermixed with empty declares. //TODO test javadoc on a package declaration. //TODO javadoc in between keywords. associateJavadoc(comments, nodes); fixPositions(nodes); fixPositions(comments); parsed = true; }
private void postProcess() { for (ParseError error : parsingResult.parseErrors) { int errStart = error.getStartIndex(); int errEnd = error.getEndIndex(); problems.add(new ParseProblem(new Position(mapPosition(errStart), mapPosition(errEnd)), error.toString())); } if (parsingResult.parseTreeRoot != null) { nodes.add(parsingResult.parseTreeRoot.getValue()); gatherComments(parsingResult.parseTreeRoot); } comments = Collections.unmodifiableList(comments); nodes = Collections.unmodifiableList(nodes); problems = Collections.unmodifiableList(problems); rtrimPositions(nodes, comments); //TODO Write test case with javadoc intermixed with empty declares. //TODO test javadoc on a package declaration. //TODO javadoc in between keywords. associateJavadoc(comments, nodes); fixPositions(nodes); fixPositions(comments); parsed = true; }
/** * Pretty prints the given parse error showing its location in the given input buffer. * * @param error the parse error * @param formatter the formatter for InvalidInputErrors * @return the pretty print text */ public static String printParseError(ParseError error, Formatter<InvalidInputError> formatter) { checkArgNotNull(error, "error"); checkArgNotNull(formatter, "formatter"); String message = error.getErrorMessage() != null ? error.getErrorMessage() : error instanceof InvalidInputError ? formatter.format((InvalidInputError) error) : error.getClass().getSimpleName(); return printErrorMessage("%s (line %s, pos %s):", message, error.getStartIndex(), error.getEndIndex(), error.getInputBuffer()); }
ParseError pe = (ParseError) it.next(); String peValue = pe.getInputBuffer().extract( pe.getStartIndex(), pe.getEndIndex()); String peMsg = pe.getErrorMessage(); Position pePos = pe.getInputBuffer().getPosition(pe.getStartIndex());
protected Localizable localize(ParseError error) { String match = match(error); Position position = getPosition(error); int line = position.line; int start = position.column; int end = start + error.getEndIndex() - error.getStartIndex(); if (error instanceof InvalidInputError) { InvalidInputError inputError = (InvalidInputError) error; MultiLocalizable failedMatchers = new MultiLocalizable( Collections2.transform( inputError.getFailedMatchers(), new Function<MatcherPath, Localizable> () { @Override public Localizable apply(MatcherPath matcherPath) { return localize(matcherPath); } } ) ); return new SidoParseInvalidInputException(match, line, start, end, failedMatchers); } else { return new SidoParseExceptionDetail(match, line, start, end, error.getErrorMessage()); } }
/** * Pretty prints the given parse error showing its location in the given input * buffer. * * @param filename The file's name. * @param error the parse error * @param noffset A negative offset for better error reporting. * @param stacktrace The stack trace. * @return the pretty print text */ public static String printParseError(final String filename, final ParseError error, final int noffset, final List<Stacktrace> stacktrace) { checkArgNotNull(error, "error"); String message = (error.getErrorMessage() != null ? error.getErrorMessage() : error instanceof InvalidInputError ? new ErrorFormatter().format((InvalidInputError) error) : "").replace("EOI", "eof"); return printErrorMessage(filename, filename + ":%2$s:%3$s: %1$s", message, error.getStartIndex() - noffset, error.getEndIndex() - noffset, error.getInputBuffer(), stacktrace); }