summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-05 15:54:34 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2024-10-05 15:54:34 -0300
commitd4b83007269548b1a83809ac0916ea99e37677b5 (patch)
tree8c1e82c56e37a18e8fe2f52a678251ec03dab87d
parentc0e6ab7f1be115c2f3079d74eaa247cab89d1ef0 (diff)
downloadmonparser-d4b83007269548b1a83809ac0916ea99e37677b5.tar.gz
monparser-d4b83007269548b1a83809ac0916ea99e37677b5.zip
Fail one-of when the only option left failed
-rw-r--r--parser.lisp11
1 files changed, 5 insertions, 6 deletions
diff --git a/parser.lisp b/parser.lisp
index b231f14..5495f74 100644
--- a/parser.lisp
+++ b/parser.lisp
@@ -70,15 +70,13 @@
`(new (progn ,@body))
(let ((v (first (car bindings)))
(p (second (car bindings))))
- (if (eq 'symbol (type-of v))
+ (if (symbolp v)
(if (string= (symbol-name v) "_")
`(discarding-bind ,p (lambda () (comp ,(cdr bindings) ,@body)))
`(bind ,p (lambda (,v) (comp ,(cdr bindings) ,@body))))
- (if (and (eq 'cons (type-of v))
- (eq 'symbol (type-of (car v)))
- (eq 'symbol (type-of (cdr v))))
+ (if (and (consp v) (symbolp (car v)) (symbolp (cdr v)))
`(bind-with-input ,p (lambda (,(car v) ,(cdr v)) (comp ,(cdr bindings) ,@body)))
- (error "Binding name/(name,input) must be either a symbol or a cons of symbols."))))))
+ (error "Binding must be either a symbol or a cons of symbols."))))))
(defun one-of (first-parser second-parser &rest other-parsers)
(lambda (input &optional lazy)
@@ -96,7 +94,8 @@
(cursor (parsing-input result))))
(setf result r)))
((failure-p r)
- (when (failure-p result)
+ (when (or (failure-p result)
+ (= (length parsers) 1))
(setf result r))))))
(if intermediate-parsers
(one-of-rec intermediate-parsers)