[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 07/255: some fixes
From: |
Eric Schulte |
Subject: |
[elpa] 07/255: some fixes |
Date: |
Sun, 16 Mar 2014 01:02:09 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 2e3885da367aa8086cca9dd986acd80999da21fd
Author: Eric Schulte <address@hidden>
Date: Tue May 15 07:45:11 2012 -0400
some fixes
---
sgf.el | 32 +++++++++++++++++++++++++++-----
1 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/sgf.el b/sgf.el
index 39683e9..2d72eb3 100644
--- a/sgf.el
+++ b/sgf.el
@@ -62,16 +62,16 @@
(def-edebug-spec parse-many (regexp string body))
(defvar parse-prop-val-re
- "\\[\\(.*?[^\\]\\)\\]")
+ "[[:space:]\n\r]*\\[\\([^\000]*?[^\\]\\)\\]")
(defvar parse-prop-re
- (format "[[:space:]]*\\([[:alpha:]]+\\(%s\\)+\\)" parse-prop-val-re))
+ (format "[[:space:]\n\r]*\\([[:alpha:]]+\\(%s\\)+\\)" parse-prop-val-re))
(defvar parse-node-re
- (format "[[:space:]]*;\\(%s\\)+" parse-prop-re))
+ (format "[[:space:]\n\r]*;\\(\\(%s\\)+\\)" parse-prop-re))
(defvar parse-tree-part-re
- (format "[[:space:]]*(\\(%s\\)[[:space:]]*\\([()]\\)" parse-node-re))
+ (format "[[:space:]\n\r]*(\\(%s\\)[[:space:]\n\r]*\\([()]\\)" parse-node-re))
(defun parse-prop-ident (str)
(let ((end (if (and (<= ?A (aref str 1))
@@ -97,6 +97,15 @@
(parse-many parse-node-re str
(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))))
+ (if cont-p
+ (list tree-part res)
+ (cons tree-part res)))))
+
;;; Tests
(require 'ert)
@@ -105,11 +114,24 @@
(flet ((should= (a b) (should (tree-equal a b :test #'string=))))
(should= (parse-props "B[pq]") '(("B" "pq")))
(should= (parse-props "GM[1]") '(("GM" "1")))
+ (should= (parse-props "GM[1]\nB[pq]\tB[pq]")
+ '(("GM" "1") ("B" "pq") ("B" "pq")))
(should (= (length (cdar (parse-props "TB[as][bs][cq][cr][ds][ep]")))
6))))
-(ert-deftest sgf-parse-nodes-test ()
+(ert-deftest sgf-parse-multiple-small-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-nodes str)))
(should (= (length nodes) 10))
(should (tree-equal (car nodes) '(("B" "pq")) :test #'string=))))
+
+(ert-deftest sgf-parse-one-large-node-test ()
+ (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]")
+ (node (car (parse-nodes str))))
+ (should (= (length node) 10))
+ (should (= (length (cdar (last node))) 5))))
- [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, 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 <=
- [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
- [elpa] 17/255: not using "I" as an index, Eric Schulte, 2014/03/15
- [elpa] 20/255: alright "i" *is* a valid position identifier, Eric Schulte, 2014/03/15
- [elpa] 16/255: cleaned up board printing, Eric Schulte, 2014/03/15
- [elpa] 09/255: parsing more complex trees, Eric Schulte, 2014/03/15