Exemplo n.º 1
0
    def stateDeclarativeRegion(cls, parserState: ParserState):
        errorMessage = "Expected one of these keywords: generic, port, begin, end."
        token = parserState.Token
        if isinstance(parserState.Token, CharacterToken):
            if (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                parserState.NewBlock = LinebreakBlock(parserState.LastBlock,
                                                      parserState.NewToken)
                parserState.TokenMarker = parserState.NewToken
                return
            elif (token == "-"):
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                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):
            keyword = token.Value.lower()
            if (keyword == "generic"):
                newToken = GenericKeyword(token)
                parserState.PushState = GenericList.OpenBlock.stateGenericKeyword
            elif (keyword == "port"):
                newToken = PortKeyword(token)
                parserState.PushState = PortList.OpenBlock.statePortKeyword
            elif (keyword == "end"):
                newToken = EndKeyword(token)
                parserState.NextState = EndGenerateBlock.stateEndKeyword
            elif (keyword == "begin"):
                parserState.NewToken = BeginKeyword(token)
                parserState.NewBlock = ElseGenerateBeginBlock(
                    parserState.LastBlock, parserState.NewToken)
                parserState.NextState = ElseGenerateBeginBlock.stateBeginKeyword
                return
            else:
                raise TokenParserException(errorMessage, token)

            parserState.NewToken = newToken
            parserState.TokenMarker = newToken
            return

        raise TokenParserException(errorMessage, token)
Exemplo n.º 2
0
    def stateAfterSensitivityList(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            tokenValue = token.Value.lower()

            for keyword in OpenBlock2.KEYWORDS:
                if (tokenValue == keyword.__KEYWORD__):
                    newToken = keyword(token)
                    parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
                    parserState.PushState = OpenBlock2.KEYWORDS[keyword]
                    parserState.NewToken = newToken
                    parserState.TokenMarker = newToken
                    return

            if (tokenValue == "begin"):
                parserState.NewToken = BeginKeyword(token)
                parserState.NewBlock = BeginBlock(parserState.LastBlock,
                                                  parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = BeginBlock.stateSequentialRegion
                return
            elif (tokenValue == "is"):
                parserState.NewToken = IsKeyword(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
                return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = cls.stateWhitespace1
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = block(parserState.LastBlock, token)
            parserState.TokenMarker = None
            parserState.NextState = cls.stateWhitespace1
            return

        raise TokenParserException("Expected whitespace after keyword ENTITY.",
                                   token)
Exemplo n.º 3
0
	def stateDeclarativeRegion(cls, parserState: ParserState):
		token = parserState.Token
		if 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 =      CommentBlock(parserState.LastBlock, token)
			parserState.TokenMarker =   None
			return
		elif isinstance(token, WordToken):
			tokenValue = token.Value.lower()

			for keyword in cls.KEYWORDS:
				if (tokenValue == keyword.__KEYWORD__):
					newToken =                keyword(token)
					parserState.PushState =   cls.KEYWORDS[keyword]
					parserState.NewToken =    newToken
					parserState.TokenMarker = newToken
					return

			if (tokenValue == "begin"):
				parserState.NewToken =  BeginKeyword(token)
				parserState.NewBlock =  cls.BEGIN_BLOCK(parserState.LastBlock, parserState.NewToken)
				parserState.NextState = cls.BEGIN_BLOCK.stateStatementRegion
				return
			elif (tokenValue == "end"):
				parserState.NewToken =  EndKeyword(token)
				parserState.NextState = cls.END_BLOCK.stateEndKeyword
				return

		raise BlockParserException(
			"Expected one of these keywords: BEGIN, END, {keywords}. Found: '{tokenValue}'.".format(
				keywords=", ".join(
					[kw.__KEYWORD__.upper() for kw in cls.KEYWORDS]
				),
				tokenValue=token.Value
			), token)
Exemplo n.º 4
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == "(")):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=parserState.NewToken)
            parserState.NextState = OpenBlock2.stateAfterSensitivityList
            parserState.PushState = SensitivityList.OpenBlock.stateOpeningParenthesis
            parserState.Counter = 1
            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
        elif isinstance(token, StringToken):
            tokenValue = token.Value.lower()

            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken)

            for keyword in OpenBlock2.KEYWORDS:
                if (tokenValue == keyword.__KEYWORD__):
                    newToken = keyword(token)
                    parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
                    parserState.PushState = cls.KEYWORDS[keyword]
                    parserState.NewToken = newToken
                    parserState.TokenMarker = newToken
                    return

            if (tokenValue == "begin"):
                parserState.NewToken = BeginKeyword(token)
                _ = BeginBlock(parserState.NewBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = BeginBlock.stateSequentialRegion
                return

        raise TokenParserException("Expected '(' after keyword PROCESS.",
                                   token)
Exemplo n.º 5
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            tokenValue = token.Value.lower()

            for keyword in cls.KEYWORDS:
                if (tokenValue == keyword.__KEYWORD__):
                    newToken = keyword(token)
                    parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
                    parserState.PushState = cls.KEYWORDS[keyword]
                    parserState.NewToken = newToken
                    parserState.TokenMarker = newToken
                    return

            if (tokenValue == "begin"):
                parserState.NewToken = BeginKeyword(token)
                parserState.NewBlock = BeginBlock(parserState.LastBlock,
                                                  parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = BeginBlock.stateSequentialRegion
                return
            elif (tokenValue == "is"):
                parserState.NewToken = IsKeyword(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = DeclarativeRegion.stateDeclarativeRegion
                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 = 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 declarations or keyword IS after sensitivity list.",
            token)