Пример #1
0
    def stateDot2(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            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, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace4
            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.stateWhitespace4
            return

        raise BlockParserException("Expected object name after '.'.", token)
Пример #2
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, WordToken):
            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 BlockParserException(
            "Expected object name (identifier) or keyword ALL.", token)
Пример #3
0
    def stateOpeningParenthesis(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            if (token <= "all"):
                parserState.NewToken = AllKeyword(token)
                parserState.NewBlock = ItemBlock(parserState.LastBlock,
                                                 parserState.NewToken,
                                                 endToken=parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = CloseBlock.stateAllKeyword
            else:
                parserState.NewToken = IdentifierToken(token)
                parserState.TokenMarker = parserState.NewToken
                parserState.NextState = ItemBlock.stateItemRemainder
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = ItemBlock.stateItemRemainder
            return
        elif isinstance(token, SpaceToken):
            blockType = IndentationBlock if isinstance(
                token, IndentationToken) else WhitespaceBlock
            parserState.NewBlock = blockType(parserState.LastBlock, token)
            parserState.TokenMarker = None
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            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

        raise BlockParserException(
            "Expected keyword ALL or signal name (identifier).", token)