summaryrefslogtreecommitdiff
path: root/parzival.lisp
diff options
context:
space:
mode:
authorBoutade <thegoofist@protonmail.com>2019-04-25 20:54:14 -0500
committerBoutade <thegoofist@protonmail.com>2019-04-25 20:54:14 -0500
commit7728cc6880490cd22f27aecfcd7d813d2c9fd9dd (patch)
tree20acd74eb93f69a53394202b85951f9feb1cebaa /parzival.lisp
parentea4eb6812dc310b29dd4cdda344067c46c27e175 (diff)
added <eof< and renamed <<= to <<and-then
Diffstat (limited to 'parzival.lisp')
-rw-r--r--parzival.lisp16
1 files changed, 13 insertions, 3 deletions
diff --git a/parzival.lisp b/parzival.lisp
index afe20d7..83e05e5 100644
--- a/parzival.lisp
+++ b/parzival.lisp
@@ -45,6 +45,16 @@
"Results in next item from the input without consuming it.")
+(<<def <eof<
+ (lambda (stream)
+ (if (peek-char stream)
+ (values t t stream)
+ (values nil nil stream)))
+ "A parser that results in T if the end of the input stream has been
+reached, fails otherwise")
+
+
+
;;; The following two macros make defining combinators much nicer. Both let you
;;; choose what to do with with the input stream based on the result of a a
;;; previous parse.
@@ -124,17 +134,17 @@ the result of P. If P fails, then so does (<<BIND P F)."
(funcall f result))))
-(defun <<= (p f &rest fs)
+(defun <<and-then (p f &rest fs)
"Just like bind but with a chain of functions. Each function accepts the
result of the parse from the previous step and returns a new parser. If any
intermediate parser fails, the whole chain fails."
(if fs
- (apply #'<<= (cons (<<bind p f) fs))
+ (apply #'<<and-then (cons (<<bind p f) fs))
(<<bind p f)))
(defun <<and (p1 p2 &rest ps)
- "Just like <<= but where parse results are ignored. I.e. Applies each parser
+ "Just like <<AND-THEN but where parse results are ignored. I.e. Applies each parser
in sequence, ignoring any intermediate results. The result (<<AND P1 P2 ... PN)
is the result of PN."
(if ps