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 setPrecedenceDfa(self, precedenceDfa): if self.precedenceDfa != precedenceDfa: self._states = dict() if precedenceDfa: precedenceState = DFAState(configs=ATNConfigSet()) precedenceState.edges = [] precedenceState.isAcceptState = False precedenceState.requiresFullContext = False self.s0 = precedenceState else: self.s0 = None self.precedenceDfa = precedenceDfa
def __init__(self, atnStartState, decision=0): # From which ATN state did we create this DFA? self.atnStartState = atnStartState self.decision = decision # A set of all DFA states. Use {@link Map} so we can get old state back # ({@link Set} only allows you to see if it's there). self._states = dict() self.s0 = None # {@code true} if this DFA is for a precedence decision; otherwise, # {@code false}. This is the backing field for {@link #isPrecedenceDfa}, # {@link #setPrecedenceDfa}. self.precedenceDfa = False if isinstance(atnStartState, StarLoopEntryState): if atnStartState.isPrecedenceDecision: self.precedenceDfa = True precedenceState = DFAState(configs=ATNConfigSet()) precedenceState.edges = [] precedenceState.isAcceptState = False precedenceState.requiresFullContext = False self.s0 = precedenceState