Created
March 9, 2012 21:07
-
-
Save dbushenko/2008707 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/defparser number [] | |
(p/let->> [d (p/many (p/digit))] | |
(p/always (reduce str d)))) | |
(declare e2) | |
(p/defparser e [] | |
(p/>> (number) (e2))) | |
(p/defparser e2 [] | |
(p/choice (p/>> (op) (e)) | |
(p/always nil))) | |
(declare expr) | |
(declare expr2) | |
(p/defparser expr [] | |
(p/choice | |
(expr2) | |
(p/let->> [x (number)] | |
(p/choice (p/let->> [o (op), | |
y (expr)] | |
(p/always (list x o y))) | |
(p/always x))))) | |
(p/defparser expr2 [] | |
(p/let->> [c1 (p/char \(), | |
e (expr), | |
c2 (p/char \))] | |
(p/always (list "[" e "]")))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment