summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-09-24 09:52:27 -0500
committerColin Okay <cbeok@protonmail.com>2020-09-24 09:52:27 -0500
commit8ad16d7f71ebce2f69f8df7aebfda5bf5715019c (patch)
treefa9672e47470e692986c39c65df01d8daf930122
parent148c1728d09c94175ebbc3ce5827967985c9a2ac (diff)
added <<conditionally
-rw-r--r--package.lisp1
-rw-r--r--parzival.lisp11
2 files changed, 11 insertions, 1 deletions
diff --git a/package.lisp b/package.lisp
index efd3e50..086fa0d 100644
--- a/package.lisp
+++ b/package.lisp
@@ -15,6 +15,7 @@
#:<<char
#:<<char-brackets
#:<<char-equal
+ #:<<conditionally
#:<<cons
#:<<cons-map
#:<<counting
diff --git a/parzival.lisp b/parzival.lisp
index cc88725..71bb6c0 100644
--- a/parzival.lisp
+++ b/parzival.lisp
@@ -54,7 +54,7 @@ and the thrid value is the stream stream. The stream will be left in
whatever state it was in when the parse stopped, either successfully
or not."
`(progn
- (defvar ,name ',name)
+ (defparameter ,name ',name)
(defun ,name (stream) ,docstring (funcall ,parser stream))))
@@ -116,6 +116,15 @@ in then. If the parse fails the combinator else is run instead."
`(<<if (,var ,parser ,stream) ,form <fail<))
+(defmacro <<conditionally (condition then else)
+ "Returns a parser that is sensative to the current state. If
+CONDITION is true, then the THEN parser is run, otherwise the ELSE parser is run."
+ `(lambda (stream)
+ (if ,condition
+ (funcall ,then stream)
+ (funcall ,else stream))))
+
+
;;; The <<PLUS COMBINATOR is vital, and gives us amazing powers to choose our
;;; own future! This section defines <<plus and uses it to define some nice utilities.