]> code.delx.au - gnu-emacs-elpa/commitdiff
Implemented a safer method for parsing algebraic moves, since for some reason
authorJohn Wiegley <johnw@newartisans.com>
Tue, 2 Sep 2008 10:07:46 +0000 (06:07 -0400)
committerJohn Wiegley <johnw@newartisans.com>
Tue, 2 Sep 2008 10:08:00 +0000 (06:08 -0400)
we weren't always seeing the full move when using looking-at.  The way I do it
now is to require some kind of whitespace after the SAN move text.

chess-algebraic.el
chess-pgn.el

index 1f76e1a70764471f3504d22ed0f488f6b26713b0..e9145e7b9924136075017be02320059f025e8798 100644 (file)
@@ -55,6 +55,9 @@ This regexp handles both long and short form.")
 (defconst chess-algebraic-regexp-entire
   (concat chess-algebraic-regexp "$"))
 
+(defconst chess-algebraic-regexp-ws
+  (concat chess-algebraic-regexp "\\s-"))
+
 (chess-message-catalog 'english
   '((clarify-piece     . "Clarify piece to move by rank or file")
     (could-not-clarify . "Could not determine which piece to use")
index 5b1b9773247febbb9fecf3e0409749d2875e558e..662d15667658844e7a82b1bb89f58c4ff4c1812f 100644 (file)
     (pgn-parse-error . "Error parsing PGN syntax")))
 
 (defun chess-pgn-read-plies (game position &optional top-level)
-  (let ((plies (list t)) prevpos)
+  (let ((plies (list t)) (begin (point)) move-beg prevpos)
     (catch 'done
       (while (not (eobp))
        (cond
         ((looking-at "[1-9][0-9]*\\.[. ]*")
          (goto-char (match-end 0)))
 
-        ((looking-at chess-algebraic-regexp)
+        ((looking-at chess-algebraic-regexp-ws)
+         (setq move-beg (point))
          (goto-char (match-end 0))
+         (skip-syntax-backward " ")
          (setq prevpos position)
-         (let* ((move (match-string-no-properties 0))
-                (ply (chess-algebraic-to-ply position move)))
+         (let* ((move (buffer-substring-no-properties move-beg (point)))
+                (ply (condition-case err
+                         (chess-algebraic-to-ply position move)
+                       (error
+                        (message "PGN: %s" (buffer-substring begin (point-max)))
+                        (error (error-message-string err))))))
            (unless ply
              (chess-error 'pgn-read-error move))
            (setq position (chess-ply-next-pos ply))