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

Parser errors on Lichess draw games using "½" character to denote a draw #586

Closed smarnach closed 1 month ago

smarnach commented 1 month ago

To reproduce, download any recent(ish) draw game from Lichess and try to parse it. Error message:

error: Uncaught (in promise) SyntaxError: Expected "!!", "!", "!?", "$", "(", "*", "+-", "-+", "0-1", "1-0", "1/2", "1/2-1/2", ";", "=", "?!", "?", "??", "D", "O-O", "O-O-O", "Z0", "x", "{", "±", "‼", "⁇", "⁈", "⁉", "↑", "→", "⇆", "∓", "∞", "□", "⟳", "⨀", "⩱", "⩲", "", [RNBQKP], [a-h], end of input, integer, or whitespace but "½" found.
    at new peg$SyntaxError (file:///home/sven/.cache/deno/npm/registry.npmjs.org/@mliebelt/pgn-parser/1.4.15/lib/index.umd.js:31:28)
    at peg$buildStructuredError (file:///home/sven/.cache/deno/npm/registry.npmjs.org/@mliebelt/pgn-parser/1.4.15/lib/index.umd.js:1069:22)
    at Object.peg$parse (file:///home/sven/.cache/deno/npm/registry.npmjs.org/@mliebelt/pgn-parser/1.4.15/lib/index.umd.js:8161:21)
    at parseGame (file:///home/sven/.cache/deno/npm/registry.npmjs.org/@mliebelt/pgn-parser/1.4.15/lib/index.umd.js:8203:29)
    at parse (file:///home/sven/.cache/deno/npm/registry.npmjs.org/@mliebelt/pgn-parser/1.4.15/lib/index.umd.js:8191:17)
    at file:///home/sven/private/pgn/main.ts:25:14
mliebelt commented 1 month ago

And I think the error message is clear: the parser expects PGN, and possible values are described here. PGN is a pure ascii format (by definition). I understand that you would like to have it working that way, but I don't think that the parser should accept characters as result characters where the specification is strict.

I did a download of both a game from lichess and chess.com, and lichess has really wrong PGN exported. I will try to file there a ticket, but I see your point: as long as lichess is doing it wrong, all others have to follow :-( ( I hate that).

The fix should be easy, I will try my very best ...

games.zip

fitztrev commented 1 month ago

Will be reverted on the next Lichess deploy https://github.com/lichess-org/scalachess/commit/9b558ff6478a810358cb1bea30bef6835afe96e8

mliebelt commented 1 month ago

Wow, @fitztrev was pretty fast. I would have not known where to search for. Glad that someone else noticed the problem (Lichess), and will fix it there. So I will close this ticket, because problem will go away soon. As long as you face the problem, use textuell query/replace of "½" with "1/2".