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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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
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)
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
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)