Skip to content

Instantly share code, notes, and snippets.

@apg
Created April 26, 2011 20:53
Show Gist options
  • Save apg/943119 to your computer and use it in GitHub Desktop.
Save apg/943119 to your computer and use it in GitHub Desktop.
(def alphas (c/one-of "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(def digits c/digit)
(def special (c/one-of ".-"))
(def float-value
(domonad c/parser-m
[sign (c/optional (c/is-char \-))
rat c/natural
dec (c/optional (c/>> (c/is-char \.) c/natural))]
(Float/parseFloat (str sign rat "." dec))))
(def graphite-key (c/stringify (c/many (c/either alphas digits special))))
(def measurement (c/>> (c/is-char \:) float-value))
(def measure-type
(domonad c/parser-m
[_ (c/is-char \|)
t (c/either (c/string "ms") (c/string "c"))]
({"c" :counter "ms" :timing} t)))
(def sample-rate (c/>> (c/is-char \@) float-value))
(def parse-stat
(domonad c/parser-m
[key graphite-key
measure (c/optional measurement)
type measure-type
rate (c/optional sample-rate)]
{:type type
:key key
:value measure
:sample rate}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment