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()); }
/** * 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()); }
while (it.hasNext()) { 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(
/** * 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); }