summaryrefslogtreecommitdiff
path: root/core.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'core.lisp')
-rw-r--r--core.lisp14
1 files changed, 10 insertions, 4 deletions
diff --git a/core.lisp b/core.lisp
index d0955fe..3d3f4e8 100644
--- a/core.lisp
+++ b/core.lisp
@@ -11,11 +11,15 @@
(setf predicate `(,predicate it)))
((characterp predicate)
(setf predicate `(char-equal ,predicate it)))
- (t (setf predicate
+ ((listp predicate)
+ (if (eq (car predicate) 'function)
+ (setf predicate `(funcall ,predicate it))
+ (setf predicate
(nsubst-if 'it
(lambda (x)
(and (symbolp x)
(string-equal (symbol-name x) "IT"))) predicate))))
+ (t (error (format nil "Invalid predicate: ~a." predicate))))
`(lambda (input &key limit lazy)
(declare (ignore lazy))
(if (and limit (<= limit 0))
@@ -33,7 +37,8 @@
(declare (ignore lazy))
(labels ((one-of-rec (parsers)
(let ((intermediate-parsers '())
- (result nil))
+ (result (make-failure :place input
+ :message "Exhausted options.")))
(dolist (p parsers)
(let ((r (funcall p
input
@@ -48,8 +53,9 @@
(setf result r)))
((failure-p r)
(when (or (failure-p result)
- (= (length parsers) 1))
- (setf result r))))))
+ (= (length parsers) 1))
+ (setf result r)))
+ (t (error (format nil "Invalid return value: ~a" r))))))
(if intermediate-parsers
(one-of-rec intermediate-parsers)
result))))