コード例 #1
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, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = ItemBlock.stateItemRemainder
            return

        raise BlockParserException(errorMessage, token)
コード例 #2
0
    def statePackageName(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot2
            return
        elif isinstance(token, SpaceToken):
            #parserState.NewToken =    BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace3
            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.stateWhitespace3
            return

        raise BlockParserException("Expected '.' after package name.", token)
コード例 #3
0
ファイル: __init__.py プロジェクト: el-coder-sb/pyVHDLParser
    def stateColon1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateSubtypeIndication
            return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace3
            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.stateWhitespace3
            return

        raise BlockParserException(
            "Expected subtype indication or whitespace after colon.", token)
コード例 #4
0
    def stateReturnKeyword(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected whitespace after keyword RETURN."
        if isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace2
            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(errorMessage, token)
コード例 #5
0
	def stateWhitespace2(cls, parserState: ParserState):
		token = parserState.Token
		errorMessage = "Expected keyword IS after generate name."
		if isinstance(token, CharacterToken):
			if (token == "\n"):
				parserState.NewToken =    LinebreakToken(token)
				if (not isinstance(parserState.LastBlock, MultiLineCommentBlock)):
					parserState.NewBlock =  CaseBlock(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 =    CaseBlock(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				parserState.TokenMarker = None
				parserState.PushState =   SingleLineCommentBlock.statePossibleCommentStart
				parserState.TokenMarker = token
				return
			elif (token == "/"):
				parserState.NewBlock =    CaseBlock(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				parserState.TokenMarker = None
				parserState.PushState =   MultiLineCommentBlock.statePossibleCommentStart
				parserState.TokenMarker = token
				return
		elif (isinstance(token, WordToken) and (token <= "is")):
			parserState.NewToken =      IsKeyword(token)
			parserState.NewBlock =      CaseBlock(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			parserState.NextState =     cls.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 BlockParserException(errorMessage, token)
コード例 #6
0
    def stateItemDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            tokenValue = token.Value.lower()
            if (tokenValue == "constant"):
                parserState.NewToken = ConstantKeyword(token)
                parserState.PushState = ParameterListInterfaceConstantBlock.stateConstantKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "variable"):
                parserState.NewToken = VariableKeyword(token)
                parserState.PushState = ParameterListInterfaceVariableBlock.stateVariableKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "signal"):
                parserState.NewToken = SignalKeyword(token)
                parserState.PushState = ParameterListInterfaceSignalBlock.stateSignalKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "type"):
                parserState.NewToken = TypeKeyword(token)
                parserState.PushState = ParameterListInterfaceTypeBlock.stateTypeKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "procedure"):
                raise NotImplementedError(
                    "Generic procedures are not supported.")
            elif (tokenValue == "function"):
                raise NotImplementedError(
                    "Generic functions are not supported.")
            elif (tokenValue == "impure"):
                raise NotImplementedError(
                    "Generic impure functions are not supported.")
            elif (tokenValue == "pure"):
                raise NotImplementedError(
                    "Generic pure functions are not supported.")
            else:
                parserState.NewToken = IdentifierToken(token)
                parserState.PushState = ParameterListInterfaceConstantBlock.stateObjectName
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = ParameterListInterfaceConstantBlock.stateObjectName
            return
        elif isinstance(token, SpaceToken):
            parserState.TokenMarker = token
            parserState.NextState = ItemBlock.stateItemRemainder
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            parserState.NextState = ItemBlock.stateItemRemainder
            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 TokenParserException("Expected parameter name (identifier).",
                                   token)
コード例 #7
0
ファイル: Procedure.py プロジェクト: el-coder-sb/pyVHDLParser
    def stateWhitespace2(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.PreviousToken)
            _ = ParameterList.OpenBlock(parserState.NewBlock,
                                        parserState.NewToken)
            parserState.TokenMarker = None
            parserState.NextState = VoidBlock.stateAfterParameterList
            parserState.PushState = ParameterList.OpenBlock.stateOpeningParenthesis
            parserState.Counter = 1
            return
        elif isinstance(token, WordToken):
            keyword = token.Value.lower()
            if (keyword == "is"):
                parserState.NewToken = IsKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = VoidBlock(parserState.NewBlock, parserState.NewToken)
                parserState.TokenMarker = parserState.NewToken
                parserState.NextState = VoidBlock.stateDeclarativeRegion
                return
            elif (keyword == "generic"):
                parserState.NewToken = GenericKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.NextState = GenericList.OpenBlock.stateGenericKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (keyword == "parameter"):
                parserState.NewToken = ParameterKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                parserState.NextState = ParameterList.OpenBlock.stateParameterKeyword
                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 = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            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 keywords GENERIC, PARAMETER or RETURN after procedure name.",
            token)
コード例 #8
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)
コード例 #9
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, FusedCharacterToken):
			parserState.NewToken =    cls.FUSED_CHARACTER_TRANSLATION[token.Value](token)
			parserState.NextState =   cls.stateExpression
			return
		elif isinstance(token, CharacterToken):
			if (token == ";"):
				if (parserState.Counter == 0):
					parserState.NewToken =  EndToken(token)
					parserState.NewBlock =  cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
					_ =                     cls.END_BLOCK(parserState.NewBlock, parserState.NewToken, endToken=parserState.NewToken)
					parserState.Pop(2)
					return
				else:
					raise BlockParserException("Mismatch in opening and closing parenthesis. Counter={0}".format(parserState.Counter), token)
			elif (token == "("):
				parserState.NewToken =    OpeningRoundBracketToken(token)
				parserState.Counter +=    1
				parserState.NextState =   cls.stateExpression
				return
			elif (token == ")"):
				if (parserState.Counter == -1):
					raise BlockParserException("Mismatch in opening and closing parenthesis. Counter={0}".format(parserState.Counter), token)
				else:
					parserState.NewToken =  ClosingRoundBracketToken(token)
					parserState.Counter -=  1
					parserState.NextState = cls.stateExpression
					return
			else:
				parserState.NewToken =    cls.CHARACTER_TRANSLATION[token.Value](token)
				parserState.NextState =   cls.stateExpression
				return
		elif isinstance(token, WordToken):
			try:
				parserState.NewToken =    cls.OPERATOR_TRANSLATIONS[token.Value](token)
			except KeyError:
				parserState.NewToken =    IdentifierToken(token)
			parserState.NextState =     cls.stateExpression
			return
		elif isinstance(token, LiteralToken):
			parserState.NextState =     cls.stateExpression
			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):
			if (not isinstance(parserState.LastBlock, LinebreakBlock)):
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				_ =                       CommentBlock(parserState.NewBlock, token)
			else:
				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 BlockParserException("Expected identifier, literal, operator, '(', ')' or ';'.", token)
