From 16169311d2d39d82a799fd90c77c829767842c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 19 Oct 2024 20:03:50 -0300 Subject: Revert some changes --- base.lisp | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) (limited to 'base.lisp') diff --git a/base.lisp b/base.lisp index a5d8b9d..61c47bc 100644 --- a/base.lisp +++ b/base.lisp @@ -2,53 +2,29 @@ (defstruct parsing tree - left - limit) + left) (defstruct failure place message) -(defun lazy-parsing-p (r) - (or (functionp r) - (parsing-p r))) - (defun new (tree) - (lambda (input &key limit lazy) - (declare (ignore limit lazy)) + (lambda (input &key lazy) + (declare (ignore lazy)) (make-parsing :tree tree :left input))) -(defun bind (parser f &key (greedy t)) - (lambda (input &key limit lazy) - (let (r) - (if greedy - (setf r (funcall parser input :limit limit)) - (let ((next-parser (funcall f nil input)) - (inner-limit -1)) - (do ((sweep-input input (advance sweep-input))) - ((or (if limit - (> (cursor-distance sweep-input input) limit) - (not (has-data? sweep-input))) - (> inner-limit -1)) - nil) - (when (lazy-parsing-p (funcall next-parser sweep-input :lazy t)) - (setf inner-limit (cursor-distance sweep-input input)) - (when limit (decf limit inner-limit)))) - (if (< inner-limit 0) - (setf r (make-failure :place input - :message "Reached end of input while sweeping.")) - (setf r (funcall parser input :limit inner-limit))))) +(defun bind (parser f) + (lambda (input &key lazy) + (let ((r (funcall parser input))) (cond ((parsing-p r) (if lazy - (lambda (ignored-input &key lazy limit) + (lambda (ignored-input &key lazy) (declare (ignore ignored-input)) (funcall (funcall f (parsing-tree r) input) (parsing-left r) - :lazy lazy - :limit (if greedy (parsing-limit r) limit))) + :lazy lazy)) (funcall (funcall f (parsing-tree r) input) - (parsing-left r) - :limit (if greedy (parsing-limit r) limit)))) + (parsing-left r)))) ((failure-p r) r) (t (error (format nil "Invalid return value: ~a" r))))))) -- cgit v1.2.3