From: Frank Duncan Date: Mon, 10 Jan 2022 20:33:14 +0000 (-0600) Subject: Remove dependency in herbie-utility X-Git-Tag: 0.1~2 X-Git-Url: https://code.consxy.com/gitweb/?a=commitdiff_plain;h=00c7e5bc45caa890553519610a96a0159be8e179;p=honey Remove dependency in herbie-utility --- diff --git a/honey.asd b/honey.asd index 94eacaf..ec78242 100644 --- a/honey.asd +++ b/honey.asd @@ -7,4 +7,4 @@ :pathname "src/main" :components ((:file "package") (:file "parse")) - :depends-on (:webthiteth :herbie-utility)) + :depends-on (:webthiteth)) diff --git a/src/main/parse.lisp b/src/main/parse.lisp index af3fca9..74745bc 100644 --- a/src/main/parse.lisp +++ b/src/main/parse.lisp @@ -30,10 +30,13 @@ DESCRIPTION: (list prev) (let* ((line (car lines)) - (parser (getf (cadr (find-if #1'(funcall (getf $1 :checker) line) (reverse *line-parsers*) :key #'cadr)) :parser))) + (parser + (getf + (cadr (find-if (lambda (parser) (funcall (getf parser :checker) line)) (reverse *line-parsers*) :key #'cadr)) + :parser))) (when (not parser) (error "Weird! Couldn't find a match for ~A" line)) (multiple-value-bind (parsed-line squash-prev suspension) (funcall (funcall parser line) prev) - (cond + (cond (squash-prev (parse-lines (cdr lines) parsed-line)) (suspension (let* @@ -58,37 +61,46 @@ DESCRIPTION: (defun parse-inline (str) (let - ((parser (getf (cadr (find-if #1'(funcall (getf $1 :checker) str) (reverse *inline-parsers*) :key #'cadr)) :parser))) + ((parser + (getf + (cadr (find-if (lambda (parser) (funcall (getf parser :checker) str)) (reverse *inline-parsers*) :key #'cadr)) + :parser))) (if parser (funcall parser str) str))) (defmacro defline-parser (regex handler) (let ((regex (format nil "^~A$" regex))) `(progn - (when (not (utils:strassoc ,regex *line-parsers*)) (push (list ,regex nil) *line-parsers*)) - (setf (utils:strassoc ,regex *line-parsers*) - (list - :checker (lambda (str) (cl-ppcre:scan ,regex str)) - :parser (lambda (str) - (apply - (function ,handler) - (mapcar - #'as-text - (coerce (second (multiple-value-list (cl-ppcre:scan-to-strings ,regex str))) 'list))))))))) + (when (not (find ,regex *line-parsers* :key #'car :test #'string=)) (push (list ,regex nil) *line-parsers*)) + (let + ((parser (find ,regex *line-parsers* :key #'car :test #'string=))) + (setf + (cadr parser) + (list + :checker (lambda (str) (cl-ppcre:scan ,regex str)) + :parser (lambda (str) + (apply + (function ,handler) + (mapcar + #'as-text + (coerce (second (multiple-value-list (cl-ppcre:scan-to-strings ,regex str))) 'list)))))))))) (defmacro definline-parser (regex handler) (let ((regex (format nil "^~A$" regex))) `(progn - (when (not (utils:strassoc ,regex *inline-parsers*)) (push (list ,regex nil) *inline-parsers*)) - (setf (utils:strassoc ,regex *inline-parsers*) - (list - :checker (lambda (str) (cl-ppcre:scan ,regex str)) - :parser (lambda (str) - (apply (function ,handler) - (mapcar - #'parse-inline - (coerce (second (multiple-value-list (cl-ppcre:scan-to-strings ,regex str))) 'list))))))))) + (when (not (find ,regex *inline-parsers* :key #'car :test #'string=)) (push (list ,regex nil) *inline-parsers*)) + (let + ((parser (find ,regex *inline-parsers* :key #'car :test #'string=))) + (setf + (cadr parser) + (list + :checker (lambda (str) (cl-ppcre:scan ,regex str)) + :parser (lambda (str) + (apply (function ,handler) + (mapcar + #'parse-inline + (coerce (second (multiple-value-list (cl-ppcre:scan-to-strings ,regex str))) 'list)))))))))) ; each parser function needs to return a function that takes the previous line and returns ;