Esempio n. 1
0
	def statePossibleCommentEnd(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, CharacterToken) and (token == "/")):
			parserState.NewToken = MultiLineCommentEndKeyword(parserState.TokenMarker)
			parserState.Pop()
			parserState.NewBlock = MultiLineCommentBlock(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			parserState.Pop()
			return
		else:
			parserState.Pop()
			parserState.NextState(parserState)
Esempio n. 2
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if 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)
Esempio n. 3
0
	def stateLinebreak(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, SpaceToken):
			parserState.NewToken = IndentationToken(token)
			parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.NewToken)
			parserState.Pop()
		else:
			parserState.Pop()
			if (parserState.TokenMarker is None):
				# print("  new marker: None -> {0!s}".format(token))
				parserState.TokenMarker = token
				# 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)
Esempio n. 4
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)
Esempio n. 5
0
	def stateWhitespace3(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) and (token <= "is")):
			parserState.NewToken =      IsKeyword(token)
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			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, 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 function name (designator).", token)
Esempio n. 6
0
    def stateExitLoopLabel(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=token, multiPart=True)
            # parserState.TokenMarker = None
            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 loop label.", token)
Esempio n. 7
0
	def stateWhitespace4(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, 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 ';' after subtype indication.", token)
Esempio n. 8
0
    def stateWhitespace2(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) and (token <= "when")):
            parserState.NewToken = WhenKeyword(token)
            parserState.NextState = cls.stateWhenKeyword
            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 ';' or keyword WHEN.", token)
Esempio n. 9
0
    def stateAllKeyword(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ")")):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = CloseBlock(parserState.LastBlock,
                                              parserState.NewToken,
                                              endToken=parserState.NewToken)
            parserState.Pop()
            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 ALL.", token)
Esempio n. 10
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, LinebreakToken):
            # TODO: review this linebreak case
            parserState.NewBlock = LinebreakBlock(parserState.LastBlock, token)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = CommentBlock(parserState.LastBlock, token)
            parserState.TokenMarker = token
            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)
Esempio n. 11
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, StringToken):
			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 TokenParserException("Expected ';', keyword WHEN or loop label.", token)
Esempio n. 12
0
	def stateWhitespace3(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, CharacterToken) and  (token == ";")):
			parserState.NewToken =    EndToken(token)
			parserState.NewBlock =    EndBlock(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken)
			parserState.Pop()
			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
		else:
			parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken)
			parserState.NextState =   EndBlock.stateError
			parserState.PushState =   ExitConditionBlock.stateExpression
			parserState.TokenMarker = parserState.Token
			parserState.NextState(parserState)
			return
Esempio n. 13
0
	def stateWhitespace4(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) and (token <= "severity")):
			parserState.NewToken =    SeverityKeyword(token)
			parserState.NextState =   cls.stateSeverityKeyword
			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 keyword SEVERITY after message.", token)
Esempio n. 14
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)
Esempio n. 15
0
    def stateEndKeyword(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, SpaceToken):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateWhitespace1
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            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 TokenParserException("Expected ';' or whitespace.", token)
Esempio n. 16
0
    def stateClosingParenthesis(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ";")):
            parserState.NewToken = EndToken(token)
            parserState.NewBlock = CloseBlock(parserState.LastBlock,
                                              parserState.TokenMarker,
                                              endToken=parserState.NewToken)
            parserState.Pop()
            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.", token)
