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

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

[elpa] 09/255: parsing more complex trees


From: Eric Schulte
Subject: [elpa] 09/255: parsing more complex trees
Date: Sun, 16 Mar 2014 01:02:09 +0000

eschulte pushed a commit to branch go
in repository elpa.

commit af8c08546d812aa01be30f09f61338cc193424bb
Author: Eric Schulte <address@hidden>
Date:   Tue May 15 08:00:44 2012 -0400

    parsing more complex trees
---
 sgf.el |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/sgf.el b/sgf.el
index 1e0f1f0..48b5954 100644
--- a/sgf.el
+++ b/sgf.el
@@ -98,13 +98,14 @@
     (collect (parse-props (match-string 1 str)))))
 
 (defun parse-trees (str)
-  (parse-many parse-tree-part-re str
-    (setq start (match-beginning 2))
-    (let ((cont-p (string= (match-string 2 str) "("))
-          (tree-part (parse-nodes (match-string 1 str))))
-      (setq res (if cont-p
-                    (list tree-part res)
-                  (cons tree-part res))))))
+  (let (cont-p)
+    (parse-many parse-tree-part-re str
+      (setq start (match-beginning 2))
+      (let ((tree-part (parse-nodes (match-string 1 str))))
+        (setq res (if cont-p
+                      (list tree-part res)
+                    (cons tree-part res)))
+        (setq cont-p (string= (match-string 2 str) "("))))))
 
 
 ;;; Tests
@@ -147,3 +148,15 @@
     (should (= 1  (length tree)))
     (should (= 1  (length (car tree))))
     (should (= 10 (length (caar tree))))))
+
+(ert-deftest sgf-parse-nested-tree ()
+  (let* ((str "(;GM[1]FF[4]
+               SZ[19]
+               GN[GNU Go 3.7.11 load and print]
+               DT[2008-12-14]
+               KM[0.0]HA[0]RU[Japanese]AP[GNU Go:3.7.11]
+               (;AW[ja][oa][pa][db][eb] ;AB[fa][ha][ia][qa][cb]))")
+         (tree (parse-trees str)))
+    (should (= 2  (length tree)))
+    (should (= 9 (length (car (first tree)))))
+    (should (= 2 (length (second tree))))))



reply via email to

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