[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 45/255: looking at a new method of parsing trees
From: |
Eric Schulte |
Subject: |
[elpa] 45/255: looking at a new method of parsing trees |
Date: |
Sun, 16 Mar 2014 01:02:16 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 8903ce95203c93e3e6ddbad5cff4973c8ea996a6
Author: Eric Schulte <address@hidden>
Date: Sat May 19 18:20:26 2012 -0400
looking at a new method of parsing trees
---
sgf.el | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/sgf.el b/sgf.el
index c6be14d..f2f3090 100644
--- a/sgf.el
+++ b/sgf.el
@@ -98,6 +98,17 @@
(defun other-color (color)
(if (equal color :b) :w :b))
+(defun rcons (x l) (append l (list x)))
+
+(defmacro rpush (x place)
+ "Insert X at the tail of the list stored in PLACE.
+Analogous to (setf PLACE (rcons X PLACE)), though more careful about
+evaluating each argument only once and in the right order. PLACE may
+be a symbol, or any generalized variable allowed by `setf'."
+ (if (symbolp place)
+ (list 'setq place (list 'rcons x place))
+ (list 'callf2 'rcons x place)))
+
;;; Parsing
(defmacro parse-many (regexp string &rest body)
@@ -146,17 +157,6 @@
(parse-many parse-node-re str
(collect (parse-props (match-string 1 str)))))
-(defun parse-trees (str)
- (let ((cont-p 0))
- (parse-many parse-tree-part-re str
- (setq
- start (match-beginning 2)
- res (add-tree cont-p (save-match-data
- (parse-nodes (match-string 1 str))) res)
- cont-p
- (+ cont-p
- (if (string= "(" (substring (match-string 0 str)
- (1- (length (match-string 0 str)))))
(defun closing-paren (str &optional index)
;; return index of closing paren watching out for []
(save-match-data
@@ -172,15 +172,15 @@
((and (= char ?\)) (zerop square-open)) (decf paren-open))))
when (zerop paren-open) return n))))
- 1 -1))))))
-
-(defun add-tree (cont-p tree-part res)
- (flet ((do-car (n acc) (if (<= n 0) acc (do-car (1- n) `(car ,acc)))))
- (if (null res)
- (setf res (nreverse tree-part))
- ;; TODO: almost there but need to push onto the end
- (eval `(push (nreverse tree-part) ,(do-car (1- cont-p) 'res)))))
- res)
+(defun parse-trees (str)
+ (let (cont-p)
+ (parse-many parse-tree-part-re str
+ (message "match: %d:%S" (1- (match-end 0)) (substring str (1- (match-end
0)) (match-end 0)))
+ (let* ((start (1- (match-end 0)))
+ (end (closing-paren str start)))
+ (collect (parse-nodes (match-string 1 str)))
+ (collect (parse-trees (substring str start end)))
+ (setq start end)))))
(defun read-from-buffer (buffer)
(process (parse-trees (with-current-buffer buffer (buffer-string)))))
- [elpa] 30/255: saving the board configuration with each sgf step, (continued)
- [elpa] 30/255: saving the board configuration with each sgf step, Eric Schulte, 2014/03/15
- [elpa] 18/255: applying moves to a board, Eric Schulte, 2014/03/15
- [elpa] 37/255: remove debug printf, Eric Schulte, 2014/03/15
- [elpa] 34/255: beginning to stub out tests for dead stone removal, Eric Schulte, 2014/03/15
- [elpa] 38/255: more capture tests, failing multistone captures, Eric Schulte, 2014/03/15
- [elpa] 36/255: passing all tests (at least it did this once), Eric Schulte, 2014/03/15
- [elpa] 26/255: improvements, considering labels and moves, Eric Schulte, 2014/03/15
- [elpa] 40/255: parsing empty properties, Eric Schulte, 2014/03/15
- [elpa] 42/255: more work with tree parsing, Eric Schulte, 2014/03/15
- [elpa] 46/255: TODO: try using load-read-function and try loading these files w/read, Eric Schulte, 2014/03/15
- [elpa] 45/255: looking at a new method of parsing trees,
Eric Schulte <=
- [elpa] 44/255: indentation, Eric Schulte, 2014/03/15
- [elpa] 43/255: paren matching, Eric Schulte, 2014/03/15
- [elpa] 49/255: removed debug stuffs, Eric Schulte, 2014/03/15
- [elpa] 47/255: parsing of sgf files with alternative paths working, Eric Schulte, 2014/03/15
- [elpa] 48/255: all tests are passing, Eric Schulte, 2014/03/15
- [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