예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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