protected boolean canMerge(ATNConfig left, long leftKey, ATNConfig right) { if (left.getState().stateNumber != right.getState().stateNumber) { return false; } if (leftKey != getKey(right)) { return false; } return left.getSemanticContext().equals(right.getSemanticContext()); }
private void updatePropertiesForAddedConfig(ATNConfig config) { if (configs.size() == 1) { uniqueAlt = config.getAlt(); } else if (uniqueAlt != config.getAlt()) { uniqueAlt = ATN.INVALID_ALT_NUMBER; } hasSemanticContext |= !SemanticContext.NONE.equals(config.getSemanticContext()); dipsIntoOuterContext |= config.getReachesIntoOuterContext(); assert !outermostConfigSet || !dipsIntoOuterContext; }
protected ActionATNConfig(LexerActionExecutor lexerActionExecutor, @NotNull ATNConfig c, @NotNull ATNState state, @Nullable PredictionContext context, boolean passedThroughNonGreedyDecision) { super(c, state, context); if (c.getSemanticContext() != SemanticContext.NONE) { throw new UnsupportedOperationException(); } this.lexerActionExecutor = lexerActionExecutor; this.passedThroughNonGreedyDecision = passedThroughNonGreedyDecision; }
public final ATNConfig transform(@NotNull ATNState state, LexerActionExecutor lexerActionExecutor, boolean checkNonGreedy) { return transform(state, context, this.getSemanticContext(), checkNonGreedy, lexerActionExecutor); }
@Override public int compare(ATNConfig o1, ATNConfig o2) { if (o1.getAlt() != o2.getAlt()) { return o1.getAlt() - o2.getAlt(); } else if (o1.getState().stateNumber != o2.getState().stateNumber) { return o1.getState().stateNumber - o2.getState().stateNumber; } else { return o1.getSemanticContext().toString().compareTo(o2.getSemanticContext().toString()); } } });
buf.append(contextDesc); if ( getSemanticContext()!=null && getSemanticContext() != SemanticContext.NONE ) { buf.append(","); buf.append(getSemanticContext());
public final ATNConfig transform(@NotNull ATNState state, boolean checkNonGreedy) { return transform(state, this.context, this.getSemanticContext(), checkNonGreedy, this.getLexerActionExecutor()); }
public final ATNConfig transform(@NotNull ATNState state, @Nullable PredictionContext context, boolean checkNonGreedy) { return transform(state, context, this.getSemanticContext(), checkNonGreedy, this.getLexerActionExecutor()); }
if (this.getState().stateNumber != subconfig.getState().stateNumber || this.getAlt() != subconfig.getAlt() || !this.getSemanticContext().equals(subconfig.getSemanticContext())) { return false;
for (ATNConfig c : configs) { if ( ambigAlts.get(c.getAlt()) ) { altToPred[c.getAlt()] = SemanticContext.or(altToPred[c.getAlt()], c.getSemanticContext());
public boolean equals(ATNConfig other) { if (this == other) { return true; } else if (other == null) { return false; } return this.getState().stateNumber==other.getState().stateNumber && this.getAlt()==other.getAlt() && this.getReachesIntoOuterContext() == other.getReachesIntoOuterContext() && this.getContext().equals(other.getContext()) && this.getSemanticContext().equals(other.getSemanticContext()) && this.isPrecedenceFilterSuppressed() == other.isPrecedenceFilterSuppressed() && this.hasPassedThroughNonGreedyDecision() == other.hasPassedThroughNonGreedyDecision() && ObjectEqualityComparator.INSTANCE.equals(this.getLexerActionExecutor(), other.getLexerActionExecutor()); }
@Nullable protected ATNConfig predTransition(@NotNull ATNConfig config, @NotNull PredicateTransition pt, boolean collectPredicates, boolean inContext) { if ( debug ) { System.out.println("PRED (collectPredicates="+collectPredicates+") "+ pt.ruleIndex+":"+pt.predIndex+ ", ctx dependent="+pt.isCtxDependent); if ( parser != null ) { System.out.println("context surrounding pred is "+ parser.getRuleInvocationStack()); } } ATNConfig c; if ( collectPredicates && (!pt.isCtxDependent || (pt.isCtxDependent&&inContext)) ) { SemanticContext newSemCtx = SemanticContext.and(config.getSemanticContext(), pt.getPredicate()); c = config.transform(pt.target, newSemCtx, false); } else { c = config.transform(pt.target, false); } if ( debug ) System.out.println("config from pred transition="+c); return c; }
@Nullable protected ATNConfig precedenceTransition(@NotNull ATNConfig config, @NotNull PrecedencePredicateTransition pt, boolean collectPredicates, boolean inContext) { if ( debug ) { System.out.println("PRED (collectPredicates="+collectPredicates+") "+ pt.precedence+">=_p"+ ", ctx dependent=true"); if ( parser != null ) { System.out.println("context surrounding pred is "+ parser.getRuleInvocationStack()); } } ATNConfig c; if (collectPredicates && inContext) { SemanticContext newSemCtx = SemanticContext.and(config.getSemanticContext(), pt.getPredicate()); c = config.transform(pt.target, newSemCtx, false); } else { c = config.transform(pt.target, false); } if ( debug ) System.out.println("config from pred transition="+c); return c; }
SemanticContext updatedContext = config.getSemanticContext().evalPrecedence(parser, globalContext); if (updatedContext == null) { if (updatedContext != config.getSemanticContext()) { configSet.add(config.transform(config.getState(), updatedContext, false), contextCache);
@Override public int hashCode() { int hashCode = MurmurHash.initialize(7); hashCode = MurmurHash.update(hashCode, getState().stateNumber); hashCode = MurmurHash.update(hashCode, getAlt()); hashCode = MurmurHash.update(hashCode, getReachesIntoOuterContext() ? 1 : 0); hashCode = MurmurHash.update(hashCode, getContext()); hashCode = MurmurHash.update(hashCode, getSemanticContext()); hashCode = MurmurHash.update(hashCode, hasPassedThroughNonGreedyDecision() ? 1 : 0); hashCode = MurmurHash.update(hashCode, getLexerActionExecutor()); hashCode = MurmurHash.finish(hashCode, 7); return hashCode; }
PredictionContext newContext = config.getContext().getParent(i); // "pop" return state ATNState returnState = atn.states.get(config.getContext().getReturnState(i)); ATNConfig c = ATNConfig.create(returnState, config.getAlt(), newContext, config.getSemanticContext());