Example #1
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected block name (identifier)."
        if isinstance(token, CharacterToken):
            if (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = NameBlock(
                        parserState.LastBlock,
                        parserState.TokenMarker,
                        endToken=parserState.NewToken.PreviousToken,
                        multiPart=True)
                    _ = LinebreakBlock(parserState.NewBlock,
                                       parserState.NewToken)
                else:
                    parserState.NewBlock = LinebreakBlock(
                        parserState.LastBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = NameBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.NewToken = LinebreakToken(token)
                _ = LinebreakBlock(parserState.NewBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "/"):
                parserState.NewBlock = NameBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateBlockName
            return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Example #2
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected  '(' after keyword GENERIC."
        if isinstance(token, CharacterToken):
            if (token == "("):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=parserState.NewToken)
                parserState.NextState = CloseBlock.stateClosingParenthesis
                parserState.PushState = OpenBlock.stateOpeningParenthesis
                parserState.Counter = 1
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = OpenBlock(
                        parserState.LastBlock,
                        parserState.TokenMarker,
                        endToken=parserState.NewToken.PreviousToken,
                        multiPart=True)
                    _ = LinebreakBlock(parserState.NewBlock,
                                       parserState.NewToken)
                else:
                    parserState.NewBlock = LinebreakBlock(
                        parserState.LastBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Example #3
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';'."
        if isinstance(token, CharacterToken):
            if (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken)
                parserState.Pop()
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = SignalAssignmentBlock(
                        parserState.LastBlock,
                        parserState.TokenMarker,
                        endToken=token.PreviousToken,
                        multiPart=True)
                    _ = LinebreakBlock(parserState.NewBlock,
                                       parserState.NewToken)
                else:
                    parserState.NewBlock = LinebreakBlock(
                        parserState.LastBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Example #4
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected keyword IS after block name."
        if isinstance(token, CharacterToken):
            if (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = NameBlock(
                        parserState.LastBlock,
                        parserState.TokenMarker,
                        endToken=parserState.NewToken.PreviousToken,
                        multiPart=True)
                    _ = LinebreakBlock(parserState.NewBlock,
                                       parserState.NewToken)
                else:
                    parserState.NewBlock = LinebreakBlock(
                        parserState.LastBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = NameBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = NameBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, StringToken) and (token <= "is")):
            parserState.NewToken = IsKeyword(token)
            parserState.NewBlock = NameBlock(parserState.LastBlock,
                                             parserState.TokenMarker,
                                             endToken=parserState.NewToken)
            parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
            return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Example #5
0
    def stateSignalAssignmentKeyword(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected whitespace after keyword SignalAssignment."
        if isinstance(token, CharacterToken):
            if (token == "\n"):
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.NewToken = LinebreakToken(token)
                _ = LinebreakBlock(parserState.NewBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = SignalAssignmentBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace1
            return

        raise TokenParserException(errorMessage, token)
Example #6
0
    def stateClosingParenthesis(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';' or whitespace."
        if isinstance(token, CharacterToken):
            if (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = CloseBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken)
                parserState.Pop()
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                parserState.PushState = LinebreakBlock.stateLinebreak
                parserState.TokenMarker = parserState.NewToken
                return
            elif (token == "-"):
                parserState.NewBlock = CloseBlock(parserState.LastBlock,
                                                  parserState.TokenMarker,
                                                  endToken=token.PreviousToken,
                                                  multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = CloseBlock(parserState.LastBlock,
                                                  parserState.TokenMarker,
                                                  endToken=token.PreviousToken,
                                                  multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, SpaceToken):
            parserState.NextState = cls.stateWhitespace1
            return

        raise TokenParserException(errorMessage, token)
Example #7
0
    def stateOpeningParenthesis(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected generic name (identifier)."
        if isinstance(token, CharacterToken):
            if (token == ")"):
                # if (parserState.TokenMarker != token):
                # 	parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.TokenMarker, token.PreviousToken)
                parserState.Pop()
                parserState.TokenMarker = token
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                      parserState.NewToken)
                parserState.TokenMarker = None
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = IndentationToken(token)
            parserState.NewBlock = IndentationBlock(parserState.LastBlock,
                                                    parserState.NewToken)
            return
        elif isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = ItemBlock.stateItemRemainder

            # if (parserState.TokenMarker != token):
            # 	parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.TokenMarker, token)
            return

        raise TokenParserException(errorMessage, token)
Example #8
0
    def stateItemDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected generic name (identifier)."

        if (isinstance(token, CharacterToken) and (token == "\n")):
            parserState.NewToken = LinebreakToken(token)
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                  parserState.NewToken)
            parserState.TokenMarker = None
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            parserState.PushState = LinebreakBlock.stateLinebreak
            return
        elif isinstance(token, SpaceToken):
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            return
        elif isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = ItemBlock.stateItemRemainder
            return

        raise TokenParserException(errorMessage, token)