Ejemplo n.º 1
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)
Ejemplo n.º 2
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, WordToken):
			parserState.NewToken =      IdentifierToken(token)
			parserState.NextState =     cls.stateContextName
			return
		elif isinstance(token, ExtendedIdentifier):
			parserState.NextState =     cls.stateContextName
			return
		elif isinstance(token, LinebreakToken):
			if (not (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				_ =                       LinebreakBlock(parserState.NewBlock, token)
			else:
				parserState.NewBlock =    LinebreakBlock(parserState.LastBlock, token)
			parserState.TokenMarker =   None
			return
		elif isinstance(token, CommentToken):
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
			_ =                         CommentBlock(parserState.NewBlock, token)
			parserState.TokenMarker =   None
			return
		elif (isinstance(token, IndentationToken) and isinstance(token.PreviousToken, (LinebreakToken, SingleLineCommentToken))):
			return
		elif (isinstance(token, SpaceToken) and (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
			parserState.NewToken =      BoundaryToken(token)
			parserState.NewBlock =      WhitespaceBlock(parserState.LastBlock, parserState.NewToken)
			parserState.TokenMarker =   None
			return

		raise BlockParserException("Expected context name (identifier).", token)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = ReferenceNameBlock.stateLibraryName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = ReferenceNameBlock.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 BlockParserException("Expected library name (identifier).",
                                   token)
Ejemplo n.º 5
0
    def stateWhitespace3(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, WordToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.stateSubtypeIndication
            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 subtype indication after colon.",
                                   token)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, WordToken):
			if (token <= "body"):
				parserState.NewToken =    BodyKeyword(token)
				parserState.NextState =   PackageBody.NameBlock.stateBodyKeyword
				return
			else:
				parserState.NewToken =    IdentifierToken(token)
				parserState.NextState =   cls.statePackageName
				return
		elif isinstance(token, LinebreakToken):
			if (not (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				_ =                       LinebreakBlock(parserState.NewBlock, token)
			else:
				parserState.NewBlock =    LinebreakBlock(parserState.LastBlock, token)
			parserState.TokenMarker =   None
			return
		elif isinstance(token, CommentToken):
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
			_ =                         CommentBlock(parserState.NewBlock, token)
			parserState.TokenMarker =   None
			return
		elif (isinstance(token, SpaceToken) and (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
			parserState.NewToken =      BoundaryToken(token)
			parserState.NewBlock =      WhitespaceBlock(parserState.LastBlock, parserState.NewToken)
			parserState.TokenMarker =   None
			return

		raise BlockParserException("Expected package name (identifier).", token)
Ejemplo n.º 8
0
	def stateWhitespace3(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, StringToken):
			parserState.NewToken =      IdentifierToken(token)
			parserState.NextState =     cls.stateMessage
			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 REPORT after assertion.", token)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if (isinstance(token, CharacterToken) and (token == ":")):
            parserState.NewToken = BoundaryToken(token)
            parserState.NextState = cls.stateColon1
            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 colon after {0} name.".format(cls.OBJECT_KIND), token)
Ejemplo n.º 12
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = ReferenceNameBlock.stateLibraryName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = ReferenceNameBlock.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) 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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
	def stateWhitespace1(cls, parserState: ParserState):
		token = parserState.Token
		if isinstance(token, StringToken):
			parserState.NewToken =      IdentifierToken(token)
			parserState.NextState =     cls.stateProcedureName
			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 procedure name (designator).", token)
Ejemplo n.º 15
0
    def stateWhitespace1(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected  '(' after keyword GENERIC."
        if isinstance(token, CharacterToken):
            if (token == "("):
                parserState.NewToken = BoundaryToken(token)
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=parserState.NewToken)
                parserState.NextState = CloseBlock.stateClosingParenthesis
                parserState.PushState = OpenBlock.stateOpeningParenthesis
                parserState.Counter = 1
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = OpenBlock(
                        parserState.LastBlock,
                        parserState.TokenMarker,
                        endToken=parserState.NewToken.PreviousToken,
                        multiPart=True)
                    _ = LinebreakBlock(parserState.NewBlock,
                                       parserState.NewToken)
                else:
                    parserState.NewBlock = LinebreakBlock(
                        parserState.LastBlock, parserState.NewToken)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = LinebreakBlock.stateLinebreak
                return
            elif (token == "-"):
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = OpenBlock(parserState.LastBlock,
                                                 parserState.TokenMarker,
                                                 endToken=token.PreviousToken,
                                                 multiPart=True)
                parserState.TokenMarker = None
                parserState.NextState = cls.stateWhitespace1
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Ejemplo n.º 16
0
	def stateWhitespace2(cls, parserState: ParserState):
		token = parserState.Token
		if (isinstance(token, WordToken) and (token <= "is")):
			parserState.NewToken =      IsKeyword(token)
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken)
			parserState.NextState =     cls.stateDeclarativeRegion
			return
		elif isinstance(token, LinebreakToken):
			if (not (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
				parserState.NewBlock =    cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
				_ =                       LinebreakBlock(parserState.NewBlock, token)
			else:
				parserState.NewBlock =    LinebreakBlock(parserState.LastBlock, token)
			parserState.TokenMarker =   None
			return
		elif isinstance(token, CommentToken):
			parserState.NewBlock =      cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True)
			_ =                         CommentBlock(parserState.NewBlock, token)
			parserState.TokenMarker =   None
			return
		elif (isinstance(token, IndentationToken) and isinstance(token.PreviousToken, (LinebreakToken, SingleLineCommentToken))):
			return
		elif (isinstance(token, SpaceToken) and (isinstance(parserState.LastBlock, CommentBlock) and isinstance(parserState.LastBlock.StartToken, MultiLineCommentToken))):
			parserState.NewToken =      BoundaryToken(token)
			parserState.NewBlock =      WhitespaceBlock(parserState.LastBlock, parserState.NewToken)
			parserState.TokenMarker =   None
			return

		raise BlockParserException("Expected keyword IS after context name.", token)
Ejemplo n.º 17
0
	def stateWhitespace3(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 =     LoopBlock.stateLoopKeyword
			parserState.PushState =     ExpressionBlockEndedByLoop.stateExpression
			parserState.PushState =     ExpressionBlockEndedByLoopORToORDownto.stateExpression
			parserState.TokenMarker =   parserState.Token
			parserState.NextState(parserState)
			return
Ejemplo n.º 18
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)
Ejemplo n.º 19
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
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected keyword IS after generate name."
        if isinstance(token, CharacterToken):
            if (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = ElseGenerateBlock(
                        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 = ElseGenerateBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = ElseGenerateBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
        elif (isinstance(token, StringToken) and (token <= "is")):
            parserState.NewToken = IsKeyword(token)
            parserState.NewBlock = ElseGenerateBlock(
                parserState.LastBlock,
                parserState.TokenMarker,
                endToken=parserState.NewToken)
            parserState.NextState = cls.stateDeclarativeRegion
            return
        elif (isinstance(token, SpaceToken)
              and isinstance(parserState.LastBlock, MultiLineCommentBlock)):
            parserState.NewToken = BoundaryToken(token)
            parserState.NewBlock = WhitespaceBlock(parserState.LastBlock,
                                                   parserState.NewToken)
            parserState.TokenMarker = None
            return

        raise TokenParserException(errorMessage, token)
Ejemplo n.º 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)
Ejemplo n.º 23
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)
Ejemplo n.º 24
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)
Ejemplo n.º 25
0
    def stateWhitespace4(cls, parserState: ParserState):
        token = parserState.Token
        errorMessage = "Expected ':=' after type mark."
        if isinstance(token, CharacterToken):
            if (token == ":"):
                parserState.NewToken = BoundaryToken(token)
                parserState.NextState = cls.statePossibleVariableAssignment
                return
            elif (token == "\n"):
                parserState.NewToken = LinebreakToken(token)
                if (not isinstance(parserState.LastBlock,
                                   MultiLineCommentBlock)):
                    parserState.NewBlock = SubTypeBlock(
                        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 = SubTypeBlock(
                    parserState.LastBlock,
                    parserState.TokenMarker,
                    endToken=token.PreviousToken,
                    multiPart=True)
                parserState.TokenMarker = None
                parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart
                parserState.TokenMarker = token
                return
            elif (token == "/"):
                parserState.NewBlock = SubTypeBlock(
                    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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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)
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
    def stateWhitespace3(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            tokenValue = token.Value.lower()
            try:
                parserState.NewToken = cls.MODES[tokenValue](token)
                parserState.NextState = cls.stateModeKeyword
                return
            except KeyError:
                parserState.NewToken = IdentifierToken(token)
                parserState.NextState = cls.stateSubtypeIndication
                return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = cls.stateSubtypeIndication
            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 subtype indication or keyword IN.", token)
Ejemplo n.º 30
0
    def stateWhitespace2(cls, parserState: ParserState):
        token = parserState.Token
        if isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.NextState = cls.statePackageName
            return
        elif isinstance(token, ExtendedIdentifier):
            parserState.NextState = cls.statePackageName
            return
        elif (isinstance(token, CharacterToken) and (token == ".")):
            parserState.NewToken = DelimiterToken(token)
            parserState.NextState = cls.stateDot1
            return
        elif isinstance(token, StringToken):
            parserState.NewToken = IdentifierToken(token)
            parserState.TokenMarker = parserState.NewToken
            parserState.NextState = cls.statePackageName
            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 TokenParserException("Expected package name (identifier).",
                                   token)