diff options
-rw-r--r-- | src/org/gnu/clojure/gnunet/parser.clj | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/org/gnu/clojure/gnunet/parser.clj b/src/org/gnu/clojure/gnunet/parser.clj new file mode 100644 index 0000000..c89876a --- /dev/null +++ b/src/org/gnu/clojure/gnunet/parser.clj @@ -0,0 +1,18 @@ +(ns org.gnu.clojure.gnunet.parser + (:use clojure.contrib.monads)) + +(def parser-m (state-t maybe-m)) + +(defn item + "Parser which returns the first item of input." + [xs] + (when (not (empty? xs)) [(first xs) (rest xs)])) + +(defn items + "Produces a parser that returns the first n items of input." + [n] + (with-monad parser-m + (m-when (> n 0) + (domonad [x item + xs (items (- n 1))] + (cons x xs)))))
\ No newline at end of file |