#How does Lichess parse PGN files/text?

8 messages · Page 1 of 1 (latest)

verbal scarab
#

I'm creating a chess app, but the packages I've tried to use for parsing PGN files throw errors:
https://www.npmjs.com/package/pgn-parser
https://www.npmjs.com/package/cm-pgn

However, when I paste the same PGN into Lichess or open the file there, everything works fine. I was wondering how Lichess handles parsing PGN files, particularly in studies, since comments are important for my app

vast dagger
#

it's in scalachess

verbal scarab
#

Great, thanks for sharing! I'll take a closer look at both scalachess and chessops

ripe arrow
verbal scarab
#

Yeah, I’m building a TypeScript app, and I was using the TypeScript version of that package, chess.ts. However, that parser, along with the others I mentioned earlier, was throwing errors. Today, I started using chessops, and it’s able to parse the PGN files that the other packages couldn’t handle.

ripe arrow
# verbal scarab Yeah, I’m building a TypeScript app, and I was using the TypeScript version of t...

chess.ts is not the same package. I was talking about chess.js https://github.com/jhlywa/chess.js which is written in typescript. This package is maintained and quite popular so if you were using this one, it's weird you got errors using it 🤔

GitHub

A TypeScript chess library for chess move generation/validation, piece placement/movement, and check/checkmate/draw detection - jhlywa/chess.js