Java 类org.antlr.v4.runtime.atn.SetTransition 实例源码

项目:codebuff    文件:LexerATNFactory.java   
/** [Aa\t \u1234a-z\]\-] char sets */
@Override
public Handle charSetLiteral(GrammarAST charSetAST) {
    ATNState left = newState(charSetAST);
    ATNState right = newState(charSetAST);
    IntervalSet set = getSetFromCharSetLiteral(charSetAST);
    left.addTransition(new SetTransition(right, set));
    charSetAST.atnState = left;
    return new Handle(left, right);
}
项目:codebuff    文件:MatchSet.java   
public MatchSet(OutputModelFactory factory, GrammarAST ast) {
    super(factory, ast);
    SetTransition st = (SetTransition)ast.atnState.transition(0);
    int wordSize = factory.getGenerator().getTarget().getInlineTestSetWordSize();
    expr = new TestSetInline(factory, null, st.set, wordSize);
    Decl d = new TokenTypeDecl(factory, expr.varName);
    factory.getCurrentRuleFunction().addLocalDecl(d);
    capture = new CaptureNextTokenType(factory,expr.varName);
}
项目:goworks    文件:GroupHighlighterLexer.java   
private static Transition createSetTransition(ATNState target, IntervalSet set) {
    if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        if (interval.a == interval.b) {
            return new AtomTransition(target, interval.a);
        } else {
            return new RangeTransition(target, interval.a, interval.b);
        }
    } else {
        return new SetTransition(target, set);
    }
}
项目:goworks    文件:TemplateLexer.java   
private static Transition createSetTransition(ATNState target, IntervalSet set) {
    if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        if (interval.a == interval.b) {
            return new AtomTransition(target, interval.a);
        } else {
            return new RangeTransition(target, interval.a, interval.b);
        }
    } else {
        return new SetTransition(target, set);
    }
}
项目:antlrworks2    文件:GroupHighlighterLexer.java   
private static Transition createSetTransition(ATNState target, IntervalSet set) {
    if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        if (interval.a == interval.b) {
            return new AtomTransition(target, interval.a);
        } else {
            return new RangeTransition(target, interval.a, interval.b);
        }
    } else {
        return new SetTransition(target, set);
    }
}
项目:antlrworks2    文件:TemplateLexer.java   
private static Transition createSetTransition(ATNState target, IntervalSet set) {
    if (set.getIntervals().size() == 1) {
        Interval interval = set.getIntervals().get(0);
        if (interval.a == interval.b) {
            return new AtomTransition(target, interval.a);
        } else {
            return new RangeTransition(target, interval.a, interval.b);
        }
    } else {
        return new SetTransition(target, set);
    }
}
项目:goworks    文件:AbstractCompletionParserATNSimulator.java   
@Override
public ATNState getReachableTarget(ATNConfig source, Transition trans, int ttype) {
    if (ttype == CaretToken.CARET_TOKEN_TYPE) {
        ATNState target = null;
        if (trans instanceof AtomTransition) {
            AtomTransition at = (AtomTransition)trans;
            if (getWordlikeTokenTypes().contains(at.label)) {
                target = at.target;
            }
        } else if (trans instanceof SetTransition) {
            SetTransition st = (SetTransition)trans;
            boolean not = trans instanceof NotSetTransition;
            // TODO: this could probably be done with an intersects method?
            for (int t : getWordlikeTokenTypes().toArray()) {
                if (!not && st.set.contains(t) || not && !st.set.contains(t)) {
                    target = st.target;
                    break;
                }
            }
        } else if (trans instanceof RangeTransition) {
            RangeTransition rt = (RangeTransition)trans;
            // TODO: there must be a better algorithm here :)
            int[] wordlikeTokenTypes = getWordlikeTokenTypes().toArray();
            int lb = Arrays.binarySearch(wordlikeTokenTypes, rt.from);
            int ub = Arrays.binarySearch(wordlikeTokenTypes, rt.to);
            if (lb >= 0 || ub >= 0 || lb != ub) {
                target = rt.target;
            }
        } else if (trans instanceof WildcardTransition) {
            target = trans.target;
        }

        if (caretTransitions == null) {
            caretTransitions = new LinkedHashMap<>();
        }

        List<Transition> configTransitions = caretTransitions.get(source);
        if (configTransitions == null) {
            configTransitions = new ArrayList<>();
            caretTransitions.put(source, configTransitions);
        }

        configTransitions.add(trans);
        return target;
    }

    return super.getReachableTarget(source, trans, ttype);
}
项目:antlrworks2    文件:AbstractCompletionParserATNSimulator.java   
@Override
public ATNState getReachableTarget(ATNConfig source, Transition trans, int ttype) {
    if (ttype == CaretToken.CARET_TOKEN_TYPE) {
        ATNState target = null;
        if (trans instanceof AtomTransition) {
            AtomTransition at = (AtomTransition)trans;
            if (getWordlikeTokenTypes().contains(at.label)) {
                target = at.target;
            }
        } else if (trans instanceof SetTransition) {
            SetTransition st = (SetTransition)trans;
            boolean not = trans instanceof NotSetTransition;
            // TODO: this could probably be done with an intersects method?
            for (int t : getWordlikeTokenTypes().toArray()) {
                if (!not && st.set.contains(t) || not && !st.set.contains(t)) {
                    target = st.target;
                    break;
                }
            }
        } else if (trans instanceof RangeTransition) {
            RangeTransition rt = (RangeTransition)trans;
            // TODO: there must be a better algorithm here :)
            int[] wordlikeTokenTypes = getWordlikeTokenTypes().toArray();
            int lb = Arrays.binarySearch(wordlikeTokenTypes, rt.from);
            int ub = Arrays.binarySearch(wordlikeTokenTypes, rt.to);
            if (lb >= 0 || ub >= 0 || lb != ub) {
                target = rt.target;
            }
        } else if (trans instanceof WildcardTransition) {
            target = trans.target;
        }

        if (caretTransitions == null) {
            caretTransitions = new LinkedHashMap<>();
        }

        List<Transition> configTransitions = caretTransitions.get(source);
        if (configTransitions == null) {
            configTransitions = new ArrayList<>();
            caretTransitions.put(source, configTransitions);
        }

        configTransitions.add(trans);
        return target;
    }

    return super.getReachableTarget(source, trans, ttype);
}