@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");
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(); }
/** * 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()); }
final List<ParseError> parseErrors = cfgResult.getParbResult().parseErrors; for (ParseError error : parseErrors) { String message = error.getErrorMessage() != null ? error.getErrorMessage() : error instanceof InvalidInputError ? formatter.format((InvalidInputError) error)
/** * 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); }
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); while (it.hasNext()) { ParseError pe = (ParseError) it.next(); errors.add(new AbcParseError(pe.getErrorMessage(), value, getCharStreamPosition()));
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()); } }