emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 40/255: parsing empty properties


From: Eric Schulte
Subject: [elpa] 40/255: parsing empty properties
Date: Sun, 16 Mar 2014 01:02:15 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit 406c9bde5d1dac9cf69479373f90ca6ac9f409a0
Author: Eric Schulte <address@hidden>
Date:   Thu May 17 19:39:52 2012 -0400

    parsing empty properties
---
 sgf-files/w-empty-properties.sgf |    6 ++++++
 sgf.el                           |   26 ++++++++++++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/sgf-files/w-empty-properties.sgf b/sgf-files/w-empty-properties.sgf
new file mode 100644
index 0000000..064ad4a
--- /dev/null
+++ b/sgf-files/w-empty-properties.sgf
@@ -0,0 +1,6 @@
+(;EV[Empty Properties]
+  S[4]
+  RE[]
+  PB[]
+  PW[]
+  C[This file has some empty properties.])
diff --git a/sgf.el b/sgf.el
index a350f66..2c260a3 100644
--- a/sgf.el
+++ b/sgf.el
@@ -111,7 +111,7 @@
 (def-edebug-spec parse-many (regexp string body))
 
 (defvar parse-prop-val-re
-  "[[:space:]\n\r]*\\[\\([^\000]*?[^\\]\\)\\]")
+  "[[:space:]\n\r]*\\[\\([^\000]*?[^\\]?\\)\\]")
 
 (defvar parse-prop-re
   (format "[[:space:]\n\r]*\\([[:alpha:]]+\\(%s\\)+\\)" parse-prop-val-re))
@@ -205,7 +205,6 @@
 
 (defun process-label (label-args)
   (mapcar (lambda (l-arg)
-            (message "l-arg:%s" l-arg)
             (if (string-match "\\([[:alpha:]]+\\):\\(.*\\)" l-arg)
                 (list
                  (cons :label (match-string 2 l-arg))
@@ -251,10 +250,14 @@
 
 (defun board-pos-to-string (board pos)
   (let ((size (board-size board)))
-    (flet ((emph (n) (and (= size 19) ; TODO: emph for other size boards
-                          (or (= 3 n)
-                              (= 4 (- size n))
-                              (= n (/ (- size 1) 2))))))
+    (flet ((emph (n) (cond
+                      ((= size 19)
+                       (or (= 3 n)
+                           (= 4 (- size n))
+                           (= n (/ (- size 1) 2))))
+                      ((= size 9)
+                       (or (= 2 n)
+                           (= 4 n))))))
       (let ((val (aref board (pos-to-index pos size))))
         (cond
          ((equal val :w) white-piece)
@@ -330,6 +333,10 @@
       (update-display))
     (pop-to-buffer buffer)))
 
+(defun display-sgf-file (path)
+  (interactive "f")
+  (display-sgf (car (read-from-file path))))
+
 (defun sgf-ref (sgf index)
   (let ((part sgf))
     (while (car index)
@@ -629,3 +636,10 @@
                           (stones-for local-board :w))))
     (with-sgf-file "sgf-files/2-capture.sgf"
       (right 8) (should (tree-equal (counts) '(6 . 0))))))
+
+(ert-deftest sgf-parse-empty-properties ()
+  (with-sgf-file "sgf-files/w-empty-properties.sgf"
+    (should (remove-if-not (lambda (prop)
+                             (let ((val (cdr prop)))
+                               (and (sequencep val) (= 0 (length val)))))
+                           (car sgf)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]