ParseErrorFormatter { public String format(ParseError parseError) { Objects.requireNonNull(parseError); InputBuffer inputBuffer = parseError.getInputBuffer(); Position position = inputBuffer.getPosition(parseError.getErrorIndex()); StringBuilder sb = new StringBuilder(); sb.append("Parse error at line ").append(position.getLine()) .append(" column ").append(position.getColumn()) .append(":\n\n"); appendSnippet(sb, inputBuffer, position); return sb.toString(); }  String format(ParseError parseError);  }
@Test public void test() { InputBuffer inputBuffer = new ImmutableInputBuffer("\t2+4*10-0*\n".toCharArray()); String result = formatter.format(new ParseError(inputBuffer, 10)); System.out.print(result); String expected = new StringBuilder() .append("Parse error at line 1 column 11:\n") .append('\n') .append("1: 2+4*10-0*\n") .append(" ^\n") .append("2: \n") .toString(); assertThat(result).isEqualTo(expected); }