likeawizard / polyglot-composer

A library to compose polyglot opening books from PGN game collections
GNU General Public License v3.0
5 stars 0 forks source link

Separate sources from parser #25

Closed likeawizard closed 1 year ago

likeawizard commented 1 year ago

The PGN parser should be just that - parsing PGN's it should not be dealing with different sources web/file, .pgn / .pgn.zst ....

With the introduction of bz2, zst and directories (weg resources in the future) the parser is growing with a lot of functionality that should not concern it. There is also duplication of some code between the ParsePaths and NewScanner that both deal with reading files.

Create a new source.go in the pgn package and define an interface like: type PGNSource interface { Open() Close() ReadBytes() Size() // For compressed types it should return the decompressed size estimate. }

The NewScanner(source PGNSource) takes a PGNSource.

Each type of source should be defined in a new struct type like: PlainPGN, Bz2PGN, ZstPGN that have underlying implementation for their file types and that they all implement the PGNSource

The parse paths can be refactored to return PGNSource than can be directly passed to a NewScanner