X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.l;h=e78c23c0902977e6f2f1f5e0f653c1e3b8acbfb2;hb=582aeb45129ac85b911614bee1b9cdf8ff0636b5;hp=4ac67dc55ab4ea41598c4b7f3c12f375cb23fbe6;hpb=7d010a9891c42f6e60eb18cbf5b75be9878a8336;p=xboard.git diff --git a/parser.l b/parser.l index 4ac67dc..e78c23c 100644 --- a/parser.l +++ b/parser.l @@ -178,7 +178,7 @@ extern void CopyBoard P((Board to, Board from)); %} %% -"+"?[A-Z][/]?[a-l][0-9][xX:-]?[a-l][0-9]((=?\(?[A-Z]\)?)|[=+])? { +"+"?[A-Z][/]?[a-l][0-9][xX:-]?[a-l][0-9](([=/]?\(?[A-Z]\)?)|[=+])? { /* * Fully-qualified algebraic move, possibly with promotion */ @@ -268,7 +268,7 @@ extern void CopyBoard P((Board to, Board from)); return (int) result; } -[a-l][0-9][xX:-]?[a-l][0-9]((=?\(?[A-Za-z]\)?)|[=+])? { +[a-l][0-9][xX:-]?[a-l][0-9](([=/]?\(?[A-Za-z]\)?)|[=+])? { /* * Simple algebraic move, possibly with promotion * [HGM] Engine moves are received in this format, with lower-case promoChar! @@ -294,7 +294,7 @@ extern void CopyBoard P((Board to, Board from)); } else { c = currentMoveString[4] = ToLower(yytext[yyleng-1]); } - if(c == '+' && gameInfo.variant != VariantShogi) c = currentMoveString[4] = NULLCHAR; // + means check outside Shogi + if(c == '+' && gameInfo.variant != VariantShogi) currentMoveString[4] = NULLCHAR; // + means check outside Shogi currentMoveString[5] = NULLCHAR; } @@ -330,7 +330,7 @@ extern void CopyBoard P((Board to, Board from)); } else if(result == WhiteNonPromotion || result == BlackNonPromotion) currentMoveString[4] = '='; currentMoveString[5] = NULLCHAR; - } else if(appData.testLegality && // strip off unnecessary and false promo characters + } else if(appData.testLegality && gameInfo.variant != VariantSChess && // strip off unnecessary and false promo characters !(result == WhitePromotion || result == BlackPromotion || result == WhiteNonPromotion || result == BlackNonPromotion)) currentMoveString[4] = NULLCHAR; @@ -384,7 +384,7 @@ extern void CopyBoard P((Board to, Board from)); * Pawn move, possibly with promotion */ DisambiguateClosure cl; - int skip = 0; char c; + int skip = 0; if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */ @@ -425,7 +425,7 @@ extern void CopyBoard P((Board to, Board from)); * Pawn capture, possibly with promotion, possibly ambiguous */ DisambiguateClosure cl; - int skip1 = 0, skip2 = 0; char c; + int skip1 = 0, skip2 = 0; if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */ @@ -584,11 +584,15 @@ extern void CopyBoard P((Board to, Board from)); if (result == WhiteCapturesEnPassant || result == BlackCapturesEnPassant) return (int) result; - else + else { // [HGM] all very nice, but this messed up the input move that we might want to accept with legality testing off... + if (WhiteOnMove(yyboardindex)) // undo the damage + currentMoveString[1]--, currentMoveString[3]--; + else currentMoveString[1]++, currentMoveString[3]++; return (int) IllegalMove; + } } -"+"?[A-Z][xX:-]?[a-l][0-9]((=?\(?[A-Z]\)?)|[=+])? { +"+"?[A-Z][xX:-]?[a-l][0-9](([=/]?\(?[A-Z]\)?)|[=+])? { /* * piece move, possibly ambiguous */ @@ -616,7 +620,7 @@ extern void CopyBoard P((Board to, Board from)); cl.ftIn = yytext[1+skip] - AAA; cl.promoCharIn = NULLCHAR; - if(yyleng-skip > 3 && gameInfo.variant == VariantShogi) /* [HGM] can have Shogi-style promotion */ + if(yyleng-skip > 3 && (gameInfo.variant == VariantShogi || gameInfo.variant == VariantSChess)) /* [HGM] can have Shogi-style promotion */ cl.promoCharIn = yytext[yyleng-1-(yytext[yyleng-1]==')')]; if(cl.promoCharIn == '+' && gameInfo.variant != VariantShogi) cl.promoCharIn = NULLCHAR; // + means check outside Shogi @@ -645,7 +649,7 @@ extern void CopyBoard P((Board to, Board from)); return (int) cl.kind; } -"+"?[A-Z][a-l0-9][xX:-]?[a-l][0-9]((=?\(?[A-Z]\)?)|[=+])? { +"+"?[A-Z][a-l0-9][xX:-]?[a-l][0-9](([=/]?\(?[A-Z]\)?)|[=+])? { /* * piece move with rank or file disambiguator */ @@ -683,7 +687,7 @@ extern void CopyBoard P((Board to, Board from)); cl.ftIn = yytext[2+skip] - AAA; cl.promoCharIn = NULLCHAR; - if(yyleng-skip > 4) /* [HGM] can have Shogi-style promotion */ + if(yyleng-skip > 4 && (gameInfo.variant == VariantShogi || gameInfo.variant == VariantSChess)) /* [HGM] can have Shogi-style promotion */ cl.promoCharIn = yytext[yyleng-1-(yytext[yyleng-1]==')')]; if(cl.promoCharIn == '+' && gameInfo.variant != VariantShogi) cl.promoCharIn = NULLCHAR; // + means check outside Shogi @@ -819,6 +823,9 @@ extern void CopyBoard P((Board to, Board from)); } [A-Za-z][@*][a-l][0-9] { + + if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */ + /* Bughouse piece drop. */ currentMoveString[1] = '@'; currentMoveString[2] = yytext[2]; @@ -895,19 +902,19 @@ extern void CopyBoard P((Board to, Board from)); return (int) (ToUpper(yytext[0]) == 'W' ? BlackWins : WhiteWins); } -("{"[^\}\n]*"} ")?(1-0|"1 - 0"|"1/0"|"1 / 0"|"1:0"|"1 : 0")(" (".*")"|" {".*"}")? { +("{"[^\}]*"}"[ \n])?(1-0|"1 - 0"|"1/0"|"1 / 0"|"1:0"|"1 : 0")(" (".*")"|" {".*"}")? { return (int) WhiteWins; } -("{"[^\}\n]*"} ")?(0-1|"0 - 1"|"0/1"|"0 / 1"|"0:1"|"0 : 1")(" (".*")"|" {".*"}")? { +("{"[^\}]*"}"[ \n])?(0-1|"0 - 1"|"0/1"|"0 / 1"|"0:1"|"0 : 1")(" (".*")"|" {".*"}")? { return (int) BlackWins; } -("{"[^\}\n]*"} ")?("1/2"|"1 / 2")(" "?[-:]" "?("1/2"|"1 / 2"))?(" (".*")"|" {".*"}")? { +("{"[^\}]*"}"[ \n])?("1/2"|"1 / 2")(" "?[-:]" "?("1/2"|"1 / 2"))?(" (".*")"|" {".*"}")? { return (int) GameIsDrawn; } -("{"[^\}\n]*"} ")?"*"(" (".*")"|" {".*"}")? { +("{"[^\}]*"}"[ \n])?"*"(" (".*")"|" {".*"}")? { return (int) GameUnfinished; }