def hasSLLConflictTerminatingPrediction(cls, mode, configs): # Configs in rule stop states indicate reaching the end of the decision # rule (local context) or end of start rule (full context). If all # configs meet this condition, then none of the configurations is able # to match additional input so we terminate prediction. # if cls.allConfigsInRuleStopStates(configs): return True # pure SLL mode parsing if mode == PredictionMode.SLL: # Don't bother with combining configs from different semantic # contexts if we can fail over to full LL; costs more time # since we'll often fail over anyway. if configs.hasSemanticContext: # dup configs, tossing out semantic predicates dup = ATNConfigSet() for c in configs: c = ATNConfig(config=c, semantic=SemanticContext.NONE) dup.add(c) configs = dup # now we have combined contexts for configs with dissimilar preds # pure SLL or combined SLL+LL mode parsing altsets = cls.getConflictingAltSubsets(configs) return cls.hasConflictingAltSet( altsets) and not cls.hasStateAssociatedWithOneAlt(configs)
def hasSLLConflictTerminatingPrediction(cls, mode, configs): # Configs in rule stop states indicate reaching the end of the decision # rule (local context) or end of start rule (full context). If all # configs meet this condition, then none of the configurations is able # to match additional input so we terminate prediction. # if cls.allConfigsInRuleStopStates(configs): return True # pure SLL mode parsing if mode == PredictionMode.SLL: # Don't bother with combining configs from different semantic # contexts if we can fail over to full LL; costs more time # since we'll often fail over anyway. if configs.hasSemanticContext: # dup configs, tossing out semantic predicates dup = ATNConfigSet() for c in configs: c = ATNConfig(c,SemanticContext.NONE) dup.add(c) configs = dup # now we have combined contexts for configs with dissimilar preds # pure SLL or combined SLL+LL mode parsing altsets = cls.getConflictingAltSubsets(configs) return cls.hasConflictingAltSet(altsets) and not cls.hasStateAssociatedWithOneAlt(configs)
def closure(self, input: InputStream, config: LexerATNConfig, configs: ATNConfigSet, currentAltReachedAcceptState: bool, speculative: bool, treatEofAsEpsilon: bool): if self.debug: print("closure(" + config.toString(self.recog, True) + ")") if isinstance(config.state, RuleStopState): if self.debug: if self.recog is not None: print("closure at %s rule stop %s\n", self.recog.getRuleNames()[config.state.ruleIndex], config) else: print("closure at rule stop %s\n", config) if config.context is None or config.context.hasEmptyPath(): if config.context is None or config.context.isEmpty(): configs.add(config) return True else: configs.add( LexerATNConfig(state=config.state, config=config, context=PredictionContext.EMPTY)) currentAltReachedAcceptState = True if config.context is not None and not config.context.isEmpty(): for i in range(0, len(config.context)): if config.context.getReturnState( i) != PredictionContext.EMPTY_RETURN_STATE: newContext = config.context.getParent( i) # "pop" return state returnState = self.atn.states[ config.context.getReturnState(i)] c = LexerATNConfig(state=returnState, config=config, context=newContext) currentAltReachedAcceptState = self.closure( input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon) return currentAltReachedAcceptState # optimization if not config.state.epsilonOnlyTransitions: if not currentAltReachedAcceptState or not config.passedThroughNonGreedyDecision: configs.add(config) for t in config.state.transitions: c = self.getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon) if c is not None: currentAltReachedAcceptState = self.closure( input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon) return currentAltReachedAcceptState
def closure( self, input: InputStream, config: LexerATNConfig, configs: ATNConfigSet, currentAltReachedAcceptState: bool, speculative: bool, treatEofAsEpsilon: bool, ): if self.debug: print("closure(" + config.toString(self.recog, True) + ")") if isinstance(config.state, RuleStopState): if self.debug: if self.recog is not None: print("closure at %s rule stop %s\n", self.recog.getRuleNames()[config.state.ruleIndex], config) else: print("closure at rule stop %s\n", config) if config.context is None or config.context.hasEmptyPath(): if config.context is None or config.context.isEmpty(): configs.add(config) return True else: configs.add(LexerATNConfig(state=config.state, config=config, context=PredictionContext.EMPTY)) currentAltReachedAcceptState = True if config.context is not None and not config.context.isEmpty(): for i in range(0, len(config.context)): if config.context.getReturnState(i) != PredictionContext.EMPTY_RETURN_STATE: newContext = config.context.getParent(i) # "pop" return state returnState = self.atn.states[config.context.getReturnState(i)] c = LexerATNConfig(state=returnState, config=config, context=newContext) currentAltReachedAcceptState = self.closure( input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon ) return currentAltReachedAcceptState # optimization if not config.state.epsilonOnlyTransitions: if not currentAltReachedAcceptState or not config.passedThroughNonGreedyDecision: configs.add(config) for t in config.state.transitions: c = self.getEpsilonTarget(input, config, t, configs, speculative, treatEofAsEpsilon) if c is not None: currentAltReachedAcceptState = self.closure( input, c, configs, currentAltReachedAcceptState, speculative, treatEofAsEpsilon ) return currentAltReachedAcceptState