コード例 #10
0
ファイル: __init__.py プロジェクト: cmarqu/pyVHDLParser
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, FusedCharacterToken):
            parserState.NewToken = cls.FUSED_CHARACTER_TRANSLATION[
                token.Value](token)
            parserState.NextState = cls.stateExpression
            return
        elif isinstance(token, CharacterToken):
            if (token == "("):
                parserState.NewToken = OpeningRoundBracketToken(token)
                parserState.Counter += 1
                parserState.NextState = cls.stateExpression
                return
            elif (token == ")"):
                parserState.NewToken = ClosingRoundBracketToken(token)
                parserState.Counter -= 1
                parserState.NextState = cls.stateExpression
                return
            else:
                parserState.NewToken = cls.CHARACTER_TRANSLATION[token.Value](
                    token)
                parserState.NextState = cls.stateExpression
                return
        elif isinstance(token, StringToken):
            if (token <= cls.EXIT_KEYWORD.__KEYWORD__):
                parserState.NewToken = cls.EXIT_KEYWORD(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.EXIT_BLOCK(parserState.NewBlock, parserState.NewToken)
                parserState.Pop()
                # parserState.TokenMarker = parserState.NewToken
                return
            else:
                try:
                    parserState.NewToken = cls.OPERATOR_TRANSLATIONS[
                        token.Value](token)
                except KeyError:
                    parserState.NewToken = IdentifierToken(token)
                parserState.NextState = cls.stateExpression
                return
        elif isinstance(token, LiteralToken):
            parserState.NextState = cls.stateExpression
            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):
            if (not isinstance(parserState.LastBlock, LinebreakBlock)):
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken,
                                           multiPart=True)
                _ = CommentBlock(parserState.NewBlock, token)
            else:
                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 ????????????.", token)
