예제 #1
0
파일: Repl.java 프로젝트: anba/es6draft
  private void handleException(ParserExceptionWithSource exception) {
    ParserException e = exception.getCause();
    String sourceCode = exception.getSourceCode();
    int lineOffset = exception.getSource().getLine();

    String sourceInfo = String.format("%s:%d:%d", e.getFile(), e.getLine(), e.getColumn());
    int start = skipLines(sourceCode, e.getLine() - lineOffset);
    int end = nextLineTerminator(sourceCode, start);
    String offendingLine = sourceCode.substring(start, end);
    String marker = Strings.repeat('.', Math.max(e.getColumn() - 1, 0)) + '^';

    console.printf("%s %s: %s%n", sourceInfo, e.getType(), e.getFormattedMessage());
    console.printf("%s %s%n", sourceInfo, offendingLine);
    console.printf("%s %s%n", sourceInfo, marker);
    printStackTrace(e);
  }