From 16169311d2d39d82a799fd90c77c829767842c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sat, 19 Oct 2024 20:03:50 -0300 Subject: Revert some changes --- core.lisp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'core.lisp') 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.")))))) -- cgit v1.2.3