mliebelt / pgn-parser

Javascript library to allow reading of a PGN (Portable Game Notation) chess game notation, and providing the result as JSON.
Apache License 2.0
65 stars 20 forks source link

cannot parse chessjs generated pgn #528

Closed Mansour-J closed 6 months ago

Mansour-J commented 6 months ago

I generated a PGN from chess.js by giving it moves and calling chess.pgn() - and now try to parse it and recieeve below errors:

image

[Event "Fork"]
[SetUp "1"]
[FEN "4r2k/R7/5N1p/p7/5p2/1P5P/P4PPK/2r5 b - - 5 44"]
[Chapter "From: 500 To: 600"]
[Informational "False"]

44. ... Rf8 45. Rh7#

I have tried to load this pgn in Lichess and few other websites and they are all fine. Is there something wrong with this pgn based on the PGN spec? or it's the parser?

mliebelt commented 6 months ago

If you look at the PGN specification, it says:

... PGN import format move number indications may have zero or more period characters following the digit sequence that gives the move number; one or more white space characters may appear between the digit sequence and the period(s). ...

That means the following:

The problem lays in the 2 times . character with spaces in between. I will think of if the grammar could be changed, to be more flexible here, but it conforms to the specification (which is not known too much ...).

Thank you for the information!

mliebelt commented 6 months ago

@Mansour-J I released a new patch version of pgn-parser, that fixes the bug you mentioned. Could you please check that the new version works with the examples you provided?

Mansour-J commented 6 months ago

Sorry I was away in weekend @mliebelt - yes it is fixed - below is a screenshot of the stuff variations I tried with it ~ Thanks 🙌🙏

image