Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Implementing a PGN parser. Should I care about the import format ?

Author: Peter Schäfer

Date: 11:01:06 02/21/05

Go up one level in this thread


On February 21, 2005 at 08:49:35, Mathieu Pagé wrote:

>>>I'm currently implementing a pgn parser. I think it is quite dificult to
>>>implement (efficiently) a parser for the PGN import format that require barely
>>>no consistencies.
>>>
>>>So, here is the question. Those of you who have already implemented a pgn
>>>parser, did you implement the import format, or just the export one? Or maybe a
>>>mix of them ? in the later case I would appreciate to have an overview a what
>>>you implemented and what you did not.
>
>I found it funny to read this in the introduction of the standard : "PGN is
>structured for easy reading and writing by human users and for easy parsing and
>generation by computer programs."
>
>Can someone explain me wich feature of the pgn standard is meant to be easy to
>parse ?

It's pretty safe to assume that each tag goes on a separate line. Even if the
import specification does not require it, I've never encountered a different PGN
file.

There are some traps to look out for: not every line starting with a bracket is
a tag. It could be inside a comment.
Same is true for empty lines.

Parsing the game body has some pitfalls too.
Consider this position: White Ke1,Nc3,Ng3, Black Bb4

1.Ne2 is legal PGN. In order to parse it correctly, you must detect that Nc3 is
pinned.

1.Nge3 would be much easier to disambiguate. PGN parsers could be simplified
quite a bit if the PGN standard was more specific at that point.







This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.