Example usage for org.antlr.v4.runtime TokenSource getInputStream

List of usage examples for org.antlr.v4.runtime TokenSource getInputStream

Introduction

In this page you can find the example usage for org.antlr.v4.runtime TokenSource getInputStream.

Prototype

public CharStream getInputStream();

Source Link

Document

Get the CharStream from which this token source is currently providing tokens.

Usage

From source file:boa.compiler.listeners.BoaErrorListener.java

License:Apache License

private void underlineError(final TokenSource tokens, final Token offendingToken, final int line,
        final int charPositionInLine, final int length) {
    final String input = tokens.getInputStream().toString() + "\n ";
    final String[] lines = input.split("\n");
    final String errorLine = lines[line - 1];
    System.err.println(errorLine.replaceAll("\t", "    "));

    int stop = Math.min(charPositionInLine, errorLine.length());
    for (int i = 0; i < stop; i++)
        if (errorLine.charAt(i) == '\t')
            System.err.print("    ");
        else//from  ww  w .  j  av  a2s .c om
            System.err.print(" ");

    int stop2 = Math.min(stop + length, errorLine.length());
    for (int i = stop; i < stop2; i++)
        if (errorLine.charAt(i) == '\t')
            System.err.print("^^^^");
        else
            System.err.print("^");

    System.err.println();
}

From source file:edu.iastate.cs.boa.ui.errors.FetchCompilerError.java

License:Apache License

private void underlineError(final TokenSource tokens, final Token offendingToken, final int line,
        final int charPositionInLine, final int length) {
    final String input = tokens.getInputStream().toString() + "\n ";
    final String[] lines = input.split("\n");
    final String errorLine = lines[line - 1];
    System.err.println(errorLine.replaceAll("\t", "    "));

    int stop = Math.min(charPositionInLine, errorLine.length());
    for (int i = 0; i < stop; i++)
        if (errorLine.charAt(i) == '\t')
            System.err.print("    ");
        else/*w w  w.  j  ava  2 s  . c o  m*/
            System.err.print(" ");

    int stop2 = Math.min(stop + length, errorLine.length());
    for (int i = stop; i < stop2; i++)
        if (errorLine.charAt(i) == '\t')
            System.err.print("^^^^");
        else
            System.err.print("^");
    System.err.println();
}