summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package.lisp2
-rw-r--r--parser.lisp23
2 files changed, 18 insertions, 7 deletions
diff --git a/package.lisp b/package.lisp
index 603f6cb..4cdb68f 100644
--- a/package.lisp
+++ b/package.lisp
@@ -22,11 +22,11 @@
#:comp
#:one-of
#:all-of
- #:negate
#:unit
#:literal
#:nothing
#:optional
#:many
+ #:repeat
#:whitespace
#:separated-list))
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))