Browse files

since a data structure might contain nil, test for emptiness of input…

… explicitly
  • Loading branch information...
1 parent 62a199a commit 0f3959eb5e235571e60451fd9af98551720c761a @bwo bwo committed Jan 2, 2013
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/the/parsatron.clj
View
9 src/the/parsatron.clj
@@ -150,10 +150,11 @@
test returns nil or if the input is empty"
[consume?]
(fn [{:keys [input pos] :as state} cok cerr eok eerr]
- (if-let [tok (first input)]
- (if (consume? tok)
- (cok tok (InputState. (rest input) (inc-sourcepos pos tok)))
- (eerr (unexpect-error (str "token '" tok "'") pos)))
+ (if-not (empty? input)
+ (let [tok (first input)]
+ (if (consume? tok)
+ (cok tok (InputState. (rest input) (inc-sourcepos pos tok)))
+ (eerr (unexpect-error (str "token '" tok "'") pos))))
(eerr (unexpect-error "end of input" pos)))))
(defn many

0 comments on commit 0f3959e

Please sign in to comment.