def processPGNText(pgnText: str): lexer = pr.ChessLexer() parser = pr.ChessParser() board = None game = None gameNumber = 0 outputGames = [] def newGame(): nonlocal board, game, gameNumber board = Board.Board() game = Game() gameNumber += 1 # add initial board game.addStep(board.getLastStep()) def processMovement(aa): nonlocal board, game board.makeMovement(aa) game.addStep(board.getLastStep()) def processGameInformation(meta): nonlocal board board.addGameInfo(meta) def processGameFinished(asd): nonlocal game, outputGames game.info = board.getGameInfo() game.id = board.getGameId() outputGames.append(copy.deepcopy(game)) newGame() # Setup parser.setGameInfoDetectedCallback( processGameInformation ) parser.setGameFinishedCallback( processGameFinished ) parser.setMovementDetectedCallback( processMovement ) newGame() # parse the input file parser.parse(lexer.tokenize(pgnText)) return outputGames
def setup_class(self): self.parser = parser.ChessParser() self.lexer = parser.ChessLexer()