summaryrefslogtreecommitdiff
path: root/core.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'core.lisp')
-rw-r--r--core.lisp34
1 files changed, 14 insertions, 20 deletions
diff --git a/core.lisp b/core.lisp
index be12f99..2870f7b 100644
--- a/core.lisp
+++ b/core.lisp
@@ -1,7 +1,7 @@
(in-package #:monparser)
(defun fail (message)
- (lambda (input &key limit lazy)
+ (lambda (input &key lazy)
(make-failure :place input :message message)))
(defmacro unit (&optional predicate)
@@ -20,20 +20,18 @@
(and (symbolp x)
(string-equal (symbol-name x) "IT"))) predicate))))
(t (error (format nil "Invalid predicate: ~a." predicate))))
- `(lambda (input &key limit lazy)
+ `(lambda (input &key lazy)
(declare (ignore lazy))
- (if (and limit (<= limit 0))
- (make-failure :place input :message "Reached established limit.")
- (if (has-data? input)
- (let ((it (peek input)))
- (if ,predicate
- (make-parsing :tree it :left (advance input) :limit (if limit (1- limit)))
- (make-failure :place input
- :message (format nil "Expected: ~a, Got: ~a" ',predicate it))))
- (make-failure :place input :message "Reached end of input.")))))
+ (if (has-data? input)
+ (let ((it (peek input)))
+ (if ,predicate
+ (make-parsing :tree it :left (advance input))
+ (make-failure :place input
+ :message (format nil "Expected: ~a, Got: ~a" ',predicate it))))
+ (make-failure :place input :message "Reached end of input."))))
(defun one-of (first-parser second-parser &rest other-parsers)
- (lambda (input &key limit lazy)
+ (lambda (input &key lazy)
(declare (ignore lazy))
(labels ((one-of-rec (parsers)
(let ((intermediate-parsers '())
@@ -42,8 +40,7 @@
(dolist (p parsers)
(let ((r (funcall p
input
- :lazy (> (length parsers) 1)
- :limit limit)))
+ :lazy (> (length parsers) 1))))
(cond ((functionp r)
(push r intermediate-parsers))
((parsing-p r)
@@ -73,17 +70,14 @@
`(bind ,parser
(lambda (&rest ,unused)
(declare (ignore ,unused))
- (comp ,(cdr bindings) ,@body))
- :greedy ,(not lazy))
+ (comp ,(cdr bindings) ,@body)))
`(bind ,parser
(lambda (,var &rest ,unused)
(declare (ignore ,unused))
- (comp ,(cdr bindings) ,@body))
- :greedy ,(not lazy)))
+ (comp ,(cdr bindings) ,@body))))
(if (and (consp var) (symbolp (car var)) (symbolp (cdr var)))
`(bind ,parser
(lambda (,(car var) ,(cdr var) &rest ,unused)
(declare (ignore ,unused))
- (comp ,(cdr bindings) ,@body))
- :greedy ,(not lazy))
+ (comp ,(cdr bindings) ,@body)))
(error "Binding must be either a symbol or a cons of symbols."))))))