Example usage for org.antlr.v4.runtime Token EPSILON

List of usage examples for org.antlr.v4.runtime Token EPSILON

Introduction

In this page you can find the example usage for org.antlr.v4.runtime Token EPSILON.

Prototype

int EPSILON

To view the source code for org.antlr.v4.runtime Token EPSILON.

Click Source Link

Document

During lookahead operations, this "token" signifies we hit rule end ATN state and did not follow it despite needing to.

Usage

From source file:com.sample.JavaErrorStrategy.java

License:BSD License

@NotNull
protected IntervalSet getErrorRecoverySet(@NotNull Parser recognizer) {
    ATN atn = recognizer.getInterpreter().atn;
    RuleContext ctx = recognizer.getContext();
    IntervalSet recoverSet = new IntervalSet();
    while (ctx != null && ctx.invokingState >= 0) {
        // compute what follows who invoked us
        ATNState invokingState = atn.states.get(ctx.invokingState);
        RuleTransition rt = (RuleTransition) invokingState.transition(0);
        IntervalSet follow = atn.nextTokens(rt.followState);
        recoverSet.addAll(follow);/*www . j  av  a  2 s.co m*/
        ctx = ctx.parent;
    }
    recoverSet.remove(Token.EPSILON);
    // System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
    return recoverSet;
}