notnil / chess

chess package for go
MIT License
508 stars 126 forks source link

Fix PGN parsing of games w/ nested variations #125

Open mikeb26 opened 1 year ago

mikeb26 commented 1 year ago

Existing moveListWithComments() contains a parsing bug when the pgn in question contains a game with nested variations. In this case the moveListTokenRe regex doesn't work as expected and results in attempts to parse an illegal game. To demonstrate the problem this commit adds a TestScannerWithNested() test case along with a 0013.pgn fixture which is an export of a lichess study. This commit also fixes the problem by adding a stripVariations() preprocess step in moveListWithComments(). I have a subsequent commit coming which adds a Scanner option to include variations in the game list when processing a pgn.