[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 02/255: parse nodes
From: |
Eric Schulte |
Subject: |
[elpa] 02/255: parse nodes |
Date: |
Sun, 16 Mar 2014 01:02:07 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit c98ecbf605f25159e832bc5d4622bf94266ad9b5
Author: Eric Schulte <address@hidden>
Date: Tue May 15 00:38:59 2012 -0400
parse nodes
---
sgf.el | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/sgf.el b/sgf.el
index 3f2073d..ba613ba 100644
--- a/sgf.el
+++ b/sgf.el
@@ -51,6 +51,13 @@
(+ 26 (- char ?A))
(- char ?a)))
+(defun parse-props (str)
+ (let (res (start 0))
+ (while (string-match "[[:space:]]*;\\([[:alpha:]]+\\(\\[[^;]+?\\]\\)+\\)"
str start)
+ (setq start (match-end 0))
+ (push (parse-prop (match-string 1 str)) res))
+ (nreverse res)))
+
(defun parse-prop (str)
(multiple-value-bind (id rest) (parse-prop-ident str)
(cons id (parse-prop-vals rest))))
@@ -65,9 +72,11 @@
(defun parse-prop-vals (str)
(let (res (start 0))
(while (string-match "\\[\\(.*?[^\\]\\)\\]" str start)
- (push (match-string 1 str) res)
- (setq start (match-end 0)))
- res))
+ (setq start (match-end 0))
+ (push (match-string 1 str) res))
+ (nreverse res)))
+
+(defun parse-node ())
;;; Tests
@@ -80,5 +89,8 @@
(should (= (length (cdr (parse-prop "TB[as][bs][cq][cr][ds][ep]")))
6))))
-(defun parse-nodes (str)
- )
+(ert-deftest parse-nodes-test ()
+ (let* ((str ";B[pq];W[dd];B[pc];W[eq];B[cp];W[cm];B[do];W[hq];B[qn];W[cj]")
+ (nodes (parse-props str)))
+ (should (= (length nodes) 10))
+ (should (tree-equal (car nodes) '("B" "pq") :test #'string=))))
- [elpa] branch go created (now a5154e6), Eric Schulte, 2014/03/15
- [elpa] 01/255: parsing properties in SGF files, Eric Schulte, 2014/03/15
- [elpa] 02/255: parse nodes,
Eric Schulte <=
- [elpa] 04/255: parse-many macro, Eric Schulte, 2014/03/15
- [elpa] 05/255: parse-nodes, Eric Schulte, 2014/03/15
- [elpa] 03/255: parse-prop -> parse-props, Eric Schulte, 2014/03/15
- [elpa] 08/255: parsing simple trees, Eric Schulte, 2014/03/15
- [elpa] 06/255: passing all tests, Eric Schulte, 2014/03/15
- [elpa] 07/255: some fixes, Eric Schulte, 2014/03/15
- [elpa] 11/255: ignore data directory, Eric Schulte, 2014/03/15
- [elpa] 14/255: processing simple/core properties, Eric Schulte, 2014/03/15
- [elpa] 13/255: splitting into sections & stubbing out parsing, Eric Schulte, 2014/03/15
- [elpa] 12/255: headers, Eric Schulte, 2014/03/15