yynewstr(game);
for (;;) {
yyboardindex = boardIndex;
- moveType = (ChessMove) yylex();
+ moveType = (ChessMove) Myylex();
switch (moveType) {
case IllegalMove: /* maybe suicide chess, etc. */
if (appData.debugMode) {
} else {
if (gameFileFP == NULL)
return FALSE;
- moveType = (ChessMove) yylex();
+ moveType = (ChessMove) Myylex();
}
done = FALSE;
cm = lastLoadGameStart = EndOfFile;
while (gn > 0) {
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
switch (cm) {
case EndOfFile:
if (cmailMsgLoaded) {
if (gn > 0) {
do {
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
} while (cm == PGNTag || cm == Comment);
}
break;
/* Skip any header junk before position diagram and/or move 1 */
for (;;) {
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
if (cm == EndOfFile ||
cm == GNUChessGame || cm == XBoardGame) {
}
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
/* Handle comments interspersed among the tags */
while (cm == Comment) {
p = yy_text;
AppendComment(currentMove, p, FALSE);
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
}
}
}
}
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
}
if (first.pr == NoProc) {
p = yy_text;
AppendComment(currentMove, p, FALSE);
yyboardindex = forwardMostMove;
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
}
if ((cm == EndOfFile && lastLoadGameStart != EndOfFile ) ||
WhiteDrop, BlackDrop,
NormalMove, AmbiguousMove, IllegalMove, ImpossibleMove,
WhiteWins, BlackWins, GameIsDrawn, GameUnfinished,
- GNUChessGame, XBoardGame, MoveNumberOne,
+ GNUChessGame, XBoardGame, MoveNumberOne, Open, Close, Nothing,
Comment, PositionDiagram, ElapsedTime, PGNTag, NAG
} ChessMove;
do {
yyboardindex = 0;
offset = yyoffset();
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
switch (cm) {
case GNUChessGame:
if ((error = GameListNewGame(¤tListGame))) {
do {
yyboardindex = 1;
offset = yyoffset();
- cm = (ChessMove) yylex();
+ cm = (ChessMove) Myylex();
if (cm == PGNTag) {
ParsePGNTag(yy_text, ¤tListGame->gameInfo);
}
extern void yynewfile P((FILE *f));
extern void yynewstr P((char *s));
-extern int yylex P((void));
+extern int Myylex P((void)); // [HGM] yylex now globally invisible, all calls must use wrapper
extern ChessMove yylexstr P((int boardIndex, char *s, char *buf, int buflen));
extern char currentMoveString[];
extern int yyboardindex;
return (int) GameUnfinished;
}
-[1-9][0-9]*/"."?[ \t\n]*[a-lNnPpRrBQqKACFEWDGHOo] {
+[1-9][0-9]*/"."?[ \t\n]*[a-lnprqoA-Z+] {
/* move numbers */
if ((yyleng == 1) && (yytext[0] == '1'))
return (int) MoveNumberOne;
+ else return (int) Nothing; // [HGM] make sure something is returned, for gathering parsed text
}
\([0-9]+:[0-9][0-9](\.[0-9]+)?\)|\{[0-9]+:[0-9][0-9](\.[0-9]+)?\} {
return (int) Comment;
}
-\([^()]*(\([^()]*(\([^()]*(\([^()]*\)[^()]*)*\)[^()]*)*\)[^()]*)+[^()]*\) { /* very nested () */
- return (int) Comment;
+\( { /* Opening parentheses */
+ return (int) Open;
}
-\([^)][^)]+\) { /* >=2 chars in () */
- return (int) Comment;
+\) { /* closing parentheses */
+ return (int) Close;
}
^[-a-zA-Z0-9]+:" ".*(\n[ \t]+.*)* {
- /* Skip mail headers */
+ return (int) Nothing; /* Skip mail headers */
}
[a-zA-Z0-9'-]+ {
- /* Skip random words */
+ return (int) Nothing; /* Skip random words */
}
.|\n {
- /* Skip everything else */
+ return (int) Nothing; /* Skip everything else */
}
%%
yy_switch_to_buffer(buffer);
#endif /*FLEX_SCANNER*/
- ret = (ChessMove) yylex();
+ ret = (ChessMove) Myylex();
strncpy(text, yy_text, len-1); // [HGM] vari: yy_text is not available to caller after buffer switch ?!?
text[len-1] = NULLCHAR;
return ret;
}
+
+int Myylex()
+{ // [HGM] wrapper for yylex, which treats nesting of parentheses
+ int symbol, nestingLevel = 0, i=0;
+ char *p;
+ static char buf[256*MSG_SIZ];
+ buf[0] = NULLCHAR;
+ do { // eat away anything not at level 0
+ symbol = yylex();
+ if(symbol == Open) nestingLevel++;
+ if(nestingLevel) { // save all parsed text between (and including) the ()
+ for(p=yytext; *p && i<256*MSG_SIZ-2;) buf[i++] = *p++;
+ buf[i] = NULLCHAR;
+ }
+ if(symbol == 0) break; // ran into EOF
+ if(symbol == Close) symbol = Comment, nestingLevel--;
+ } while(nestingLevel || symbol == Nothing);
+ yy_text = buf[0] ? buf : (char*)yytext;
+ return symbol;
+}
yynewstr(tags);
for (;;) {
yyboardindex = 0;
- moveType = (ChessMove) yylex();
+ moveType = (ChessMove) Myylex();
if (moveType == (ChessMove) 0) {
break;
} else if (moveType == PGNTag) {