[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 04/255: parse-many macro
From: |
Eric Schulte |
Subject: |
[elpa] 04/255: parse-many macro |
Date: |
Sun, 16 Mar 2014 01:02:08 +0000 |
eschulte pushed a commit to branch go
in repository elpa.
commit 7759093af72f1f31029850279b4f53df02976938
Author: Eric Schulte <address@hidden>
Date: Tue May 15 06:58:14 2012 -0400
parse-many macro
---
sgf.el | 26 +++++++++++++++-----------
1 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/sgf.el b/sgf.el
index 82b027b..2bda8bb 100644
--- a/sgf.el
+++ b/sgf.el
@@ -51,13 +51,20 @@
(+ 26 (- char ?A))
(- char ?a)))
+(defmacro parse-many (regexp string &rest body)
+ (declare (indent 2))
+ `(let (res (start 0))
+ (flet ((collect (it) (push it res)))
+ (while (string-match ,regexp ,string start)
+ (setq start (match-end 0))
+ (save-match-data ,@body))
+ (nreverse res))))
+(def-edebug-spec parse-many (regexp string body))
+
(defun parse-props (str)
- (let (res (start 0))
- (while (string-match "[[:space:]]*\\([[:alpha:]]+\\(\\[[^;]+?\\]\\)+\\)"
str start)
- (setq start (match-end 0))
- (multiple-value-bind (id rest) (parse-prop-ident (match-string 1 str))
- (push (cons id (parse-prop-vals rest)) res)))
- (nreverse res)))
+ (parse-many "[[:space:]]*\\([[:alpha:]]+\\(\\[[^;]+?\\]\\)+\\)" str
+ (multiple-value-bind (id rest) (parse-prop-ident (match-string 1 str))
+ (collect (cons id (parse-prop-vals rest))))))
(defun parse-prop-ident (str)
(let ((end (if (and (<= ?A (aref str 1))
@@ -67,11 +74,8 @@
(substring str end))))
(defun parse-prop-vals (str)
- (let (res (start 0))
- (while (string-match "\\[\\(.*?[^\\]\\)\\]" str start)
- (setq start (match-end 0))
- (push (match-string 1 str) res))
- (nreverse res)))
+ (parse-many "\\[\\(.*?[^\\]\\)\\]" str
+ (collect (match-string 1 str))))
(defun parse-nodes ())
- [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 <=
- [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, 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