@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 Position getPosition(ParseError error) { return error.getInputBuffer().getPosition(error.getStartIndex()); }
private static String buildMessage(List<ParseError> errors) { if (errors == null || errors.isEmpty()) { throw new IllegalArgumentException( "Cannot build a CSSParseException without a list of errors"); } StringBuilder sb = new StringBuilder(); for (ParseError pe : errors) { Position pos = pe.getInputBuffer().getPosition(pe.getStartIndex()); String message = pe.getErrorMessage() != null ? pe.getErrorMessage() : pe instanceof InvalidInputError ? new DefaultInvalidInputErrorFormatter() .format((InvalidInputError) pe) : pe.getClass().getSimpleName(); sb.append(message) .append(" (line ") .append(pos.line) .append(", column ") .append(pos.column) .append(")"); sb.append('\n'); } sb.setLength(sb.length() - 1); return sb.toString(); }
protected String match(ParseError error) { return error.getInputBuffer().extract(error.getStartIndex(), error.getEndIndex()); }
message, document, document.createPosition(ibuf.getOriginalIndex(error.getStartIndex())), document.createPosition(ibuf.getOriginalIndex(error.getEndIndex())) );
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()); }
private boolean performLocatingRun(InputBuffer inputBuffer) { resetValueStack(); ParseRunner<V> locatingRunner = new ErrorLocatingParseRunner<V>(rootMatcherWithoutPTB, getInnerHandler()) .withParseErrors(getParseErrors()) .withValueStack(getValueStack()); lastParsingResult = locatingRunner.run(inputBuffer); errorIndex = lastParsingResult.matched ? -1 : getParseErrors().remove(getParseErrors().size() - 1).getStartIndex(); return lastParsingResult.matched; }
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()); int peIndex = abcInputBuffer.getIndex(pePos); CharStreamPosition csp = new CharStreamPosition(
public ParsingResult<V> run(InputBuffer inputBuffer) { checkArgNotNull(inputBuffer, "inputBuffer"); resetValueStack(); // first, run a basic match ParsingResult<V> result = runBasicMatch(inputBuffer); if (result.matched) return result; // all good // ok, we have a parse error, so determine the error location resetValueStack(); result = runLocatingMatch(inputBuffer); Preconditions.checkState(!result.matched); // we failed before so we should really be failing again Preconditions.checkState(result.parseErrors.size() >= 1); // may be more than one in case of custom ActionExceptions // finally perform a third, reporting run (now that we know the error location) resetValueStack(); result = runReportingMatch(inputBuffer, result.parseErrors.get(0).getStartIndex()); Preconditions.checkState(!result.matched); // we failed before so we should really be failing again return result; }
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); }