[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 05/255: parse-nodes
From: |
Eric Schulte |
Subject: |
[elpa] 05/255: parse-nodes |
Date: |
Sun, 16 Mar 2014 01:02:08 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit ac2444e06643b63ebaf3405c2918d8f9c9971ec3
Author: Eric Schulte <address@hidden>
Date: Tue May 15 07:06:57 2012 -0400
parse-nodes
---
sgf.el | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/sgf.el b/sgf.el
index 2bda8bb..d9e42ba 100644
--- a/sgf.el
+++ b/sgf.el
@@ -61,10 +61,14 @@
(nreverse res))))
(def-edebug-spec parse-many (regexp string body))
-(defun parse-props (str)
- (parse-many "[[:space:]]*\\([[:alpha:]]+\\(\\[[^;]+?\\]\\)+\\)" str
- (multiple-value-bind (id rest) (parse-prop-ident (match-string 1 str))
- (collect (cons id (parse-prop-vals rest))))))
+(defvar prop-val-re
+ "\\[\\(.*?[^\\]\\)\\]")
+
+(defvar parse-prop-re
+ (format "[[:space:]]*\\([[:alpha:]]+\\(%s\\)+\\)" prop-val-re))
+
+(defvar parse-node-re
+ (format "[[:space:]]*;\\(%s\\)+" parse-prop-re))
(defun parse-prop-ident (str)
(let ((end (if (and (<= ?A (aref str 1))
@@ -74,10 +78,17 @@
(substring str end))))
(defun parse-prop-vals (str)
- (parse-many "\\[\\(.*?[^\\]\\)\\]" str
+ (parse-many parse-prop-re str
(collect (match-string 1 str))))
-(defun parse-nodes ())
+(defun parse-props (str)
+ (parse-many parse-prop-re str
+ (multiple-value-bind (id rest) (parse-prop-ident (match-string 1 str))
+ (collect (cons id (parse-prop-vals rest))))))
+
+(defun parse-nodes (str)
+ (parse-many parse-node-re str
+ (collect (parse-props (match-string 1 str)))))
;;; Tests
@@ -94,4 +105,4 @@
(let* ((str ";B[pq];W[dd];B[pc];W[eq];B[cp];W[cm];B[do];W[hq];B[qn];W[cj]")
(nodes (parse-nodes str)))
(should (= (length nodes) 10))
- (should (tree-equal (car nodes) '("B" "pq") :test #'string=))))
+ (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, 2014/03/15
- [elpa] 04/255: parse-many macro, Eric Schulte, 2014/03/15
- [elpa] 05/255: parse-nodes,
Eric Schulte <=
- [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
- [elpa] 15/255: board display, Eric Schulte, 2014/03/15
- [elpa] 22/255: example sgf file generated using gcoban, Eric Schulte, 2014/03/15