def addDFAState(self, configs: ATNConfigSet) -> DFAState: # the lexer evaluates predicates on-the-fly; by this point configs # should not contain any configurations with unevaluated predicates. assert not configs.hasSemanticContext proposed = DFAState(configs=configs) firstConfigWithRuleStopState = None for c in configs: if isinstance(c.state, RuleStopState): firstConfigWithRuleStopState = c break if firstConfigWithRuleStopState is not None: proposed.isAcceptState = True proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor proposed.prediction = self.atn.ruleToTokenType[ firstConfigWithRuleStopState.state.ruleIndex] dfa = self.decisionToDFA[self.mode] existing = dfa.states.get(proposed, None) if existing is not None: return existing newState = proposed newState.stateNumber = len(dfa.states) configs.setReadonly(True) newState.configs = configs dfa.states[newState] = newState return newState
def addDFAState(self, configs): proposed = DFAState(configs=configs) firstConfigWithRuleStopState = next( (cfg for cfg in configs if isinstance(cfg.state, RuleStopState)), None) if firstConfigWithRuleStopState is not None: proposed.isAcceptState = True proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor proposed.prediction = self.atn.ruleToTokenType[ firstConfigWithRuleStopState.state.ruleIndex] dfa = self.decisionToDFA[self.mode] existing = dfa.states.get(proposed, None) if existing is not None: return existing newState = proposed newState.stateNumber = len(dfa.states) configs.setReadonly(True) newState.configs = configs dfa.states[newState] = newState return newState
def addDFAState(self, configs:ATNConfigSet) -> DFAState: proposed = DFAState(configs=configs) firstConfigWithRuleStopState = None for c in configs: if isinstance(c.state, RuleStopState): firstConfigWithRuleStopState = c break if firstConfigWithRuleStopState is not None: proposed.isAcceptState = True proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor proposed.prediction = self.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex] dfa = self.decisionToDFA[self.mode] existing = dfa.states.get(proposed, None) if existing is not None: return existing newState = proposed newState.stateNumber = len(dfa.states) configs.setReadonly(True) newState.configs = configs dfa.states[newState] = newState return newState
def addDFAState(self, configs): # the lexer evaluates predicates on-the-fly; by this point configs # should not contain any configurations with unevaluated predicates. assert not configs.hasSemanticContext proposed = DFAState(configs=configs) firstConfigWithRuleStopState = None for c in configs: if isinstance(c.state, RuleStopState): firstConfigWithRuleStopState = c break if firstConfigWithRuleStopState is not None: proposed.isAcceptState = True proposed.lexerActionExecutor = firstConfigWithRuleStopState.lexerActionExecutor proposed.prediction = self.atn.ruleToTokenType[firstConfigWithRuleStopState.state.ruleIndex] dfa = self.decisionToDFA[self.mode] existing = dfa.states.get(proposed, None) if existing is not None: return existing newState = proposed newState.stateNumber = len(dfa.states) configs.setReadonly(True) newState.configs = configs dfa.states[newState] = newState return newState