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 stateDeclarativeRegion(cls, parserState: ParserState): errorMessage = "Expected one of these keywords: generic, port, begin, end." token = parserState.Token if isinstance(parserState.Token, CharacterToken): if (token == "\n"): parserState.NewToken = LinebreakToken(token) parserState.NewBlock = LinebreakBlock(parserState.LastBlock, parserState.NewToken) parserState.TokenMarker = parserState.NewToken return elif (token == "-"): parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart parserState.TokenMarker = token return elif (token == "/"): parserState.PushState = MultiLineCommentBlock.statePossibleCommentStart parserState.TokenMarker = token return elif isinstance(token, SpaceToken): parserState.NewToken = IndentationToken(token) parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.NewToken) return elif isinstance(token, StringToken): keyword = token.Value.lower() if (keyword == "generic"): newToken = GenericKeyword(token) parserState.PushState = GenericList.OpenBlock.stateGenericKeyword elif (keyword == "port"): newToken = PortKeyword(token) parserState.PushState = PortList.OpenBlock.statePortKeyword elif (keyword == "end"): newToken = EndKeyword(token) parserState.NextState = EndGenerateBlock.stateEndKeyword elif (keyword == "begin"): parserState.NewToken = BeginKeyword(token) parserState.NewBlock = ElseGenerateBeginBlock( parserState.LastBlock, parserState.NewToken) parserState.NextState = ElseGenerateBeginBlock.stateBeginKeyword return else: raise TokenParserException(errorMessage, token) parserState.NewToken = newToken parserState.TokenMarker = newToken return raise TokenParserException(errorMessage, token)