(in-package #:monparser) (defstruct parsing tree left) (defstruct failure place message) (defun new (tree) (lambda (input &key lazy) (declare (ignore lazy)) (make-parsing :tree tree :left input))) (defmacro bind (parser f) `(lambda (input &key lazy) (let ((r (funcall ,parser input))) (cond ((parsing-p r) (if lazy (lambda (ignored-input &key lazy) (declare (ignore ignored-input)) (funcall (funcall ,f (parsing-tree r) input) (parsing-left r) :lazy lazy)) (funcall (funcall ,f (parsing-tree r) input) (parsing-left r)))) ((failure-p r) r) (t (error (format nil "Invalid return value: ~a" r)))))))