def stateLinebreak(cls, parserState: ParserState): token = parserState.Token if isinstance(token, SpaceToken): parserState.NewToken = IndentationToken(token) parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.NewToken) parserState.Pop() else: parserState.Pop() if (parserState.TokenMarker is None): # print(" new marker: None -> {0!s}".format(token)) parserState.TokenMarker = token # print(" {DARK_GREEN}re-issue: {GREEN}{state!s} {DARK_GREEN}token={GREEN}{token}{NOCOLOR}".format(state=parserState, token=parserState.Token, **Console.Foreground)) parserState.NextState(parserState)
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)
def stateOpeningParenthesis(cls, parserState: ParserState): token = parserState.Token errorMessage = "Expected generic name (identifier)." if isinstance(token, CharacterToken): if (token == ")"): # if (parserState.TokenMarker != token): # parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.TokenMarker, token.PreviousToken) parserState.Pop() parserState.TokenMarker = token return elif (token == "\n"): parserState.NewToken = LinebreakToken(token) parserState.NewBlock = LinebreakBlock(parserState.LastBlock, parserState.NewToken) parserState.TokenMarker = None parserState.PushState = LinebreakBlock.stateLinebreak return elif (token == "-"): parserState.TokenMarker = None parserState.PushState = SingleLineCommentBlock.statePossibleCommentStart parserState.TokenMarker = token return elif (token == "/"): parserState.TokenMarker = None 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): parserState.NewToken = IdentifierToken(token) parserState.TokenMarker = parserState.NewToken parserState.NextState = ItemBlock.stateItemRemainder # if (parserState.TokenMarker != token): # parserState.NewBlock = IndentationBlock(parserState.LastBlock, parserState.TokenMarker, token) return raise TokenParserException(errorMessage, token)