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

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

Introduction

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

Prototype

public int getStartIndex() 

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//from w  w w. j  a v  a 2s  .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);//from  w ww .j  av  a 2  s . co m
    parseException.initCause(lnvae);
    throw new RuntimeException(parseException);
}