コード例 #11
0
	def stateExpression(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, FusedCharacterToken):
			try:
				parserState.NewToken = cls.FUSED_CHARACTER_TRANSLATION[token.Value](token)
				return
			except KeyError:
				if (token == cls.EXIT_CHAR):
					if (parserState.Counter == 0):
						parserState.NewToken = cls.EXIT_TOKEN(token)
						parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
						_ =                    cls.EXIT_BLOCK(parserState.NewBlock, parserState.NewToken, endToken=parserState.NewToken)
						parserState.Pop(2)
						return
					else:
						raise BlockParserException("Mismatch in opening and closing parenthesis. Counter={0}".format(parserState.Counter), token)
		elif isinstance(token, CharacterToken):
			if (token == cls.EXIT_CHAR):
				if (parserState.Counter == 0):
					parserState.NewToken =  cls.EXIT_TOKEN(token)
					parserState.NewBlock =  cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
					_ =                     cls.EXIT_BLOCK(parserState.NewBlock, parserState.NewToken, endToken=parserState.NewToken)
					parserState.Pop(2)
					return
				else:
					raise BlockParserException("Mismatch in opening and closing parenthesis. Counter={0}".format(parserState.Counter), token)
			elif (token == "("):
				parserState.NewToken =    OpeningRoundBracketToken(token)
				parserState.Counter +=    1
				return
			elif (token == ")"):
				if (parserState.Counter == 0):
					parserState.NewToken =    BoundaryToken(token)
					parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
					parserState.Pop(3, parserState.NewToken)
					return
				else:
					parserState.NewToken =    ClosingRoundBracketToken(token)
					parserState.Counter -=    1
					return
			else:
				parserState.NewToken =    cls.CHARACTER_TRANSLATION[token.Value](token)
				return
		elif isinstance(token, WordToken):
			try:
				parserState.NewToken =    cls.OPERATOR_TRANSLATIONS[token.Value](token)
			except KeyError:
				parserState.NewToken =    IdentifierToken(token)
			return
		elif isinstance(token, LiteralToken):
			return
		elif isinstance(token, SpaceToken):
			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 BlockParserException("Expected ?????????????.", token)
コード例 #12
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)
コード例 #13
0
ファイル: Process.py プロジェクト: Paebbels/pyVHDLParser
    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)
コード例 #14
0
ファイル: PortMapList.py プロジェクト: Paebbels/pyVHDLParser
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token

        errorMessage = "Expected  '(' after keyword PORT."
        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 BlockParserException(errorMessage, token)
コード例 #15
0
    def stateOpeningParenthesis(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ")")):
            # if (parserState.TokenMarker != token):
            # 	parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.TokenMarker, token.PreviousToken)
            parserState.Pop(1, token)
            return
        elif isinstance(token, WordToken):
            if (token <= "constant"):
                parserState.NewToken = ConstantKeyword(token)
                parserState.NextState = DelimiterBlock.stateItemDelimiter
                parserState.PushState = GenericListInterfaceConstantBlock.stateConstantKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (token <= "type"):
                parserState.NewToken = TypeKeyword(token)
                parserState.NextState = DelimiterBlock.stateItemDelimiter
                parserState.PushState = GenericListInterfaceTypeBlock.stateTypeKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (token <= "procedure"):
                raise NotImplementedError(
                    "Generic procedures are not supported.")
            elif (token <= "function"):
                raise NotImplementedError(
                    "Generic functions are not supported.")
            elif (token <= "impure"):
                raise NotImplementedError(
                    "Generic impure functions are not supported.")
            elif (token <= "pure"):
                raise NotImplementedError(
                    "Generic pure functions are not supported.")
            else:
                parserState.NewToken = IdentifierToken(token)
                parserState.NextState = DelimiterBlock.stateItemDelimiter
                parserState.PushState = GenericListInterfaceConstantBlock.stateObjectName
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = GenericListInterfaceConstantBlock.stateObjectName
            return
        elif isinstance(token, SpaceToken):
            blockType = IndentationBlock if isinstance(
                token, IndentationToken) else WhitespaceBlock
            parserState.NewBlock = blockType(parserState.LastBlock, token)
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            # parserState.NextState =   cls.stateWhitespace1
            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.stateWhitespace1
            return

        raise BlockParserException(
            "Expected interface constant name (identifier) or keyword: CONSTANT, TYPE, PROCEDURE, FUNCTION, PURE, IMPURE.",
            token)
コード例 #16
0
ファイル: __init__.py プロジェクト: cmarqu/pyVHDLParser
    def stateExpression(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, FusedCharacterToken):
            parserState.NewToken = cls.FUSED_CHARACTER_TRANSLATION[
                token.Value](token)
            return
        elif isinstance(token, CharacterToken):
            if (token == "("):
                parserState.NewToken = OpeningRoundBracketToken(token)
                parserState.Counter += 1
                return
            elif (token == ")"):
                parserState.NewToken = ClosingRoundBracketToken(token)
                parserState.Counter -= 1
                return
            else:
                parserState.NewToken = cls.CHARACTER_TRANSLATION[token.Value](
                    token)
                return
        elif isinstance(token, StringToken):
            tokenValue = token.Value.lower()
            if (tokenValue == cls.EXIT_KEYWORD.__KEYWORD__):
                parserState.NewToken = LoopKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = cls.EXIT_BLOCK(parserState.NewBlock, parserState.NewToken)
                parserState.Pop(2)
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "to"):
                from pyVHDLParser.Blocks.ControlStructure.ForLoop import LoopIterationDirectionBlock

                parserState.NewToken = ToKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = LoopIterationDirectionBlock(parserState.NewBlock,
                                                parserState.NewToken)
                parserState.Pop()
                parserState.TokenMarker = parserState.NewToken
                return
            elif (tokenValue == "downto"):
                from pyVHDLParser.Blocks.ControlStructure.ForLoop import LoopIterationDirectionBlock

                parserState.NewToken = DowntoKeyword(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = LoopIterationDirectionBlock(parserState.NewBlock,
                                                parserState.NewToken)
                parserState.Pop()
                parserState.TokenMarker = parserState.NewToken
                return
            else:
                try:
                    parserState.NewToken = cls.OPERATOR_TRANSLATIONS[
                        token.Value](token)
                except KeyError:
                    parserState.NewToken = IdentifierToken(token)
                return
        elif isinstance(token, LiteralToken):
            return
        elif isinstance(token, SpaceToken):
            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 '(' or whitespace after keyword GENERIC.", token)
コード例 #17
0
ファイル: Generic1.py プロジェクト: cmarqu/pyVHDLParser
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if ((cls.KEYWORD_IS_OPTIONAL is True) and (token == ";")):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=parserState.NewToken)
                parserState.Pop()
                return
        elif isinstance(token, StringToken):
            IS_SINGLE_KEYWORD = isinstance(cls.KEYWORD, tuple)
            KW = cls.KEYWORD[0] if IS_SINGLE_KEYWORD else cls.KEYWORD
            if (token <= KW.__KEYWORD__):
                parserState.NewToken = KW(token)
                parserState.NextState = cls.stateKeyword1
            elif (cls.EXPECTED_NAME_KIND == "label"):
                parserState.NewToken = LabelToken(token)
                parserState.NextState = cls.stateSimpleName
            else:
                parserState.NewToken = IdentifierToken(token)
                parserState.NextState = cls.stateSimpleName
            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

        if (cls.KEYWORD_IS_OPTIONAL is True):
            if (cls.EXPECTED_NAME_KIND == "label"):
                errorMessage = "Expected ';', {0} keyword or {1} label.".format(
                    cls.EXPECTED_NAME.upper(), cls.EXPECTED_NAME)
            else:
                errorMessage = "Expected ';', {0} keyword or {1} name.".format(
                    cls.EXPECTED_NAME.upper(), cls.EXPECTED_NAME)
        else:
            if (cls.EXPECTED_NAME_KIND == "label"):
                errorMessage = "Expected {0} keyword or {1} label.".format(
                    cls.EXPECTED_NAME.upper(), cls.EXPECTED_NAME)
            else:
                errorMessage = "Expected {0} keyword or {1} name.".format(
                    cls.EXPECTED_NAME.upper(), cls.EXPECTED_NAME)

        raise TokenParserException(errorMessage, token)
コード例 #18
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, FusedCharacterToken):
			parserState.NewToken =    cls.FUSED_CHARACTER_TRANSLATION[token.Value](token)
			parserState.NextState =   cls.stateExpression
			return
		elif isinstance(token, CharacterToken):
			if (token == "("):
				parserState.NewToken =    OpeningRoundBracketToken(token)
				parserState.Counter +=    1
				parserState.NextState =   cls.stateExpression
				return
			elif (token == ")"):
				parserState.NewToken =  ClosingRoundBracketToken(token)
				parserState.Counter -=  1
				parserState.NextState = cls.stateExpression
				return
			else:
				parserState.NewToken =    cls.CHARACTER_TRANSLATION[token.Value](token)
				parserState.NextState =   cls.stateExpression
				return
		elif isinstance(token, WordToken):
			tokenValue = token.Value.lower()
			if (tokenValue == cls.EXIT_KEYWORD.__KEYWORD__):
				parserState.NewToken =    LoopKeyword(token)
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
				_ =                       cls.EXIT_BLOCK(parserState.NewBlock, parserState.NewToken)
				parserState.Pop(1, parserState.NewToken)
				return
			elif (tokenValue == "to"):
				from pyVHDLParser.Blocks.ControlStructure.ForLoop import LoopIterationDirectionBlock

				parserState.NewToken =    ToKeyword(token)
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
				_ =                       LoopIterationDirectionBlock(parserState.NewBlock, parserState.NewToken)
				parserState.Pop()
				return
			elif (tokenValue == "downto"):
				from pyVHDLParser.Blocks.ControlStructure.ForLoop import LoopIterationDirectionBlock

				parserState.NewToken =    DowntoKeyword(token)
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
				_ =                       LoopIterationDirectionBlock(parserState.NewBlock, parserState.NewToken)
				parserState.Pop()
				return
			else:
				try:
					parserState.NewToken =  cls.OPERATOR_TRANSLATIONS[token.Value](token)
				except KeyError:
					parserState.NewToken =  IdentifierToken(token)
				parserState.NextState =   cls.stateExpression
				return
		elif isinstance(token, LiteralToken):
			parserState.NextState =     cls.stateExpression
			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):
			if (not isinstance(parserState.LastBlock, LinebreakBlock)):
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				_ =                       CommentBlock(parserState.NewBlock, token)
			else:
				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 BlockParserException("Expected ????????????.", token)