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

项目:goworks    文件:GoParserFactory.java   
public static SemanticContext.Predicate getQidPredicate(@NonNull ATN atn) {
    int predicateIndex = -1;
    for (ATNState state : atn.states) {
        if (state.ruleIndex != GoParser.RULE_qualifiedIdentifier) {
            continue;
        }

        for (int i = 0; i < state.getNumberOfOptimizedTransitions(); i++) {
            Transition transition = state.getOptimizedTransition(i);
            if (transition instanceof PredicateTransition) {
                predicateIndex = ((PredicateTransition)transition).predIndex;
            }
        }
    }

    assert predicateIndex >= 0 : "Couldn't find the QID predicate transition.";
    return new SemanticContext.Predicate(GoParser.RULE_qualifiedIdentifier, predicateIndex, false);
}
项目:intellij-plugin-v4    文件:ProfilerPanel.java   
public static String getSemanticContextDisplayString(PredicateEvalInfo pred,
                                                     PreviewState previewState,
                                                     SemanticContext semctx,
                                                     int alt,
                                                     boolean result) {
    Grammar g = previewState.g;
    String semanticContextDisplayString = g.getSemanticContextDisplayString(semctx);
    if ( semctx instanceof SemanticContext.PrecedencePredicate ) {
        int ruleIndex = previewState.parsingResult.parser.getATN().decisionToState.get(pred.decision).ruleIndex;
        Rule rule = g.getRule(ruleIndex);
        int precedence = ((SemanticContext.PrecedencePredicate) semctx).precedence;
        // precedence = n - originalAlt + 1, So:
        int originalAlt = rule.getOriginalNumberOfAlts()-precedence+1;
        alt = originalAlt;
    }
    return semanticContextDisplayString+" => alt "+alt+" is "+result;
}
项目:codebuff    文件:Grammar.java   
/** Given an arbitrarily complex SemanticContext, walk the "tree" and get display string.
 *  Pull predicates from grammar text.
 */
public String getSemanticContextDisplayString(SemanticContext semctx) {
    if ( semctx instanceof SemanticContext.Predicate ) {
        return getPredicateDisplayString((SemanticContext.Predicate)semctx);
    }
    if ( semctx instanceof SemanticContext.AND ) {
        SemanticContext.AND and = (SemanticContext.AND)semctx;
        return joinPredicateOperands(and, " and ");
    }
    if ( semctx instanceof SemanticContext.OR ) {
        SemanticContext.OR or = (SemanticContext.OR)semctx;
        return joinPredicateOperands(or, " or ");
    }
    return semctx.toString();
}
项目:codebuff    文件:Grammar.java   
public String joinPredicateOperands(SemanticContext.Operator op, String separator) {
    StringBuilder buf = new StringBuilder();
    for (SemanticContext operand : op.getOperands()) {
        if (buf.length() > 0) {
            buf.append(separator);
        }

        buf.append(getSemanticContextDisplayString(operand));
    }

    return buf.toString();
}
项目:codebuff    文件:Grammar.java   
public String getPredicateDisplayString(SemanticContext.Predicate pred) {
    if ( indexToPredMap==null ) {
        indexToPredMap = getIndexToPredicateMap();
    }
    ActionAST actionAST = indexToPredMap.get(pred.predIndex);
    return actionAST.getText();
}
项目:Scratch-ApuC    文件:DFAState.java   
public PredPrediction(SemanticContext pred, int alt) {
    this.alt = alt;
    this.pred = pred;
}