当前位置: 首页>>代码示例>>Python>>正文


Python IntervalSet.IntervalSet类代码示例

本文整理汇总了Python中antlr4.IntervalSet.IntervalSet的典型用法代码示例。如果您正苦于以下问题:Python IntervalSet类的具体用法?Python IntervalSet怎么用?Python IntervalSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IntervalSet类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getErrorRecoverySet

 def getErrorRecoverySet(self, recognizer:Parser):
     atn = recognizer._interp.atn
     ctx = recognizer._ctx
     recoverSet = IntervalSet()
     while ctx is not None and ctx.invokingState>=0:
         # compute what follows who invoked us
         invokingState = atn.states[ctx.invokingState]
         rt = invokingState.transitions[0]
         follow = atn.nextTokens(rt.followState)
         recoverSet.addSet(follow)
         ctx = ctx.parentCtx
     recoverSet.removeOne(Token.EPSILON)
     return recoverSet
开发者ID:lecode-official,项目名称:antlr4,代码行数:13,代码来源:ErrorStrategy.py

示例2: SetTransition

class SetTransition(Transition):
    def __init__(self, target, set):
        super(SetTransition, self).__init__(target)
        self.serializationType = self.SET
        if set is not None:
            self.label = set
        else:
            self.label = IntervalSet()
            self.label.addRange(Interval(Token.INVALID_TYPE, Token.INVALID_TYPE + 1))

    def matches(self, symbol, minVocabSymbol, maxVocabSymbol):
        return symbol in self.label

    def __unicode__(self):
        return unicode(self.label)
开发者ID:antlr,项目名称:antlr4,代码行数:15,代码来源:Transition.py

示例3: SetTransition

class SetTransition(Transition):

    def __init__(self, target:ATNState, set:IntervalSet):
        super().__init__(target)
        self.serializationType = self.SET
        if set is not None:
            self.label = set
        else:
            self.label = IntervalSet()
            self.label.addRange(range(Token.INVALID_TYPE, Token.INVALID_TYPE + 1))

    def matches( self, symbol:int, minVocabSymbol:int,  maxVocabSymbol:int):
        return symbol in self.label

    def __str__(self):
        return str(self.label)
开发者ID:Yuxinghan,项目名称:antlr4-python3,代码行数:16,代码来源:Transition.py

示例4: __init__

 def __init__(self, target:ATNState, set:IntervalSet):
     super().__init__(target)
     self.serializationType = self.SET
     if set is not None:
         self.label = set
     else:
         self.label = IntervalSet()
         self.label.addRange(range(Token.INVALID_TYPE, Token.INVALID_TYPE + 1))
开发者ID:Yuxinghan,项目名称:antlr4-python3,代码行数:8,代码来源:Transition.py

示例5: __init__

 def __init__(self, target, set):
     super(SetTransition, self).__init__(target)
     self.serializationType = self.SET
     if set is not None:
         self.label = set
     else:
         self.label = IntervalSet()
         self.label.addRange(Interval(Token.INVALID_TYPE, Token.INVALID_TYPE + 1))
开发者ID:Ali-Khorshidi,项目名称:antlr4,代码行数:8,代码来源:Transition.py

示例6: makeLabel

 def makeLabel(self):
     s = IntervalSet()
     s.addRange(range(self.start, self.stop + 1))
     return s
开发者ID:Yuxinghan,项目名称:antlr4-python3,代码行数:4,代码来源:Transition.py

示例7: getExpectedTokens

 def getExpectedTokens(self, stateNumber: int, ctx: RuleContext):
     if stateNumber < 0 or stateNumber >= len(self.states):
         raise Exception("Invalid state number.")
     s = self.states[stateNumber]
     following = self.nextTokens(s)
     if Token.EPSILON not in following:
         return following
     expected = IntervalSet()
     expected.addSet(following)
     expected.removeOne(Token.EPSILON)
     while ctx != None and ctx.invokingState >= 0 and Token.EPSILON in following:
         invokingState = self.states[ctx.invokingState]
         rt = invokingState.transitions[0]
         following = self.nextTokens(rt.followState)
         expected.addSet(following)
         expected.removeOne(Token.EPSILON)
         ctx = ctx.parentCtx
     if Token.EPSILON in following:
         expected.addOne(Token.EOF)
     return expected
开发者ID:CodeGrimoire,项目名称:antlr4,代码行数:20,代码来源:ATN.py

示例8: _LOOK

    def _LOOK(self, s:ATNState, stopState:ATNState , ctx:PredictionContext, look:IntervalSet, lookBusy:set,
                     calledRuleStack:set, seeThruPreds:bool, addEOF:bool):
        c = ATNConfig(s, 0, ctx)

        if c in lookBusy:
            return
        lookBusy.add(c)

        if s == stopState:
            if ctx is None:
                look.addOne(Token.EPSILON)
                return
            elif ctx.isEmpty() and addEOF:
                look.addOne(Token.EOF)
                return

        if isinstance(s, RuleStopState ):
            if ctx is None:
                look.addOne(Token.EPSILON)
                return
            elif ctx.isEmpty() and addEOF:
                look.addOne(Token.EOF)
                return

            if ctx != PredictionContext.EMPTY:
                # run thru all possible stack tops in ctx
                for i in range(0, len(ctx)):
                    returnState = self.atn.states[ctx.getReturnState(i)]
                    removed = returnState.ruleIndex in calledRuleStack
                    try:
                        calledRuleStack.discard(returnState.ruleIndex)
                        self._LOOK(returnState, stopState, ctx.getParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
                    finally:
                        if removed:
                            calledRuleStack.add(returnState.ruleIndex)
                return

        for t in s.transitions:
            if type(t) == RuleTransition:
                if t.target.ruleIndex in calledRuleStack:
                    continue

                newContext = SingletonPredictionContext.create(ctx, t.followState.stateNumber)

                try:
                    calledRuleStack.add(t.target.ruleIndex)
                    self._LOOK(t.target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
                finally:
                    calledRuleStack.remove(t.target.ruleIndex)
            elif isinstance(t, AbstractPredicateTransition ):
                if seeThruPreds:
                    self._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
                else:
                    look.addOne(self.HIT_PRED)
            elif t.isEpsilon:
                self._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
            elif type(t) == WildcardTransition:
                look.addRange( range(Token.MIN_USER_TOKEN_TYPE, self.atn.maxTokenType + 1) )
            else:
                set_ = t.label
                if set_ is not None:
                    if isinstance(t, NotSetTransition):
                        set_ = set_.complement(Token.MIN_USER_TOKEN_TYPE, self.atn.maxTokenType)
                    look.addSet(set_)
开发者ID:DanMcLaughlin,项目名称:antlr4,代码行数:64,代码来源:LL1Analyzer.py


注:本文中的antlr4.IntervalSet.IntervalSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。