[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 43/255: paren matching
From: |
Eric Schulte |
Subject: |
[elpa] 43/255: paren matching |
Date: |
Sun, 16 Mar 2014 01:02:15 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 7507d888a4dbf1f11c23379aa8f187ce2d9e6f76
Author: Eric Schulte <address@hidden>
Date: Fri May 18 15:05:49 2012 -0400
paren matching
---
sgf.el | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/sgf.el b/sgf.el
index 2d00c42..55e67cd 100644
--- a/sgf.el
+++ b/sgf.el
@@ -157,6 +157,21 @@
(+ 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
+ (let ((paren-open 0)
+ (square-open 0))
+ (loop for n from (or index 0) to (1- (length str))
+ do (let ((last (when (> n 0) (aref str (1- n))))
+ (char (aref str n)))
+ (cond
+ ((= char ?\[) (incf square-open))
+ ((and (= char ?\]) (not (= last ?\\))) (decf square-open))
+ ((and (= char ?\() (zerop square-open)) (incf paren-open))
+ ((and (= char ?\)) (zerop square-open)) (decf paren-open))))
+ when (zerop paren-open) return n))))
+
1 -1))))))
(defun add-tree (cont-p tree-part res)
@@ -654,3 +669,8 @@
(let ((val (cdr prop)))
(and (sequencep val) (= 0 (length val)))))
(car sgf)))))
+
+(ert-deftest sgf-paren-matching ()
+ (let ((str "(a (b) [c \\] ) ] d)"))
+ (should (= (closing-paren str) (1- (length str))))
+ (should (= (closing-paren str 3) 5))))
- [elpa] 37/255: remove debug printf, (continued)
- [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, 2014/03/15
- [elpa] 44/255: indentation, Eric Schulte, 2014/03/15
- [elpa] 43/255: paren matching,
Eric Schulte <=
- [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
- [elpa] 53/255: passing all tests, Eric Schulte, 2014/03/15
- [elpa] 54/255: more parsing/syntax tweaks, Eric Schulte, 2014/03/15