Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ea33d1a870
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (34 sloc) 1.112 kb
(ns parsatron.languages.bencode
(:use [the.parsatron]))
(declare ben-value)
(defparser positive-int []
(p-let [digits (many1 (digit))]
(always (read-string (apply str digits)))))
(defparser negative-int []
(p-let [digits (>> (char \-) (many1 (digit)))]
(always (read-string (apply str digits)))))
(defparser ben-integer []
(between (char \i) (char \e)
(defparser ben-bytestring []
(p-let [length (positive-int)
_ (char \:)
chars (times length (any-char))]
(always (apply str chars))))
(defparser ben-list []
(between (char \l) (char \e)
(many (ben-value))))
(defparser ben-dictionary []
(let [entry (p-let [key (ben-value)
val (ben-value)]
(always [key val]))]
(between (char \d) (char \e)
(p-let [entries (many entry)]
(always (into {} entries))))))
(defparser ben-value []
(choice (ben-integer)
Jump to Line
Something went wrong with that request. Please try again.