示例#1
0
    def stateObjectName(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace2
            return
        elif (isinstance(token, CharacterToken) and (token == ":")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateColon1
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = block(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace2
            return

        raise TokenParserException(
            "Expected whitespace after interface {0} name.".format(
                cls.OBJECT_KIND), token)
示例#2
0
 def stateItemRemainder(cls, parserState: ParserState):
     token = parserState.Token
     if isinstance(token, CharacterToken):
         if (token == "("):
             parserState.Counter += 1
         elif (token == ")"):
             parserState.Counter -= 1
             if (parserState.Counter == 0):
                 parserState.NewToken = BoundaryToken(token)
                 parserState.NewBlock = ItemBlock(
                     parserState.LastBlock,
                     parserState.TokenMarker,
                     endToken=parserState.NewToken.PreviousToken)
                 _ = CloseBlock(parserState.NewBlock, parserState.NewToken)
                 parserState.Pop()
                 parserState.TokenMarker = None
             else:
                 parserState.NewToken = ClosingRoundBracketToken(token)
                 # parserState.NewBlock =    CloseBlock(parserState.LastBlock, parserState.NewToken)
                 # parserState.Pop()
         elif (token == ";"):
             if (parserState.Counter == 1):
                 parserState.NewToken = DelimiterToken(token)
                 parserState.NewBlock = ItemBlock(
                     parserState.LastBlock,
                     parserState.TokenMarker,
                     endToken=parserState.NewToken.PreviousToken)
                 _ = DelimiterBlock(parserState.NewBlock,
                                    parserState.NewToken)
                 parserState.NextState = DelimiterBlock.stateItemDelimiter
             else:
                 raise TokenParserException(
                     "Mismatch in opening and closing parenthesis: open={0}"
                     .format(parserState.Counter), token)
示例#3
0
    def stateDot1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.statePackageName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = cls.statePackageName
            return
        elif (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot1
            return
        elif isinstance(token, SpaceToken):
            #parserState.NewToken =    BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace2
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = block(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace2
            return

        raise BlockParserException("Expected package name after '.'.", token)
示例#4
0
    def stateWhitespace5(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ","):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken)
                _ = DelimiterBlock(parserState.NewBlock,
                                   parserState.NewToken,
                                   endToken=parserState.NewToken)
                parserState.NextState = DelimiterBlock.stateDelimiter
                return
            elif (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = EndBlock(parserState.NewBlock,
                             parserState.NewToken,
                             endToken=parserState.NewToken)
                parserState.Pop()
                parserState.TokenMarker = None
                return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise BlockParserException("Expected ',' or ';'.", token)
示例#5
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ';'):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.DELIMITER_BLOCK(parserState.NewBlock,
                                        parserState.NewToken)
                parserState.Pop()
                return
            elif (token == ')'):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.Pop(2)
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, LinebreakToken):
            if (not (isinstance(parserState.LastBlock, CommentBlock)
                     and isinstance(parserState.LastBlock.StartToken,
                                    MultiLineCommentToken))):
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken,
                                           multiPart=True)
                _ = LinebreakBlock(parserState.NewBlock, token)
            else:
                parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                      token)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = CommentBlock(parserState.LastBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException("Expected ';' or ')'.", token)
示例#6
0
    def stateSubtypeIndication(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, FusedCharacterToken) and (token == ":=")):
            parserState.NewToken = VariableAssignmentKeyword(token)
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=parserState.NewToken)
            parserState.NextState = cls.DELIMITER_BLOCK.stateItemDelimiter
            parserState.PushState = cls.EXPRESSION.stateBeforeExpression
            parserState.TokenMarker = None
            parserState.Counter = 0
            return
        elif isinstance(token, CharacterToken):
            if (token == ';'):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.DELIMITER_BLOCK(parserState.NewBlock,
                                        parserState.NewToken)
                parserState.Pop()
                return
            elif (token == ')'):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.Pop(2)
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace5
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = block(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace5
            return

        raise TokenParserException(
            "Expected ';', ':=' or whitespace after subtype indication.",
            token)
示例#7
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.statePackageName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = cls.statePackageName
            return
        elif (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot1
            return
        elif isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = cls.statePackageName
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise BlockParserException("Expected package name (identifier).",
                                   token)
示例#8
0
    def stateWhitespace4(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot1
            return
        elif isinstance(token, StringToken):
            if (token <= "all"):
                parserState.NewToken = AllKeyword(token)
            else:
                parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateObjectName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = cls.stateObjectName
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(
            "Expected object name (identifier) or keyword ALL.", token)
示例#9
0
    def stateObjectName(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ","):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken)
                _ = DelimiterBlock(parserState.NewBlock,
                                   parserState.NewToken,
                                   endToken=parserState.NewToken)
                parserState.NextState = DelimiterBlock.stateDelimiter
                return
            elif (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken)
                _ = EndBlock(parserState.NewBlock,
                             parserState.NewToken,
                             endToken=parserState.NewToken)
                parserState.Pop()
                return
        elif isinstance(token, SpaceToken):
            # parserState.NewToken =    WhitespaceBlock(parserState.LastBlock, token)
            parserState.NextState = cls.stateWhitespace5
            return
        elif isinstance(token, LinebreakToken):
            parserState.NextState = cls.stateWhitespace5
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace5
            return

        raise BlockParserException("Expected ',', ';' or whitespace.", token)
示例#10
0
    def stateTypeName(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ';'):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.DELIMITER_BLOCK(parserState.NewBlock,
                                        parserState.NewToken)
                parserState.Pop()
                return
            elif (token == ')'):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.Pop(2)
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace2
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = block(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace2
            return

        raise TokenParserException(
            "Expected ';', ')' or whitespace after interface type name.",
            token)
示例#11
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ":")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateColon1
            return
        elif isinstance(token, LinebreakToken):
            if (not (isinstance(parserState.LastBlock, CommentBlock)
                     and isinstance(parserState.LastBlock.StartToken,
                                    MultiLineCommentToken))):
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken,
                                           multiPart=True)
                _ = LinebreakBlock(parserState.NewBlock, token)
            else:
                parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                      token)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = CommentBlock(parserState.LastBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(
            "Expected ':' after interface {0} name.".format(cls.OBJECT_KIND),
            token)
示例#12
0
    def stateLibraryName(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot1
            return
        elif isinstance(token, SpaceToken):
            #parserState.NewToken =    BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace1
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = block(parserState.NewBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace1
            return

        raise TokenParserException("Expected '.' after library name.", token)
示例#13
0
    def stateWhitespace5(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, FusedCharacterToken) and (token == ":=")):
            parserState.NewToken = VariableAssignmentKeyword(token)
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=parserState.NewToken)
            parserState.NextState = cls.DELIMITER_BLOCK.stateItemDelimiter
            parserState.PushState = cls.EXPRESSION.stateBeforeExpression
            parserState.Counter = 0
            return
        elif isinstance(token, CharacterToken):
            if (token == ';'):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.DELIMITER_BLOCK(parserState.NewBlock,
                                        parserState.NewToken)
                parserState.Pop()
                return
            elif (token == ')'):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.Pop(2)
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, LinebreakToken):
            if (not (isinstance(parserState.LastBlock, CommentBlock)
                     and isinstance(parserState.LastBlock.StartToken,
                                    MultiLineCommentToken))):
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken,
                                           multiPart=True)
                _ = LinebreakBlock(parserState.NewBlock, token)
            else:
                parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                      token)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = CommentBlock(parserState.LastBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException("Expected ';' or ':='.", token)