diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-12 16:09:29 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2024-10-12 16:09:29 -0300 |
commit | 1b00d7b4b1eaa3b1ce2ea12e3bfa255450143cb5 (patch) | |
tree | 051dec13a4007734c15c51cd10d3baf588307b41 /parser.lisp | |
parent | 26653bc01c3ed47983d1c618eef03ff5a73672bf (diff) | |
download | monparser-1b00d7b4b1eaa3b1ce2ea12e3bfa255450143cb5.tar.gz monparser-1b00d7b4b1eaa3b1ce2ea12e3bfa255450143cb5.zip |
Handle case where many parses an empty result
Diffstat (limited to 'parser.lisp')
-rw-r--r-- | parser.lisp | 8 |
1 files 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)) |