summaryrefslogtreecommitdiff
path: root/core.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2026-10-25 17:11:22 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2026-10-25 17:11:22 -0300
commit8203d8f2f8bc7f31c98ac4d926de9b35c4bd1669 (patch)
tree1528fb1f17bebaf6bc2ab0aaaa8b6a670e8f6373 /core.lisp
parentc2bc2dbc61a5df9c3a5dfb19cefd83dae93266db (diff)
downloadmonparser-8203d8f2f8bc7f31c98ac4d926de9b35c4bd1669.tar.gz
monparser-8203d8f2f8bc7f31c98ac4d926de9b35c4bd1669.zip
Add a until variant to many
Diffstat (limited to 'core.lisp')
-rw-r--r--core.lisp10
1 files changed, 6 insertions, 4 deletions
diff --git a/core.lisp b/core.lisp
index 502507b..316b5c4 100644
--- a/core.lisp
+++ b/core.lisp
@@ -69,13 +69,15 @@
(defun optional (p)
(one-of p nothing))
-(declaim (ftype (function (parser &key (:all t)) parser) many))
-(defun many (p &key all)
+(declaim (ftype (function (parser &key (:all t) (:until parser)) parser) many))
+(defun many (p &key all until)
(lambda (input)
(let ((result '()))
- (do ((r (funcall p (cursor-rebase input)) (funcall p (result-place r))))
+ (do ((end? (if until (funcall until (cursor-rebase input))) (if until (funcall until (result-place r))))
+ (r (funcall p (cursor-rebase input)) (funcall p (result-place r))))
((or (failure-p r)
- (cursor-at-start? (result-place r)))
+ (cursor-at-start? (result-place r))
+ (parsing-p end?))
(cond ((or (null result)
(and all (cursor-has-data? (result-place (first result)))))
(if (failure-p r)