xboard-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XBoard-devel] Parsing moves from a string


From: h.g. muller
Subject: [XBoard-devel] Parsing moves from a string
Date: Fri, 19 Feb 2010 07:55:59 +0100

I have some problems to make the variation display work reliable.
For this feature I need to parse a piece of PGN that is availabe in
a text buffer (the contents of the comment popup that the user clicked).
Variations in PGN can contain arbitrary PGN elements (including sub-
variatons) To a lesser extent the problem also occurs when walking an
engine PV from the engine thinking output, although there you usually
encounter not as wide a variety in PGN elements. (Some engines do
put move numbers in their PV, though. Not to mention smilies, which are
not even PGN compliant.)

The problem is that XBoard contains no routine to parse consecutive
moves from a string. yylex() seems to parse from file input. There is a
routine ParseOneMove(), which calls yyexstr() to parse the first move
of the string. It was originally used for parsing the engine move. yylexstr()
is a routine that seems to use a kudge to parse from a string: it redirects
the input to a temporary buffer it creates, then calls yylex(), and finally
restores the origina input source.

I now repeatedly call ParseOneMove() repeatedly from ParsePV, but it
does not report back how many characters from the input it parsed. So
when I want to parse the next element of the PV or the variation comment,
I basically have to guess where that starts, by looking for the next space,
or the next closing brace, or whatever. This rapidly gets very complicated,
and is still unreliable.

Is there a way to figure out how many characters yylex() did parse?
As an alternative I could turn ParseOneMove() into ParseNextMove()
that calls yylex() in stead of yylexstr() to parse the next PGN element,
and make a new ParseOneMove() that does the redirection now done
in yylexstr(), then calls ParseNextMove, and finaly restores the input
source. From ParsePV() I could then do something similar, but call
ParseNextMove repeatedly. But I am a bit afraid I will be piling kludge
upon kludge that way.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]