PGN - Comment including the } char

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

PGN - Comment including the } char

Post by Fulvio »

The PGN standard says:
"Comment text may appear in PGN data. There are two kinds of comments. The
first kind is the "rest of line" comment; this comment type starts with a
semicolon character and continues to the end of the line. The second kind
starts with a left brace character and continues to the next right brace
character. Comments cannot appear inside any token.

Brace comments do not nest; a left brace character appearing in a brace comment
loses its special meaning and is ignored. A semicolon appearing inside of a
brace comment loses its special meaning and is ignored. Braces appearing
inside of a semicolon comments lose their special meaning and are ignored."

There is a problem with comments containing right brace } characters.
I can think about a few workarounds:
1) Simply remove } characters from comments
2) Replace } characters with normal )
3) Replace } characters with } and restore } to } when a PGN is opened.

I kind of like the idea of using the HTML entity } because it is transparent for the user, which can re-open the PGN and see his comment unchanged. However the PGN will somehow lose in portability because in other programs the } will not be restore to }.

Which workaround do you think is the best one? Other ideas?
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: PGN - Comment including the } char

Post by gbtami »

"There is a problem with comments containing right brace } characters."
I see no problem here. Can you explain this a bit, please?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: PGN - Comment including the } char

Post by hgm »

Well, the PGN standard says that comments cannot contain a }, as a closing } by definition terminates the comment.

I suppose the problem is: when your GUI has an input field for typing comments, what to do when the user types a } there?

XBoard is not pedantic here, and allows you to type anything. If you make the PGN unparsable by that, it is your own fault, and you should be more careful next time. This was done because the 'comment window' is also used for recursive variations or stuff in brackets, and users that know what they are doing want to combine those can type things like "{xxx} (yyy) (zzz) [bla]". If they type something that doesn't start with { [ ( XBoard will enclose it in { }.
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: PGN - Comment including the } char

Post by gbtami »

Ahh, I see the "problem" now.
Telling the truth all choices suggested by Fulvio are unacceptable IMO.

My suggested choices if user wants to type "{this is a } right brace comment}" in comment editor:
1. Enable typing }. When you parse such .pgn just parse it as spec say: "this is a "
2. Enable typing }, but warn user when he/she save it.
3. Enable typing }, but warn user when he/she wants to save it, and disable saving.
4. Disable typing }.

In PyChess we use 1.
Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: PGN - Comment including the } char

Post by Fulvio »

Sorry if my post wasn't clear and thanks for the suggestions.
However the problem occurs also when games are exported from a database to a PGN file.
Just warning the user with "part of the comment was deleted" or "the PGN is unparsable, you should be more careful next time" feels a bit rude :)

Does anyone have the latest Chessbase?
What it does when a comment containing a } char is exported to PGN?
User avatar
hgm
Posts: 27788
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: PGN - Comment including the } char

Post by hgm »

How can a comment with a } ever end up in the database? Technically everything behind the } would no longer be a comment at the time you submitted the game. If the submission process allows offering the games in non-PGN format, with 'naked' text as comments between the moves, it should be more careful in turning these texts into comments.

In general the thing I hate most is unbalanced brackets/braces/parentheses. So if a } is a forbidden character in comments, a { should not be used either. My preference would be to replace } by )], and then any { that balances it by [(.