Skip to content

Commit

Permalink
Add except?.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramarren committed Mar 28, 2012
1 parent d246c1d commit c12c799
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@
#:parse-sequence*
#:quoted?
#:pure-word?
#:pure-word*)
#:pure-word*
#:except?)
;; some function for creating -using-context parsers from other packages
(:export #:storage-of
#:common-of
Expand Down
9 changes: 9 additions & 0 deletions parsers.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,15 @@ otherwhise return it as a result"
(result hooked)
(zero)))))

(defun except? (p q)
"Parser: match p unless q matches."
(let ((not-q-result (gensym)))
(with-parsers (p q)
(mdo (<- maybe-q-result (choice1 q (result not-q-result)))
(if (eql maybe-q-result not-q-result)
p
(zero))))))

(defmacro named? (name &body body)
"Parser macro: give BODY a NAME, so it can refer to itself without causing generator recursion."
(with-unique-names (parser wrapped inp)
Expand Down

0 comments on commit c12c799

Please sign in to comment.