Skip to content

Instantly share code, notes, and snippets.

@jasonjckn
Created January 6, 2012 02:40
Show Gist options
  • Save jasonjckn/1568682 to your computer and use it in GitHub Desktop.
Save jasonjckn/1568682 to your computer and use it in GitHub Desktop.
(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