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

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

Introduction

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

Prototype

@Override
    public CharStream getInputStream() 

Source Link

Usage

From source file:org.apache.lucene.expressions.js.JavascriptErrorHandlingLexer.java

License:Apache License

/**
 * Ensures the ANTLR lexer will throw an exception after the first error
 * @param lnvae the lexer exception//  w  ww  .  ja v a  2  s.  c  om
 */
@Override
public void recover(LexerNoViableAltException lnvae) {
    CharStream charStream = lnvae.getInputStream();
    int startIndex = lnvae.getStartIndex();
    String text = charStream.getText(Interval.of(startIndex, charStream.index()));

    ParseException parseException = new ParseException("unexpected character '" + getErrorDisplay(text) + "'"
            + " on line (" + _tokenStartLine + ") position (" + _tokenStartCharPositionInLine + ")",
            _tokenStartCharIndex);
    parseException.initCause(lnvae);
    throw new RuntimeException(parseException);
}

From source file:org.elasticsearch.painless.ErrorHandlingLexer.java

License:Apache License

@Override
public void recover(LexerNoViableAltException lnvae) {
    CharStream charStream = lnvae.getInputStream();
    int startIndex = lnvae.getStartIndex();
    String text = charStream.getText(Interval.of(startIndex, charStream.index()));

    ParseException parseException = new ParseException("Error [" + _tokenStartLine + ":"
            + _tokenStartCharPositionInLine + "]: unexpected character [" + getErrorDisplay(text) + "].",
            _tokenStartCharIndex);/*  ww w.j  av  a2s. co  m*/
    parseException.initCause(lnvae);
    throw new RuntimeException(parseException);
}