From 1b00d7b4b1eaa3b1ce2ea12e3bfa255450143cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 12 Oct 2024 16:09:29 -0300 Subject: Handle case where many parses an empty result --- parser.lisp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/parser.lisp b/parser.lisp index bfe2614..d22ae81 100644 --- a/parser.lisp +++ b/parser.lisp @@ -40,6 +40,10 @@ :message (format nil "Didn't reach expected limit: ~a." limit)) (make-parsing :tree tree :left input)))) +(defun fail (message) + (lambda (input &key limit lazy) + (make-failure :place input :message message))) + (defun bind (p f &key (greedy t)) (lambda (input &key limit lazy) (let (r) @@ -165,7 +169,7 @@ (defun many (p) (comp ((x p) (xs (if (not x) - (error "Cannot define (many (optional x)). Use (optional (many x)) instead.") + (fail "Parsing result is empty.") (optional (many p))))) (cons x xs))) @@ -191,7 +195,7 @@ (comp ((v p) (sep (optional separator)) (vn (if sep - (crit (separated-list p separator)) + (separated-list p separator) nothing))) (if include-separator (cons v (cons sep vn)) -- cgit v1.2.3