summaryrefslogtreecommitdiff
path: root/parser.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2024-06-10 03:28:51 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2024-06-10 03:28:51 -0300
commitaabcaf712f67ac88ec8bd32b5477f17c1a182080 (patch)
treebe15f466b92a8d34f9808efc4fbb631bea6bd1d4 /parser.lisp
parent3eba112a9a5be8181b8ca39b2ca955f28984b1b6 (diff)
downloadmonparser-aabcaf712f67ac88ec8bd32b5477f17c1a182080.tar.gz
monparser-aabcaf712f67ac88ec8bd32b5477f17c1a182080.zip
Add repeat parser
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))