summaryrefslogtreecommitdiff
path: root/core.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'core.lisp')
-rw-r--r--core.lisp29
1 files changed, 17 insertions, 12 deletions
diff --git a/core.lisp b/core.lisp
index 833eb41..43dd234 100644
--- a/core.lisp
+++ b/core.lisp
@@ -3,6 +3,7 @@
(defparameter nothing
(new nil))
+(declaim (ftype (function (symbol list) list) normalize))
(defun normalize (sym expression)
(nsubst-if sym
(lambda (x)
@@ -24,19 +25,21 @@
(setf predicate
(normalize 'it predicate))))
(t (error (format nil "Invalid predicate: ~a." predicate))))
- `(lambda (start input)
- (declare (ignore start))
- (if (has-data? input)
- (let ((it (peek input)))
- (if ,predicate
- (make-parsing :tree it
- :start input
- :end (advance input))
- (make-failure :place input
- :message (format nil "Expected: ~a, Got: ~:c." ',predicate it))))
- (make-failure :place input
- :message (format nil "Reached end of input. Expected: ~a." ',predicate)))))
+ `(the parser
+ (lambda (start input)
+ (declare (ignore start))
+ (if (has-data? input)
+ (let ((it (peek input)))
+ (if ,predicate
+ (make-parsing :tree it
+ :start input
+ :end (advance input))
+ (make-failure :place input
+ :message (format nil "Expected: ~a, Got: ~:c." ',predicate it))))
+ (make-failure :place input
+ :message (format nil "Reached end of input. Expected: ~a." ',predicate))))))
+(declaim (ftype (function (parser parser &rest parser) parser) one-of))
(defun one-of (first-parser second-parser &rest other-parsers)
(lambda (start input)
(declare (ignore start))
@@ -63,9 +66,11 @@
(t (error (format nil "Invalid return value: ~a." r))))))
result)))
+(declaim (ftype (function (parser) parser) optional))
(defun optional (p)
(one-of p nothing))
+(declaim (ftype (function (parser &key (:all t)) parser) many))
(defun many (p &key all)
(lambda (start input)
(declare (ignore start))