From 9d6003f90bbe5b4be88d36f9ffa4ae5084b1c92a Mon Sep 17 00:00:00 2001 From: Greg Sexton Date: Sun, 10 Aug 2014 16:50:28 +0100 Subject: [PATCH] Rewrite elisp parser to use builtin funcs More accurate and much faster. --- origami-parsers.el | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/origami-parsers.el b/origami-parsers.el index 339f0ce..4da7351 100644 --- a/origami-parsers.el +++ b/origami-parsers.el @@ -66,28 +66,23 @@ children of the pair." (parser-1? pair)) pair)))) -(defun origami-paren-parser (create) - (let ((pair (origami-pair (parser-char "(") - (lambda () (origami-paren-parser create)) - (parser-char ")") - create))) - (parser-0+ (parser-conj - (parser-do - (parser-drop-until-regex "[()]") - (parser-1? pair)) - pair)))) - (defun origami-elisp-parser (create) - (let ((def-regex "(def\\w*\\s-*\\(\\s_\\|\\w\\)*")) - (let ((pair (origami-pair (parser-regex def-regex) - (lambda () (origami-paren-parser (lambda (&rest _) nil))) - (parser-char ")") - create))) - (parser-0+ (parser-conj - (parser-do - (parser-drop-until-regex (concat def-regex "\\|)")) - (parser-1? pair)) - pair))))) + (lambda (content) + (with-temp-buffer + (insert (parser-content-string content)) + (beginning-of-buffer) + (beginning-of-defun -1) + (let (beg end offset acc) + (while (< (point) (point-max)) + (setq beg (point)) + (search-forward-regexp "(def\\w*\\s-*\\(\\s_\\|\\w\\)*" nil t) + (setq offset (- (point) beg)) + (end-of-defun) + (backward-char) + (setq end (point)) + (setq acc (cons (funcall create beg end offset nil) acc)) + (beginning-of-defun -1)) + (list (reverse acc)))))) (provide 'origami-parsers)