Beispiel #1
0
 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
 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
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
    def getControlRecoverySet(self, recognizer: Parser):
        ctx = recognizer._ctx
        recoverSet = IntervalSet()

        while ctx is not None and ctx.invokingState >= 0:

            # If statement (for Else we only want EndIf):
            if isinstance(
                    ctx,
                (wizardParser.IfStmtContext, wizardParser.ElifStmtContext)):
                recoverSet.addOne(wizardLexer.Elif)
                recoverSet.addOne(wizardLexer.Else)
                recoverSet.addOne(wizardLexer.EndIf)
            elif isinstance(ctx, wizardParser.ElseStmtContext):
                recoverSet.addOne(wizardLexer.EndIf)

            # For/While statement:
            elif isinstance(ctx, wizardParser.ForStmtContext):
                recoverSet.addOne(wizardLexer.EndFor)
            elif isinstance(ctx, wizardParser.WhileStmtContext):
                recoverSet.addOne(wizardLexer.EndWhile)

            # Case/Default context:
            elif isinstance(
                    ctx,
                (wizardParser.CaseStmtContext,
                 wizardParser.DefaultStmtContext),
            ):
                recoverSet.addOne(wizardLexer.Break)

            # Select context:
            elif isinstance(ctx, wizardParser.SelectStmtContext):
                recoverSet.addOne(wizardLexer.EndSelect)

            ctx = ctx.parentCtx
        recoverSet.removeOne(Token.EPSILON)

        return recoverSet