kevinludwig / pgn-parser

Parse PGN files using peg.js
MIT License
36 stars 19 forks source link

there are correct pgns that it is not parsed correctly (with errors) #32

Open sky10p opened 2 years ago

sky10p commented 2 years ago

I have tried to parse this pgn :

[Event "?"] [Site "?"] [Date "2022.04.11"] [Round "?"] [White "Sistema Colle"] [Black "Defensa india de rey"] [Result "*"] [ECO "A70"] [Annotator "sky10p"] [PlyCount "26"] [SourceVersionDate "2022.04.11"]

  1. d4 Nf6 2. Nf3 g6 3. e3 Bg7 {[%cal Gf1e2,Gf1d3]} 4. Bd3 O-O 5. O-O {[%cal Gd7d5,Gc7c5,Gd7d6]} d6 {[%cal Gc2c4,Gb2b3,Gc2c3]} 6. Nbd2 (6. c4 e5 7. dxe5 (7. Nc3 {Si no cambia los peones, queremos forzar que haga d5, desarrollamos el caballo para eso} Nc6 8. d5 (8. b3 Nd7 {[%cal Gg7d4,Ge5d4,Gd7e5,Ge5g4]} 9. d5 Ne7 {[%csl Gc5,Gf5][%cal Gf7f5,Gd7c5]}) 8... Ne7 9. e4 Nd7) 7... dxe5 8. Nxe5 Qe7 9. Nf3 (9. f4 Nbd7 10. Nxd7 Bxd7 11. Nc3 {[%csl Ge3]} Bc6 {[%cal Gf8e8, Ga8d8,Gc6h1,Ge7e3,Gg7a1]}) 9... Rd8 10. Qc2 Nc6 {[%cal Gc6b4]} 11. a3 Qd6 { [%csl Gd3][%cal Gd6d3]} 12. Rd1 (12. Be2 Bf5 13. Qb3 Ne4 14. Qxb7 (14. Nc3 Na5
  2. Qa4 (15. Qb4 Bxc3 16. bxc3 Qa6 {[%csl Gc4,Gc5,Ge2][%cal Ga6e2,Gc7c5]} 17. Bb2 c5 18. Qb5 Be6 19. Qxa6 bxa6 {[%csl Gc4][%cal Ga5c4,Ge6c4,Gd8d1]}) 15... Bxc3 16. bxc3 Nxc3) 14... Rdb8) 12... Bf5 {[%csl Gd3][%cal Gf5c2,Gd6d1]}) (6. b3 {[%cal Gc1b2]} e5 7. dxe5 dxe5 {[%csl Ge4][%cal Ge5e4]} 8. Nxe5 (8. Nbd2 e4
  3. Nxe4 Nxe4 10. Bxe4 Bxa1) (8. e4 Qe7 {[%csl Gd8][%cal Gf8d8,Ge7e5]} 9. Ba3 { [%csl Gf4][%cal Gf6h5,Gh5f4]} (9. Bb2 Rd8 10. Nbd2 Nh5 {[%csl Gf4][%cal Gh5f4]}
  4. Nc4 c5 {[%csl Gd4][%cal Gb8c6,Gc6d4]} 12. Ncxe5 {[%cal Gg7a1]} Nd7 13. Nxd7 (13. Nc4 b5 14. Bxg7 bxc4 {[%cal Gc4d3,Gh5g7,Gg8g7]}) 13... Bxb2 14. Rb1 Bg7 { [%csl Gb6,Gb8,Gc5,Gd7,Ge5,Gf6,Gf8]}) 9... c5 10. Nbd2 Nh5 11. g3 Rd8 12. Nc4 Nc6 13. Ne3 Nf6 14. Qe2 Nd4) 8... Ng4 9. Nxg4 (9. f4 Nxe5 10. fxe5 Bxe5 { [%cal Ge5a1,Gd8h4]} 11. c3 Qh4 12. h3 (12. g3 Bxg3 13. hxg3 Qxg3+ 14. Kh1 Rd8 { [%csl Gh5][%cal Gd8d5,Gd5h5]}) 12... Bxh3 13. gxh3 Qg3+ 14. Kh1 Qh2#) 9... Bxa1 ) 6... a5 {Las negras quieren que las blancas hagan el avance e4 para romper en el centro con su peón de e y empiezan su ataque en el flanco de dama} 7. c3 (7. c4 e5 8. dxe5 (8. b3 Re8 9. Qc2 Na6 10. a3 Qe7 11. Be2 Bf5) 8... dxe5 9. Nxe5 Ne8 {[%csl Gc4][%cal Gg7e5,Gd8d3] Su caballo está atrapado} 10. Ndf3 { [%cal Gd1d3]} Qe7) 7... a4 8. e4 (8. Re1 e5 9. dxe5 dxe5 10. Nxe5 Ng4 11. Nxg4 Qxd3 12. e4 {[%cal Gg4e3]} a3 13. bxa3 Bxg4 14. Qxg4 Bxc3) 8... e5 9. dxe5 dxe5
  5. Nxe5 Ng4 {[%cal Gg4e5,Gg7e5,Gd8d3]} 11. Nxg4 Qxd3 {[%csl Gg4][%cal Gg7a1] Por el peón dejamos su caballo débil y desubicado y abrimos la diagonal del alfil} 12. Ne3 (12. a3 f5 13. exf5 gxf5 14. Ne3 f4 15. Nc2 (15. Nec4 b5 { El caballo queda atrapado}) 15... Be6 16. Nf3 (16. Nb4 Qf5 17. Nf3 c5 {[%csl Ga6,Gd5]} 18. Nc2 (18. Nd3 Rd8) 18... Bb3) 16... Qxd1 17. Rxd1 Bb3 {[%cal Gb3d1]} 18. Rd2 Nc6 19. Ncd4 Nxd4 20. Nxd4 Rfe8 {[%cal Ge8e1]} 21. Kf1 Bc4+ 22. Ne2 Rxe2 23. Rxe2 Re8) 12... Be6 {[%csl Ge4][%cal Gd2f3,Gd3e4]} 13. Nf3 (13. Qc2 Rd8 14. Qxd3 Rxd3 {[%csl Gc3][%cal Ga4a3,Gg7c3]} 15. a3 Na6 {[%csl Gd2,Ge4] [%cal Gc1d2,Gd2e4]} 16. Nf3 Nc5 17. e5 Nb3 18. Rb1 Ra5 {[%csl Ge5][%cal Ga5e5, Gg7e5]}) 13... Qxe4 *

but it's thrown this error: Expected " ", "\"", "\r", "\t", or "\x0C" but "\n" found.

kevinludwig commented 2 years ago

Hi,

I have not looked but what is a symbol like this meaning: "Gg7d4". It's not a notation I am familiar with.

kevinludwig commented 2 years ago

OK so quick research, I can see that %cal and %csl is an extension that is not in the PGN spec. Here's some info I dug up on it quickly, https://chess.stackexchange.com/questions/18402/pgn-with-arrows-and-circles. I'll take a look and see what a reasonable approach would be to dealing with this, but I would assume its some variant of ignoring it or just reading it into a string since its just arbitrary extension data, not actually part of spec.