Example usage for org.antlr.v4.runtime.atn ATN nextTokens

List of usage examples for org.antlr.v4.runtime.atn ATN nextTokens

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.atn ATN nextTokens.

Prototype

public IntervalSet nextTokens(ATNState s) 

Source Link

Document

Compute the set of valid tokens that can occur starting in s and staying in same rule.

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);//w ww  .java 2  s.  c o m
        ctx = ctx.parent;
    }
    recoverSet.remove(Token.EPSILON);
    // System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
    return recoverSet;
}