Example usage for org.antlr.v4.runtime.misc IntervalSet addAll

List of usage examples for org.antlr.v4.runtime.misc IntervalSet addAll

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.misc IntervalSet addAll.

Prototype

@Override
    public IntervalSet addAll(IntSet set) 

Source Link

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

From source file:org.tvl.goworks.editor.go.highlighter.GoHighlighterLexer.java

License:Open Source License

private static Transition patchTransition(Transition transition, IntervalSet digitChars,
        IntervalSet letterChars) {//from w w w. j a v  a  2 s .c om
    switch (transition.getSerializationType()) {
    case Transition.ATOM:
    case Transition.RANGE:
    case Transition.SET:
        break;

    default:
        return null;
    }

    IntervalSet label = transition.label();
    if (label == null) {
        return null;
    }

    IntervalSet updated = null;
    if (label.contains(unicodeDigitPlaceholder)) {
        updated = new IntervalSet(label);
        updated.addAll(digitChars);
        if (updated.size() == digitChars.size()) {
            updated = digitChars;
        }
    }

    if (label.contains(unicodeLetterPlaceholder)) {
        if (updated != null) {
            updated.addAll(label);
        } else {
            updated = new IntervalSet(label);
        }

        updated.addAll(letterChars);
        if (updated.size() == letterChars.size()) {
            updated = letterChars;
        }
    }

    if (updated == null) {
        return null;
    }

    return new SetTransition(transition.target, updated);
}