summaryrefslogtreecommitdiff
path: root/chess-pgn.el
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-09-01 00:23:25 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-09-01 00:23:25 -0400
commitdf9a2a83a17d2b7dec1f650d0258525d42ae8841 (patch)
tree5db23b86dd93a0d2557261dc26f1e68d8624c748 /chess-pgn.el
parent43bbaca3f58764063f2a83f92d747cf45ae182a0 (diff)
Increased the verbosity and number of errors generated for incorrectly parsed
PGN games.
Diffstat (limited to 'chess-pgn.el')
-rw-r--r--chess-pgn.el36
1 files changed, 20 insertions, 16 deletions
diff --git a/chess-pgn.el b/chess-pgn.el
index ab42511..c94c039 100644
--- a/chess-pgn.el
+++ b/chess-pgn.el
@@ -68,6 +68,9 @@
(throw 'done t))
(t
+ (if (eq t (car (last plies)))
+ (error "PGN parser: Expected a ply here: '%s'"
+ (buffer-substring (point) (point-max))))
(nconc plies (list (chess-ply-create*
(chess-ply-next-pos (car (last plies))))))
(throw 'done t)))
@@ -85,22 +88,23 @@ Optionally use the supplied STRING instead of the current buffer."
(chess-pgn-parse)))
(defun chess-pgn-parse ()
- (when (or (looking-at "\\[")
- (and (search-forward "[" nil t)
- (goto-char (match-beginning 0))))
- (let ((game (chess-game-create)))
- (chess-game-set-tags game nil)
- (while (looking-at "\\[\\(\\S-+\\)\\s-+\\(\".+?\"\\)\\][ \t\n\r]+")
- (chess-game-set-tag game (match-string-no-properties 1)
- (read (match-string-no-properties 2)))
- (goto-char (match-end 0)))
- (let ((fen (chess-game-tag game "FEN")) plies)
- (if fen
- (chess-game-set-start-position game (chess-fen-to-pos fen)))
- (setq plies (chess-pgn-read-plies game (chess-game-pos game) t))
- (if plies
- (chess-game-set-plies game plies)))
- game)))
+ (if (or (looking-at "\\[")
+ (and (search-forward "[" nil t)
+ (goto-char (match-beginning 0))))
+ (let ((game (chess-game-create))
+ (begin (point)))
+ (chess-game-set-tags game nil)
+ (while (looking-at "\\[\\(\\S-+\\)\\s-+\\(\".*?\"\\)\\][ \t\n\r]+")
+ (chess-game-set-tag game (match-string-no-properties 1)
+ (read (match-string-no-properties 2)))
+ (goto-char (match-end 0)))
+ (let ((fen (chess-game-tag game "FEN")))
+ (if fen
+ (chess-game-set-start-position game (chess-fen-to-pos fen)))
+ (chess-game-set-plies game (chess-pgn-read-plies game (chess-game-pos game) t)))
+ game)
+ (error "Data not in legal PGN format: '%s'"
+ (buffer-substring (point) (point-max)))))
(defun chess-pgn-insert-annotations (game index ply)
(dolist (ann (chess-pos-annotations (chess-ply-pos ply)))