Skip to content
Browse files

renamed p-let to let->>

  • Loading branch information...
1 parent ddee90d commit 9d58e1076c60c3ec05679ba3b62198349349417c @youngnh committed Sep 20, 2011
Showing with 12 additions and 12 deletions.
  1. +3 −3 README.md
  2. +5 −5 src/parsatron/languages/bencode.clj
  3. +4 −4 src/the/parsatron.clj
View
6 README.md
@@ -54,16 +54,16 @@ ethos. Look for expansion in this area.
Beyond just verifying that a string is a valid member of some language, The
Parsatron offers you facilities for interacting with and operating on the things
you parse via sequencing of multiple parsers and binding their results. The
-macros `>>` and `p-let` embody this facility.
+macros `>>` and `let->>` embody this facility.
As an example, [bencoded strings](http://en.wikipedia.org/wiki/Bencode) are prefixed by their length and a colon:
(defparser ben-string []
- (p-let [length (integer)]
+ (let->> [length (integer)]
(>> (char \:)
(times length (any-char)))))
-`p-let` allows you to capture and name the result of a parser so it's value may
+`let->>` allows you to capture and name the result of a parser so it's value may
be used later. `>>` is very similar to Clojure's `do` in that it executes it's
forms in order, but "throws away" all but the value of the last form.
View
10 src/parsatron/languages/bencode.clj
@@ -4,11 +4,11 @@
(declare ben-value)
(defparser positive-int []
- (p-let [digits (many1 (digit))]
+ (let->> [digits (many1 (digit))]
(always (read-string (apply str digits)))))
(defparser negative-int []
- (p-let [digits (>> (char \-) (many1 (digit)))]
+ (let->> [digits (>> (char \-) (many1 (digit)))]
(always (read-string (apply str digits)))))
(defparser ben-integer []
@@ -18,7 +18,7 @@
(negative-int))))
(defparser ben-bytestring []
- (p-let [length (positive-int)
+ (let->> [length (positive-int)
_ (char \:)
chars (times length (any-char))]
(always (apply str chars))))
@@ -28,11 +28,11 @@
(many (ben-value))))
(defparser ben-dictionary []
- (let [entry (p-let [key (ben-value)
+ (let [entry (let->> [key (ben-value)
val (ben-value)]
(always [key val]))]
(between (char \d) (char \e)
- (p-let [entries (many entry)]
+ (let->> [entries (many entry)]
(always (into {} entries))))))
(defparser ben-value []
View
8 src/the/parsatron.clj
@@ -67,11 +67,11 @@
([m n] `(nxt ~m ~n))
([m n & ms] `(nxt ~m (>> ~n ~@ms))))
-(defmacro p-let [[& bindings] & body]
+(defmacro let->> [[& bindings] & body]
(let [[bind-form p] (take 2 bindings)]
(if (= 2 (count bindings))
`(bind ~p (fn [~bind-form] ~@body))
- `(bind ~p (fn [~bind-form] (p-let ~(drop 2 bindings) ~@body))))))
+ `(bind ~p (fn [~bind-form] (let->> ~(drop 2 bindings) ~@body))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; m+
@@ -163,13 +163,13 @@
(satisfy #(Character/isLetter %)))
(defn between [open close p]
- (p-let [_ open
+ (let->> [_ open
x p
_ close]
(always x)))
(defn many1 [p]
- (p-let [x p
+ (let->> [x p
xs (many p)]
(always (cons x xs))))

0 comments on commit 9d58e10

Please sign in to comment.
Something went wrong with that request. Please try again.