Rewrite elisp parser to use builtin funcs

More accurate and much faster.
This commit is contained in:
Greg Sexton 2014-08-10 16:50:28 +01:00
parent 4d66682979
commit 9d6003f90b

View File

@ -66,28 +66,23 @@ children of the pair."
(parser-1? pair)) (parser-1? pair))
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) (defun origami-elisp-parser (create)
(let ((def-regex "(def\\w*\\s-*\\(\\s_\\|\\w\\)*")) (lambda (content)
(let ((pair (origami-pair (parser-regex def-regex) (with-temp-buffer
(lambda () (origami-paren-parser (lambda (&rest _) nil))) (insert (parser-content-string content))
(parser-char ")") (beginning-of-buffer)
create))) (beginning-of-defun -1)
(parser-0+ (parser-conj (let (beg end offset acc)
(parser-do (while (< (point) (point-max))
(parser-drop-until-regex (concat def-regex "\\|)")) (setq beg (point))
(parser-1? pair)) (search-forward-regexp "(def\\w*\\s-*\\(\\s_\\|\\w\\)*" nil t)
pair))))) (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) (provide 'origami-parsers)