summaryrefslogtreecommitdiff
path: root/parser.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'parser.lisp')
-rw-r--r--parser.lisp23
1 files changed, 17 insertions, 6 deletions
diff --git a/parser.lisp b/parser.lisp
index 5470523..82f619e 100644
--- a/parser.lisp
+++ b/parser.lisp
@@ -26,8 +26,8 @@
(make-parsing :tree tree :left input)))
(defun bind-with-input (p f)
- (declare (optimize (speed 3)))
- (declare (type function p f))
+ (declare (optimize (speed 3))
+ (function p f))
(lambda (input)
(let ((r (funcall p input)))
(if (parsing-p r)
@@ -36,8 +36,8 @@
r))))
(defun bind (p f)
- (declare (optimize (speed 3)))
- (declare (type function p f))
+ (declare (optimize (speed 3))
+ (function p f))
(lambda (input)
(let ((r (funcall p input)))
(if (parsing-p r)
@@ -46,8 +46,8 @@
r))))
(defun discarding-bind (p f)
- (declare (optimize (speed 3)))
- (declare (type function p f))
+ (declare (optimize (speed 3))
+ (function p f))
(lambda (input)
(let ((r (funcall p input)))
(if (parsing-p r)
@@ -130,6 +130,17 @@
(xs (optional (many p))))
(cons x xs)))
+(defun repeat (p min &optional (max 0))
+ (if (> min 0)
+ (comp ((x p)
+ (xs (repeat p (1- min) (1- max))))
+ (cons x xs))
+ (if (> max 0)
+ (comp ((x (optional p))
+ (xs (repeat p 0 (if x (1- max) 0))))
+ (if x (cons x xs) x))
+ nothing)))
+
(defparameter whitespace
(comp ((_ (optional (many (unit char:whitespace?)))))
nil))