Created
March 6, 2012 21:17
-
-
Save dbushenko/1989021 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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