From d4b83007269548b1a83809ac0916ea99e37677b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 5 Oct 2024 15:54:34 -0300 Subject: Fail one-of when the only option left failed --- parser.lisp | 11 +++++------ 1 file 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) -- cgit v1.2.3