[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 59/255: passing first two tests
From: |
Eric Schulte |
Subject: |
[elpa] 59/255: passing first two tests |
Date: |
Sun, 16 Mar 2014 01:02:19 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 60753a5a854a03ee45fe8e836fff51b776113dfd
Author: Eric Schulte <address@hidden>
Date: Tue May 22 10:33:19 2012 -0400
passing first two tests
---
sgf-tests.el | 29 ++++++++++-------------------
sgf2el.el | 30 ++++++++++++++++--------------
2 files changed, 26 insertions(+), 33 deletions(-)
diff --git a/sgf-tests.el b/sgf-tests.el
index 0f83016..4f65341 100644
--- a/sgf-tests.el
+++ b/sgf-tests.el
@@ -31,17 +31,6 @@
(require 'sgf-board)
(require 'ert)
-(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))))
-
(ert-deftest sgf-parse-simple-tree ()
(let* ((str "(;GM[1]FF[4]
SZ[19]
@@ -49,9 +38,10 @@
DT[2008-12-14]
KM[0.0]HA[0]RU[Japanese]AP[GNU Go:3.7.11]AW[ja][oa]
[pa][db][eb])")
- (tree (parse-trees str)))
- (should (= 1 (length tree)))
- (should (= 10 (length (first tree))))))
+ (sgf (sgf2el-str str)))
+ (should (= 1 (length sgf)))
+ (should (= 10 (length (first sgf))))
+ (should (= 6 (length (car (last (first sgf))))))))
(ert-deftest sgf-parse-nested-tree ()
(let* ((str "(;GM[1]FF[4]
@@ -60,11 +50,12 @@
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 (= 3 (length tree)))
- (should (= 9 (length (first tree))))
- (should (= 6 (length (car (second tree)))))
- (should (= 6 (length (car (third tree)))))))
+ (sgf (sgf2el-str str)))
+ (should (= 2 (length sgf)))
+ (should (= 9 (length (first sgf))))
+ (should (= 2 (length (second sgf))))
+ (should (= 6 (length (car (first (second sgf))))))
+ (should (= 6 (length (car (second (second sgf))))))))
(ert-deftest sgf-parse-file-test ()
(let ((game (read-from-file "sgf-files/jp-ming-5.sgf")))
diff --git a/sgf2el.el b/sgf2el.el
index 5fa11d2..4c60fa3 100644
--- a/sgf2el.el
+++ b/sgf2el.el
@@ -28,17 +28,22 @@
;;; Code:
(eval-when-compile (require 'cl))
-(defvar prop-re "\\([[:alpha:]]+\\)\\(\\(\\[[^\000]*?[^\\]?\\]\\)+\\)")
+(defvar prop-re
+ "\\([[:alpha:]]+\\)\\(\\([[:space:]]*\\[[^\000]*?[^\\]?\\]\\)+\\)")
-(defvar prop-val-re "\\[\\([^\000]*?[^\\]?\\)\\]")
+(defvar prop-val-re
+ "\\[\\([^\000]*?[^\\]?\\)\\]")
(defvar sgf2el-special-properties nil
"A-list of properties and functions to specially convert their values.")
-(defun sgf2el (str)
+(defun sgf2el-str (str)
"Convert a string of sgf into the equivalent Emacs Lisp."
(with-temp-buffer
- (insert str) (sgf2el-region (point-min) (point-max)) (buffer-string)))
+ (insert str)
+ (sgf2el-region (point-min) (point-max))
+ (goto-char (point-min))
+ (read (current-buffer))))
(defun make-keyword (string)
(intern (concat ":" (upcase string))))
@@ -72,19 +77,16 @@
(interactive "r")
(let ((start (copy-marker (or start (point-min))))
(end (copy-marker (or end (point-max))))
- (re (format "\\(%s\\|%s\\)" prop-re ";"))
+ (re (format "\\(%s\\|%s\\)" prop-re "\\(([[:space:]]*\\)*\\(;\\)"))
last-node)
(save-excursion (goto-char start)
(while (re-search-forward re end t)
- (message "1%S 2%S 3%S 4%S 5%S"
- (match-string 1)
- (match-string 2)
- (match-string 3)
- (match-string 4)
- (match-string 5))
- (if (string= (match-string 0) ";")
- (progn (replace-match (if last-node ")(" "("))
- (setq last-node t))
+ (if (string= (match-string 6) ";")
+ (progn
+ (replace-match "(" nil nil nil 6)
+ (when last-node
+ (save-excursion (goto-char (match-beginning 0)) (insert ")")))
+ (setq last-node t))
(let* ((key (sgf2el-convert-prop-key (match-string 2)))
(val (sgf2el-convert-prop-vals key
(sgf2el-all-matches (match-string 3) prop-val-re 1)))
- [elpa] 52/255: more condensed collecting of games w/alternatives, (continued)
- [elpa] 52/255: more condensed collecting of games w/alternatives, Eric Schulte, 2014/03/15
- [elpa] 51/255: parsing large complex files, Eric Schulte, 2014/03/15
- [elpa] 39/255: passing all tests, Eric Schulte, 2014/03/15
- [elpa] 50/255: whitespace, Eric Schulte, 2014/03/15
- [elpa] 41/255: simplified parse-tree, but not done, Eric Schulte, 2014/03/15
- [elpa] 53/255: passing all tests, Eric Schulte, 2014/03/15
- [elpa] 54/255: more parsing/syntax tweaks, Eric Schulte, 2014/03/15
- [elpa] 56/255: some utility functions, Eric Schulte, 2014/03/15
- [elpa] 55/255: new approach to parsing sgf files into elisp, Eric Schulte, 2014/03/15
- [elpa] 61/255: passing first 6 tests, Eric Schulte, 2014/03/15
- [elpa] 59/255: passing first two tests,
Eric Schulte <=
- [elpa] 62/255: automatically normalize elisp sgf buffers, Eric Schulte, 2014/03/15
- [elpa] 58/255: able to load and play through games w/sgf2el, Eric Schulte, 2014/03/15
- [elpa] 60/255: passing first five tests, Eric Schulte, 2014/03/15
- [elpa] 64/255: passing all tests, Eric Schulte, 2014/03/15
- [elpa] 67/255: support for converting *very* large files, Eric Schulte, 2014/03/15
- [elpa] 63/255: consistently passing first 7 tests, Eric Schulte, 2014/03/15
- [elpa] 73/255: indentation, Eric Schulte, 2014/03/15
- [elpa] 66/255: parsing weird comments, Eric Schulte, 2014/03/15
- [elpa] 72/255: tweak header, Eric Schulte, 2014/03/15
- [elpa] 68/255: misc, Eric Schulte, 2014/03/15