blob: 61c47bc9ec0f0a5883f7f08d5435858d8d740c92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
(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)))
(defun 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)))))))
|