@Override public String toString() { return toString(null, true); }
protected ATNConfig actionTransition(ATNConfig config, ActionTransition t) { if ( debug ) System.out.println("ACTION edge "+t.ruleIndex+":"+t.actionIndex); return new ATNConfig(config, t.target); }
/** An ATN configuration is equal to another if both have * the same state, they predict the same alternative, and * syntactic/semantic contexts are the same. */ @Override public boolean equals(Object o) { if (!(o instanceof ATNConfig)) { return false; } return this.equals((ATNConfig)o); }
hasSemanticContext = true; if (config.getOuterContextDepth() > 0) { dipsIntoOuterContext = true; if (config.isPrecedenceFilterSuppressed()) { existing.setPrecedenceFilterSuppressed(true);
configSet.add(new ATNConfig(config, updatedContext), mergeCache); if (!config.isPrecedenceFilterSuppressed()) {
if ( config.getState() instanceof RuleStopState ) { if ( !config.getContext().isEmpty() ) { boolean hasEmpty = config.getContext().hasEmpty(); int nonEmptySize = config.getContext().size() - (hasEmpty ? 1 : 0); for (int i = 0; i < nonEmptySize; i++) { 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()); c.setOuterContextDepth(config.getOuterContextDepth()); c.setPrecedenceFilterSuppressed(config.isPrecedenceFilterSuppressed()); assert depth > Integer.MIN_VALUE; closure(c, configs, intermediate, closureBusy, collectPredicates, hasMoreContexts, contextCache, depth - 1, treatEofAsEpsilon); config = config.transform(config.getState(), PredictionContext.EMPTY_LOCAL, false); getRuleName(config.getState().ruleIndex)); if (config.getContext() == PredictionContext.EMPTY_FULL) { config = config.transform(config.getState(), PredictionContext.EMPTY_LOCAL, false); else if (!config.getReachesIntoOuterContext() && PredictionContext.isEmptyLocal(config.getContext())) { ATNState p = config.getState(); && p.getStateType() == ATNState.STAR_LOOP_ENTRY && ((StarLoopEntryState)p).precedenceRuleDecision
public boolean add(ATNConfig e, @Nullable PredictionContextCache contextCache) { ensureWritable(); assert !outermostConfigSet || !e.getReachesIntoOuterContext(); addKey = (mergedConfig == null); if (mergedConfig != null && canMerge(e, key, mergedConfig)) { mergedConfig.setOuterContextDepth(Math.max(mergedConfig.getOuterContextDepth(), e.getOuterContextDepth())); if (e.isPrecedenceFilterSuppressed()) { mergedConfig.setPrecedenceFilterSuppressed(true); PredictionContext joined = PredictionContext.join(mergedConfig.getContext(), e.getContext(), contextCache); updatePropertiesForMergedConfig(e); if (mergedConfig.getContext() == joined) { return false; mergedConfig.setContext(joined); return true; ATNConfig unmergedConfig = unmerged.get(i); if (canMerge(e, key, unmergedConfig)) { unmergedConfig.setOuterContextDepth(Math.max(unmergedConfig.getOuterContextDepth(), e.getOuterContextDepth())); if (e.isPrecedenceFilterSuppressed()) { unmergedConfig.setPrecedenceFilterSuppressed(true); PredictionContext joined = PredictionContext.join(unmergedConfig.getContext(), e.getContext(), contextCache); updatePropertiesForMergedConfig(e); if (unmergedConfig.getContext() == joined) { return false; unmergedConfig.setContext(joined);
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()); }
public String toString(Recognizer<?, ?> recog, boolean showAlt) { StringBuilder buf = new StringBuilder(); // if ( state.ruleIndex>=0 ) { // if ( recog!=null ) buf.append(recog.getRuleNames()[state.ruleIndex]+":"); // else buf.append(state.ruleIndex+":"); // } buf.append('('); buf.append(state); if ( showAlt ) { buf.append(","); buf.append(alt); } if ( context!=null ) { buf.append(",["); buf.append(context.toString()); buf.append("]"); } if ( semanticContext!=null && semanticContext != SemanticContext.NONE ) { buf.append(","); buf.append(semanticContext); } if ( getOuterContextDepth()>0 ) { buf.append(",up=").append(getOuterContextDepth()); } buf.append(')'); return buf.toString(); } }
contexts = getContext().toStrings(recog, this.getState().stateNumber); buf.append(getState()); if ( showAlt ) { buf.append(","); buf.append(getAlt()); if ( getContext()!=null ) { buf.append(","); buf.append(contextDesc); if ( getSemanticContext()!=null && getSemanticContext() != SemanticContext.NONE ) { buf.append(","); buf.append(getSemanticContext()); if ( getReachesIntoOuterContext() ) { buf.append(",up=").append(getOuterContextDepth());
for (ATNConfig config : configs) { if (config.getAlt() != 1) { continue; SemanticContext updatedContext = config.getSemanticContext().evalPrecedence(parser, globalContext); if (updatedContext == null) { statesFromAlt1.put(config.getState().stateNumber, config.getContext()); if (updatedContext != config.getSemanticContext()) { configSet.add(config.transform(config.getState(), updatedContext, false), contextCache); if (config.getAlt() == 1) { if (!config.isPrecedenceFilterSuppressed()) { PredictionContext context = statesFromAlt1.get(config.getState().stateNumber); if (context != null && context.equals(config.getContext())) {
public void dumpDeadEndConfigs(@NotNull NoViableAltException nvae) { System.err.println("dead end configs: "); for (ATNConfig c : nvae.getDeadEndConfigs()) { String trans = "no edges"; if ( c.getState().getNumberOfOptimizedTransitions()>0 ) { Transition t = c.getState().getOptimizedTransition(0); if ( t instanceof AtomTransition) { AtomTransition at = (AtomTransition)t; trans = "Atom "+getTokenName(at.label); } else if ( t instanceof SetTransition ) { SetTransition st = (SetTransition)t; boolean not = st instanceof NotSetTransition; trans = (not?"~":"")+"Set "+st.set.toString(); } } System.err.println(c.toString(parser, true)+":"+trans); } }
public boolean equals(ATNConfig other) { if (this == other) { return true; } else if (other == null) { return false; } return this.state.stateNumber==other.state.stateNumber && this.alt==other.alt && (this.context==other.context || (this.context != null && this.context.equals(other.context))) && this.semanticContext.equals(other.semanticContext) && this.isPrecedenceFilterSuppressed() == other.isPrecedenceFilterSuppressed(); }
int outermostPrecedenceReturn = ((EpsilonTransition)t).outermostPrecedenceReturn(); if (outermostPrecedenceReturn == _dfa.atnStartState.ruleIndex) { c.setPrecedenceFilterSuppressed(true);
boolean currentAltReachedAcceptState = c.getAlt() == skipAlt; if (currentAltReachedAcceptState && c.hasPassedThroughNonGreedyDecision()) { continue; int n = c.getState().getNumberOfOptimizedTransitions(); for (int ti=0; ti<n; ti++) { // for each optimized transition Transition trans = c.getState().getOptimizedTransition(ti); ATNState target = getReachableTarget(trans, t); if ( target!=null ) { LexerActionExecutor lexerActionExecutor = c.getLexerActionExecutor(); if (lexerActionExecutor != null) { lexerActionExecutor = lexerActionExecutor.fixOffsetBeforeMatch(input.index() - startIndex); if (closure(input, c.transform(target, lexerActionExecutor, true), reach, currentAltReachedAcceptState, true, treatEofAsEpsilon)) { skipAlt = c.getAlt(); break;
private ATNConfig transform(@NotNull ATNState state, @Nullable PredictionContext context, @NotNull SemanticContext semanticContext, boolean checkNonGreedy, LexerActionExecutor lexerActionExecutor) { boolean passedThroughNonGreedy = checkNonGreedy && checkNonGreedyDecision(this, state); if (semanticContext != SemanticContext.NONE) { if (lexerActionExecutor != null || passedThroughNonGreedy) { return new ActionSemanticContextATNConfig(lexerActionExecutor, semanticContext, this, state, context, passedThroughNonGreedy); } else { return new SemanticContextATNConfig(semanticContext, this, state, context); } } else if (lexerActionExecutor != null || passedThroughNonGreedy) { return new ActionATNConfig(lexerActionExecutor, this, state, context, passedThroughNonGreedy); } else { return new ATNConfig(this, state, context); } }
if (this.getState().stateNumber != subconfig.getState().stateNumber || this.getAlt() != subconfig.getAlt() || !this.getSemanticContext().equals(subconfig.getSemanticContext())) { return false; leftWorkList.add(getContext()); rightWorkList.add(subconfig.getContext()); while (!leftWorkList.isEmpty()) { PredictionContext left = leftWorkList.pop();
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; }