Created
January 6, 2012 02:40
-
-
Save jasonjckn/1568682 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 test1.core | |
(:use [clarsec core monad]) | |
(:use [clojure.pprint :only (pprint)])) | |
(def perm (<$> keyword | |
(<|> (symb "public") | |
(symb "private") | |
(symb "protected")))) | |
(def type | |
(<|> (symb "int") | |
(symb "long"))) | |
(def member-var-decl (let-bind [p perm | |
t type | |
name identifier | |
_ semi] | |
(result {:id :member-var-decl | |
:name name | |
:type t | |
:perm p}))) | |
(def method (let-bind [p perm | |
t type | |
name identifier | |
params (parens (optional identifier)) | |
body (braces identifier) | |
_ semi] | |
(result {:id :method | |
:name name | |
:type t | |
:perm p | |
:body body}))) | |
(def class-def | |
(let-bind [p perm | |
_ (symb "class") | |
name identifier | |
body (braces | |
(many | |
(<|> method member-var-decl)))] | |
(result {:id :class | |
:body body | |
:perm p | |
:name name}))) | |
#_ (pprint (:value (parse class-def "public class X { | |
private int myvar2; | |
private long myvar1; | |
}"))) | |
#_ (parse perm "public") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment