Beispiel #1
0
    def stateSubtypeIndication(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ';')):
            parserState.NewToken = EndToken(token)
            parserState.NewBlock = cls(
                parserState.LastBlock,
                parserState.TokenMarker,
                endToken=parserState.NewToken.PreviousToken)
            _ = cls.END_BLOCK(parserState.NewBlock, parserState.NewToken)
            parserState.Pop()
            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 ';' or whitespace after subtype indication.", token)
Beispiel #2
0
    def stateInKeyword(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)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = LoopBlock.stateSequentialRegion
            parserState.PushState = ExpressionBlockEndedByLoopORToORDownto.stateExpression
            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 TokenParserException(
            "Expected '(' or whitespace after keyword IN.", token)
Beispiel #3
0
	def stateAfterParameterList(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, CharacterToken) and (token == ";")):
			parserState.NewToken =      EndToken(token)
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			parserState.Pop()
			return
		elif isinstance(token, StringToken):
			if (token <= "is"):
				parserState.NewToken =    IsKeyword(token)
				parserState.NewBlock =    VoidBlock(parserState.LastBlock, parserState.TokenMarker, parserState.NewToken)
				parserState.NextState =   DeclarativeRegion.stateDeclarativeRegion
				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 =      block(parserState.LastBlock, token)
			parserState.TokenMarker =   None
			parserState.NextState =     cls.stateWhitespace1
			return

		raise TokenParserException("Expected keyword RETURN.", token)
Beispiel #4
0
    def stateFunctionName(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 = ReturnTypeBlock.stateAfterParameterList
            parserState.PushState = ParameterList.OpenBlock.stateOpeningParenthesis
            parserState.Counter = 1
            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 '(' or whitespace after function name.", token)
    def stateItemDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            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):
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            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 signal name (identifier).", token)
    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 BlockParserException(
            "Expected whitespace after interface {0} name.".format(
                cls.OBJECT_KIND), token)
    def stateColon1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            try:
                parserState.NewToken = cls.MODES[token.Value.lower()](token)
                parserState.NextState = cls.stateModeKeyword
                return
            except KeyError:
                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)
Beispiel #8
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, CharacterToken) and (token == ";")):
			parserState.NewToken =    EndToken(token)
			parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			parserState.Pop()
			return
		elif isinstance(token, WordToken):
			if (token <= "when"):
				parserState.NewToken =    WhenKeyword(token)
				parserState.NextState =   cls.stateWhenKeyword
				return
			else:
				parserState.NewToken =    IdentifierToken(token)
				# parserState.TokenMarker = parserState.NewToken
				parserState.NextState =   cls.stateExitLoopLabel
				return
		elif isinstance(token, ExtendedIdentifier):
			parserState.NextState =   cls.stateExitLoopLabel
			return
		elif isinstance(token, (LinebreakToken, CommentToken)):
			block =                   LinebreakBlock if isinstance(token, LinebreakToken) else CommentBlock
			parserState.NewBlock =    block(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 ';', keyword WHEN or loop label.", token)
Beispiel #9
0
	def stateVariableAssignment(cls, parserState: ParserState):
		token = parserState.Token
		errorMessage = "Expected ':=' or whitespace after type mark."
		if isinstance(token, CharacterToken):
			if (token == "\n"):
				parserState.NewBlock =    TypeBlock(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				parserState.NewToken =    LinebreakToken(token)
				_ =                       LinebreakBlock(parserState.NewBlock, parserState.NewToken)
				parserState.TokenMarker = None
				parserState.NextState =   cls.stateWhitespace5
				parserState.PushState =   LinebreakBlock.stateLinebreak
				return
			elif (token == "-"):
				parserState.NewBlock = TypeBlock(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				parserState.TokenMarker = None
				parserState.NextState = cls.stateWhitespace5
				parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
				parserState.TokenMarker = token
				return
			elif (token == "/"):
				parserState.NewBlock = TypeBlock(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				parserState.TokenMarker = None
				parserState.NextState = cls.stateWhitespace5
				parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
				parserState.TokenMarker = token
				return
		elif isinstance(token, SpaceToken):
			parserState.NextState = cls.stateWhitespace5
			return

		raise TokenParserException(errorMessage, token)
Beispiel #10
0
    def stateNextKeyword(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ";")):
            parserState.NewToken = EndToken(token)
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=parserState.NewToken)
            parserState.Pop()
            return
        elif isinstance(token, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            # parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken, multiPart=True)
            # parserState.TokenMarker = None
            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 ';' or whitespace after keyword EXIT.", token)
Beispiel #11
0
	def stateBlockKeyword(cls, parserState: ParserState):
		token = parserState.Token
		errorMessage = "Expected whitespace after keyword "
		if isinstance(token, CharacterToken):
			if (token == "\n"):
				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.NextState =   cls.stateWhitespace1
				parserState.PushState =   LinebreakBlock.stateLinebreak
				return
			elif (token == "-"):
				parserState.NewBlock =    NameBlock(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 =    NameBlock(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 BlockParserException(errorMessage, token)
Beispiel #12
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, WordToken):
			parserState.NewToken =      IdentifierToken(token)
			parserState.NextState =     cls.stateConfigurationName
			return
		elif isinstance(token, ExtendedIdentifier):
			parserState.NextState =     cls.stateConfigurationName
			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 BlockParserException("Expected configuration name (identifier).", token)
Beispiel #13
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = LibraryNameBlock.stateLibraryName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = LibraryNameBlock.stateLibraryName
            return
        elif isinstance(token, (LinebreakToken, CommentToken)):
            block = LinebreakBlock if isinstance(
                token, LinebreakToken) else CommentBlock
            parserState.NewBlock = block(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 library name (identifier).",
                                   token)
Beispiel #14
0
    def statePortKeyword(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 = CloseBlock.stateClosingParenthesis
            parserState.PushState = cls.stateOpeningParenthesis
            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 '(' or whitespace after keyword PORT.", token)
Beispiel #15
0
    def stateItemDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            if (token <= "signal"):
                parserState.NewToken = SignalKeyword(token)
                parserState.PushState = PortListInterfaceSignalBlock.stateSignalKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            else:
                parserState.NewToken = IdentifierToken(token)
                parserState.PushState = PortListInterfaceSignalBlock.stateObjectName
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = PortListInterfaceSignalBlock.stateObjectName
            return
        elif isinstance(token, SpaceToken):
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            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 port name (identifier).", token)
Beispiel #16
0
    def stateDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = LibraryNameBlock.stateLibraryName
            parserState.TokenMarker = parserState.NewToken
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = LibraryNameBlock.stateLibraryName
            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, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            # parserState.NewBlock =      WhitespaceBlock(parserState.LastBlock, parserState.NewToken)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = cls.stateWhitespace1
            return

        raise TokenParserException("Expected library name (identifier).",
                                   token)
Beispiel #17
0
	def stateWhenKeyword(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, CharacterToken):
			if  (token == ";"):
				parserState.NewToken =    EndToken(token)
				parserState.NewBlock =    EndBlock(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
				parserState.Pop()
				return
			elif  (token == "("):
				parserState.NewToken =    BoundaryToken(token)
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
				parserState.TokenMarker = parserState.NewToken
				parserState.NextState =   EndBlock.stateError
				parserState.PushState =   ExitConditionBlock.stateExpression
				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 ';' or whitespace after keyword RETURN.", token)
Beispiel #18
0
    def stateReturnType(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';' or whitespace after type mark (return type)."
        if (isinstance(token, CharacterToken) and (token == ";")):
            parserState.NewToken = EndToken(token)
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=parserState.NewToken)
            parserState.Pop()
            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(errorMessage, token)
Beispiel #19
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if 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
		else:
			parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken)
			parserState.NextState =   ThenBlock.stateThenKeyword
			parserState.PushState =   ExpressionBlockEndedByThen.stateExpression
			parserState.TokenMarker = parserState.Token
			parserState.NextState(parserState)
			return
Beispiel #20
0
	def stateElsIfKeyword(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)
			parserState.TokenMarker = parserState.NewToken
			parserState.NextState =   ThenBlock.stateThenKeyword
			parserState.PushState =   ExpressionBlockEndedByThen.stateExpression
			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
		else:
			parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken)
			parserState.NextState =   ThenBlock.stateThenKeyword
			parserState.PushState =   ExpressionBlockEndedByThen.stateExpression
			parserState.TokenMarker = parserState.Token
			parserState.NextState(parserState)
			return
Beispiel #21
0
	def stateWhitespace0(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, WordToken):
			parserState.NewToken =    IdentifierToken(token)
			parserState.NextState =   cls.stateVariableKeyword
			return
		elif isinstance(token, ExtendedIdentifier):
			parserState.NextState =   cls.stateVariableKeyword
			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, 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 whitespace after keyword SHARED.", token)
Beispiel #22
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected attribute name (identifier)."
        if isinstance(token, CharacterToken):
            if (token == ":"):
                parserState.NewToken = BoundaryToken(token)
                parserState.NextState = cls.stateColon1
                return
            if (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = AttributeDeclarationBlock(
                        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 = AttributeDeclarationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = AttributeDeclarationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateColon1()
            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)
Beispiel #23
0
    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):
            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)
                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)
Beispiel #24
0
	def statePossibleCommentStart(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, CharacterToken) and (token == "*")):
			parserState.NewToken =    MultiLineCommentStartKeyword(parserState.TokenMarker)
			parserState.TokenMarker = parserState.NewToken
			parserState.NextState =   cls.stateConsumeComment
			return
		else:
			parserState.Pop()
			# print("  {DARK_GREEN}re-issue: {GREEN}{state!s}     {DARK_GREEN}token={GREEN}{token}{NOCOLOR}".format(state=parserState, token=parserState.Token, **Console.Foreground))
			parserState.NextState(parserState)
Beispiel #25
0
    def stateWhitespace3(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=parserState.NewToken)
                parserState.Pop()
                return
        elif isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateSimpleName
            return
        elif isinstance(token, ExtendedIdentifier):
            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

        raise TokenParserException(
            "Expected ';' or {0} name.".format(cls.EXPECTED_NAME), token)
Beispiel #26
0
    def stateItemDelimiter(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            if (token <= "constant"):
                parserState.NewToken = ConstantKeyword(token)
                parserState.PushState = GenericListInterfaceConstantBlock.stateConstantKeyword
                parserState.TokenMarker = parserState.NewToken
                return
            elif (token <= "type"):
                parserState.NewToken = TypeKeyword(token)
                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.PushState = GenericListInterfaceConstantBlock.stateObjectName
                parserState.TokenMarker = parserState.NewToken
                return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = GenericListInterfaceConstantBlock.stateObjectName
            return
        elif isinstance(token, SpaceToken):
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            parserState.NextState = OpenBlock.stateOpeningParenthesis
            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 generic name (identifier).",
                                   token)
Beispiel #27
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            tokenValue = token.Value.lower()
            if (tokenValue == "when"):
                newToken = WhenKeyword(token)
                parserState.NewToken = newToken
                parserState.TokenMarker = newToken
                parserState.NextState = WhenBlock.stateWhenKeyword
                return
            elif (tokenValue == "end"):
                parserState.NewToken = EndKeyword(token)
                parserState.NextState = cls.END_BLOCK.stateEndKeyword
                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 TokenParserException(
            "Expected one of these keywords: WHEN or END. Found: '{tokenValue}'."
            .format(tokenValue=token.Value), token)
Beispiel #28
0
	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, StringToken):
			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 TokenParserException("Expected '(' or keywords GENERIC, PARAMETER or RETURN after procedure name.", token)
Beispiel #29
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)
Beispiel #30
0
    def stateEntityInstantiationName(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';' after entityInstantiation name."
        if isinstance(token, CharacterToken):
            if (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = EntityInstantiationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken)
                parserState.Pop()
                return
            elif (token == "\n"):
                parserState.NewBlock = EntityInstantiationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.NewToken = LinebreakToken(token)
                _ = LinebreakBlock(parserState.NewBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace2
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = EntityInstantiationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace2
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = EntityInstantiationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace2
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif isinstance(token, SpaceToken):
            parserState.NextState = cls.stateWhitespace2
            return

        raise TokenParserException(errorMessage, token)