summaryrefslogtreecommitdiff
path: root/parser.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'parser.lisp')
-rw-r--r--parser.lisp31
1 files changed, 17 insertions, 14 deletions
diff --git a/parser.lisp b/parser.lisp
index 16911ec..37abb75 100644
--- a/parser.lisp
+++ b/parser.lisp
@@ -29,16 +29,16 @@
(lambda (input)
(make-failure :place input :message message)))
-(defun any (first-parser &rest other-parsers)
+(defun either (first-parser &rest other-parsers)
(lambda (input)
- (labels ((any-rec (body)
- (if (cdr body)
- (let ((r (funcall (car body) input)))
- (if (parsing-p r)
- r
- (any-rec (cdr body))))
- (funcall (car body) input))))
- (any-rec (cons first-parser other-parsers)))))
+ (labels ((either-rec (body)
+ (if (cdr body)
+ (let ((r (funcall (car body) input)))
+ (if (parsing-p r)
+ r
+ (either-rec (cdr body))))
+ (funcall (car body) input))))
+ (either-rec (cons first-parser other-parsers)))))
(defun unit (&optional (predicate #'characterp))
(lambda (input)
@@ -56,14 +56,17 @@
(p (second (car bindings))))
`(bind ,p (lambda (,v) (comp ,(cdr bindings) ,@body))))))
+(defparameter nothing
+ (new nil))
+
(defun zero-or-one (p)
- (any p (new nil)))
+ (either p nothing))
(defun zero-or-more (p)
- (any (comp ((x p)
- (xs (zero-or-more p)))
- (cons x xs))
- (new nil)))
+ (either (comp ((x p)
+ (xs (zero-or-more p)))
+ (cons x xs))
+ nothing))
(defun one-or-more (p)
(comp ((x p)