Skip to content

Instantly share code, notes, and snippets.

@dbushenko
Created March 6, 2012 21:17
Show Gist options
  • Save dbushenko/1989021 to your computer and use it in GitHub Desktop.
Save dbushenko/1989021 to your computer and use it in GitHub Desktop.
(ns ptest.core
(:require [the.parsatron :as p]))
(p/defparser op []
(p/choice (p/char \+)
(p/char \-)
(p/char \*)
(p/char \/)))
(p/defparser number []
(p/let->> [d (p/many (p/digit))]
(p/always (reduce str d))))
(p/defparser expr []
(p/let->> [n1 (number)
o (op)
n2 (number)]
(p/always (list n1 o n2))))
(p/defparser mexpr []
(p/many (expr)))
(p/defparser bexpr []
(p/let->> [b1 (p/char \()
e (mexpr)
b2 (p/char \))]
(list b1 e b2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment