def stateObjectName(cls, parserState: ParserState): token = parserState.Token if isinstance(token, SpaceToken): parserState.NewToken = BoundaryToken(token) parserState.NextState = cls.stateWhitespace2 return elif (isinstance(token, CharacterToken) and (token == ":")): parserState.NewToken = DelimiterToken(token) parserState.NextState = cls.stateColon1 return elif isinstance(token, (LinebreakToken, CommentToken)): block = LinebreakBlock if isinstance( token, LinebreakToken) else CommentBlock parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = block(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace2 return raise TokenParserException( "Expected whitespace after interface {0} name.".format( cls.OBJECT_KIND), token)
def stateItemRemainder(cls, parserState: ParserState): token = parserState.Token if isinstance(token, CharacterToken): if (token == "("): parserState.Counter += 1 elif (token == ")"): parserState.Counter -= 1 if (parserState.Counter == 0): parserState.NewToken = BoundaryToken(token) parserState.NewBlock = ItemBlock( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) _ = CloseBlock(parserState.NewBlock, parserState.NewToken) parserState.Pop() parserState.TokenMarker = None else: parserState.NewToken = ClosingRoundBracketToken(token) # parserState.NewBlock = CloseBlock(parserState.LastBlock, parserState.NewToken) # parserState.Pop() elif (token == ";"): if (parserState.Counter == 1): parserState.NewToken = DelimiterToken(token) parserState.NewBlock = ItemBlock( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) _ = DelimiterBlock(parserState.NewBlock, parserState.NewToken) parserState.NextState = DelimiterBlock.stateItemDelimiter else: raise TokenParserException( "Mismatch in opening and closing parenthesis: open={0}" .format(parserState.Counter), token)
def stateDot1(cls, parserState: ParserState): token = parserState.Token if isinstance(token, WordToken): 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, SpaceToken): #parserState.NewToken = BoundaryToken(token) parserState.NextState = cls.stateWhitespace2 return elif isinstance(token, (LinebreakToken, CommentToken)): block = LinebreakBlock if isinstance( token, LinebreakToken) else CommentBlock parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = block(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace2 return raise BlockParserException("Expected package name after '.'.", 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 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 stateSubtypeIndication(cls, parserState: ParserState): token = parserState.Token if (isinstance(token, FusedCharacterToken) and (token == ":=")): parserState.NewToken = VariableAssignmentKeyword(token) parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken) parserState.NextState = cls.DELIMITER_BLOCK.stateItemDelimiter parserState.PushState = cls.EXPRESSION.stateBeforeExpression parserState.TokenMarker = None parserState.Counter = 0 return elif isinstance(token, CharacterToken): if (token == ';'): parserState.NewToken = DelimiterToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) _ = cls.DELIMITER_BLOCK(parserState.NewBlock, parserState.NewToken) parserState.Pop() return elif (token == ')'): parserState.NewToken = BoundaryToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) parserState.Pop(2) parserState.TokenMarker = parserState.NewToken return elif isinstance(token, SpaceToken): parserState.NewToken = BoundaryToken(token) parserState.NextState = cls.stateWhitespace5 return elif isinstance(token, (LinebreakToken, CommentToken)): block = LinebreakBlock if isinstance( token, LinebreakToken) else CommentBlock parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = block(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace5 return raise TokenParserException( "Expected ';', ':=' or whitespace after subtype indication.", token)
def stateWhitespace2(cls, parserState: ParserState): token = parserState.Token if isinstance(token, WordToken): 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, WordToken): 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 BlockParserException("Expected package name (identifier).", token)
def stateWhitespace4(cls, parserState: ParserState): token = parserState.Token if (isinstance(token, CharacterToken) and (token == ".")): parserState.NewToken = DelimiterToken(token) parserState.NextState = cls.stateDot1 return elif isinstance(token, StringToken): if (token <= "all"): parserState.NewToken = AllKeyword(token) else: parserState.NewToken = IdentifierToken(token) parserState.NextState = cls.stateObjectName return elif isinstance(token, ExtendedIdentifier): parserState.NextState = cls.stateObjectName 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 object name (identifier) or keyword ALL.", token)
def stateObjectName(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=token.PreviousToken) _ = EndBlock(parserState.NewBlock, parserState.NewToken, endToken=parserState.NewToken) parserState.Pop() return elif isinstance(token, SpaceToken): # parserState.NewToken = WhitespaceBlock(parserState.LastBlock, token) parserState.NextState = cls.stateWhitespace5 return elif isinstance(token, LinebreakToken): parserState.NextState = cls.stateWhitespace5 return elif isinstance(token, CommentToken): parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = CommentBlock(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace5 return raise BlockParserException("Expected ',', ';' or whitespace.", token)
def stateTypeName(cls, parserState: ParserState): token = parserState.Token if isinstance(token, CharacterToken): if (token == ';'): parserState.NewToken = DelimiterToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) _ = cls.DELIMITER_BLOCK(parserState.NewBlock, parserState.NewToken) parserState.Pop() return elif (token == ')'): parserState.NewToken = BoundaryToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) parserState.Pop(2) parserState.TokenMarker = parserState.NewToken return elif isinstance(token, SpaceToken): parserState.NewToken = BoundaryToken(token) parserState.NextState = cls.stateWhitespace2 return elif isinstance(token, (LinebreakToken, CommentToken)): block = LinebreakBlock if isinstance( token, LinebreakToken) else CommentBlock parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = block(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace2 return raise TokenParserException( "Expected ';', ')' or whitespace after interface type name.", token)
def stateWhitespace2(cls, parserState: ParserState): token = parserState.Token if (isinstance(token, CharacterToken) and (token == ":")): parserState.NewToken = DelimiterToken(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, 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 ':' after interface {0} name.".format(cls.OBJECT_KIND), token)
def stateLibraryName(cls, parserState: ParserState): token = parserState.Token if (isinstance(token, CharacterToken) and (token == ".")): parserState.NewToken = DelimiterToken(token) parserState.NextState = cls.stateDot1 return elif isinstance(token, SpaceToken): #parserState.NewToken = BoundaryToken(token) parserState.NextState = cls.stateWhitespace1 return elif isinstance(token, (LinebreakToken, CommentToken)): block = LinebreakBlock if isinstance( token, LinebreakToken) else CommentBlock parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=token.PreviousToken, multiPart=True) _ = block(parserState.NewBlock, token) parserState.TokenMarker = None parserState.NextState = cls.stateWhitespace1 return raise TokenParserException("Expected '.' after library name.", token)
def stateWhitespace5(cls, parserState: ParserState): token = parserState.Token if (isinstance(token, FusedCharacterToken) and (token == ":=")): parserState.NewToken = VariableAssignmentKeyword(token) parserState.NewBlock = cls(parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken) parserState.NextState = cls.DELIMITER_BLOCK.stateItemDelimiter parserState.PushState = cls.EXPRESSION.stateBeforeExpression parserState.Counter = 0 return elif isinstance(token, CharacterToken): if (token == ';'): parserState.NewToken = DelimiterToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) _ = cls.DELIMITER_BLOCK(parserState.NewBlock, parserState.NewToken) parserState.Pop() return elif (token == ')'): parserState.NewToken = BoundaryToken(token) parserState.NewBlock = cls( parserState.LastBlock, parserState.TokenMarker, endToken=parserState.NewToken.PreviousToken) parserState.Pop(2) parserState.TokenMarker = parserState.NewToken return elif isinstance(token, 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)