Esempio n. 17
0
    def stateKeyword1(cls, parserState: ParserState):
        IS_DOUBLE_KEYWORD = isinstance(cls.KEYWORD, tuple)
        nextState = cls.stateWhitespace2 if IS_DOUBLE_KEYWORD else cls.stateWhitespace3
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (not isinstance(cls.KEYWORD, tuple) 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 = nextState
            return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            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 TokenParserException("Expected ';' or whitespace.", token)
Esempio n. 18
0
    def stateExpressionEnd(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';'."
        if isinstance(token, CharacterToken):
            if (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = TypeBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=parserState.NewToken)
                parserState.Pop()
                return
            elif (token == "-"):
                parserState.NewBlock = TypeBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                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.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return

        raise TokenParserException(errorMessage, token)
Esempio n. 19
0
 def stateItemRemainder(cls, parserState: ParserState):
     token = parserState.Token
     if isinstance(token, CharacterToken):
         if (token == "("):
             parserState.Counter += 1
         elif (token == ")"):
             parserState.Counter -= 1
             if (parserState.Counter == 0):
                 parserState.NewToken = BoundaryToken(token)
                 parserState.NewBlock = ItemBlock(
                     parserState.LastBlock,
                     parserState.TokenMarker,
                     endToken=parserState.NewToken.PreviousToken)
                 _ = CloseBlock(parserState.NewBlock, parserState.NewToken)
                 parserState.Pop()
                 parserState.TokenMarker = None
             else:
                 parserState.NewToken = ClosingRoundBracketToken(token)
                 # parserState.NewBlock =    CloseBlock(parserState.LastBlock, parserState.NewToken)
                 # parserState.Pop()
         elif (token == ";"):
             if (parserState.Counter == 1):
                 parserState.NewToken = DelimiterToken(token)
                 parserState.NewBlock = ItemBlock(
                     parserState.LastBlock,
                     parserState.TokenMarker,
                     endToken=parserState.NewToken.PreviousToken)
                 _ = DelimiterBlock(parserState.NewBlock,
                                    parserState.NewToken)
                 parserState.NextState = DelimiterBlock.stateItemDelimiter
             else:
                 raise TokenParserException(
                     "Mismatch in opening and closing parenthesis: open={0}"
                     .format(parserState.Counter), token)
Esempio n. 20
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, WordToken):
            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 BlockParserException("Expected keyword RETURN.", token)
Esempio n. 21
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 TokenParserException("Expected ';' or whitespace after keyword RETURN.", token)
Esempio n. 22
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)
Esempio n. 23
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ';'."
        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.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = EntityInstantiationBlock(
                        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 = EntityInstantiationBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                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.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Esempio n. 24
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)
Esempio n. 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)
Esempio n. 26
0
    def stateWhitespace5(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, CharacterToken):
            if (token == ","):
                parserState.NewToken = DelimiterToken(token)
                parserState.NewBlock = cls(parserState.LastBlock,
                                           parserState.TokenMarker,
                                           endToken=token.PreviousToken)
                _ = DelimiterBlock(parserState.NewBlock,
                                   parserState.NewToken,
                                   endToken=parserState.NewToken)
                parserState.NextState = DelimiterBlock.stateDelimiter
                return
            elif (token == ";"):
                parserState.NewToken = EndToken(token)
                parserState.NewBlock = cls(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=parserState.NewToken.PreviousToken)
                _ = EndBlock(parserState.NewBlock,
                             parserState.NewToken,
                             endToken=parserState.NewToken)
                parserState.Pop()
                parserState.TokenMarker = None
                return
        elif isinstance(token, LinebreakToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token,
                                       multiPart=True)
            parserState.TokenMarker = None
            return
        elif isinstance(token, CommentToken):
            parserState.NewBlock = cls(parserState.LastBlock,
                                       parserState.TokenMarker,
                                       endToken=token.PreviousToken,
                                       multiPart=True)
            _ = CommentBlock(parserState.NewBlock, token)
            parserState.TokenMarker = None
            return
        elif (isinstance(token, IndentationToken)
              and isinstance(token.PreviousToken,
                             (LinebreakToken, SingleLineCommentToken))):
            return
        elif (isinstance(token, SpaceToken) and
              (isinstance(parserState.LastBlock, CommentBlock) and isinstance(
                  parserState.LastBlock.StartToken, MultiLineCommentToken))):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise BlockParserException("Expected ',' or ';'.", token)
Esempio n. 27
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)
Esempio n. 28
0
    def stateTypeName(cls, parserState: ParserState):
        token = parserState.Token
        if 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.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 TokenParserException(
            "Expected ';', ')' or whitespace after interface type name.",
            token)
Esempio n. 29
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 BlockParserException(errorMessage, token)
Esempio n. 30
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 == ";"):
				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
				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
					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 operator, '(', ')', ';' or whitespace.", token)