summaryrefslogtreecommitdiff
path: root/chess-pgn.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-02 06:07:46 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-02 06:08:00 -0400
commitb651df304c04900c38b71fbf1d69bc9c3a56e7b1 (patch)
tree189610fa685752f201d8992b57f9577579ea4b55 /chess-pgn.el
parentdfa8e3a39f5572c8426336f4e4140d43e28bf963 (diff)
Implemented a safer method for parsing algebraic moves, since for some reason
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.
Diffstat (limited to 'chess-pgn.el')
-rw-r--r--chess-pgn.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/chess-pgn.el b/chess-pgn.el
index 5b1b977..662d156 100644
--- a/chess-pgn.el
+++ b/chess-pgn.el
@@ -18,18 +18,24 @@
(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))