Skip to content

Instantly share code, notes, and snippets.

@jasonjckn
Created January 8, 2012 04:37
Show Gist options
  • Select an option

  • Save jasonjckn/1577224 to your computer and use it in GitHub Desktop.

Select an option

Save jasonjckn/1577224 to your computer and use it in GitHub Desktop.
(def identifier (m-re #"[a-zA-Z][a-zA-Z0-9]*")) ;; TODO: Is this accurate?
(def modifier (one-of-symb "public protected private static abstract final native
sychronized transient volatile strictfp"))
(def infix-op (one-of-symb "|| && | ^ & == = < > <= << >> > - + * / %"))
(def prefix-op (one-of-symb "++ -- ! ~ + -"))
(def postfix-op (one-of-symb "++ --"))
(def basic-type (one-of-symb "byte short char int long float double boolean"))
(def void (symb "void"))
(def bool-literal (one-of-symb "true false"))
(def literal (<|> stringLiteral
(one-of-symb "null")
bool-literal
natural)) ;; TODO
;; TODO: incomplete
(def simple-expr
(many
(<|> (<$> vec (parens (lazy simple-expr)))
literal
identifier
infix-op)))
(def assignment (m-assoc* :syntax :assignment
:lhs identifier ;; TODO: incomplete??
_ (symb "=")
:rhs simple-expr))
(def expr (<|> assignment simple-expr)) ;; TODO: implement expressions.
(def statement) ;; Forward declare.
;; TODO: Is this right?
(def block (braces (<|> (many (lazy statement)))))
(def if-else (m-assoc* :syntax :if-else
_ (symb "if")
:cond (parens expr)
:when-true statement)) ;; TODO
(def return (m-assoc* :syntax :return
_ (symb "return")
:expr expr
_ semi))
(def expr-statement (<* expr semi))
(def statement (<|> block if-else return expr-statement)) ;; TODO correct???
(def type basic-type) ;; TODO: Not complete.
(def var-decl (m-assoc* :type type
:id identifier))
(def parameter var-decl) ;; TODO: not actually var-decl
(def method-decl (m-assoc* :syntax :method-decl
:modifier modifier ;; TODO: what about multiple modifiers?
:type (<|> type void)
:id identifier
:params (parens (sep-by parameter comma))
;; TODO: What about throws?
:body block)) ;; TODO: Can body be omitted?
(def field-decl (m-assoc* :syntax :field-decl
:modifier modifier ;; TODO: what about multiple modifiers?
:type type
:id identifier
:init (optional (*> (symb "=") expr))))
;; TODO: class extends implements
;; TODO: body is not complete
(def class-decl (m-assoc* :syntax :class-decl
:modifier modifier
_ (symb "class")
:id identifier
:body (braces (many method-decl))))
@sritchie

sritchie commented Jan 8, 2012

Copy link
Copy Markdown

Yo fool, send me your email! I think that description only prints for TODO facts, like

(defn happy! [] "SAD!")

(future-fact "Much-needed test of absolutely nada."
    (happy) => "HAPPY!"
        (provided (happy) => "HAPPY!"))

@jasonjckn

Copy link
Copy Markdown
Author

Hey man, so I'm programmatically creating facts
(facts desc (parse-file contents) => (map-containing {:type :consumed}))
(facts desc (parse-file contents) => (map-containing {:type :failed}))))))

So I'll have to change Midje or something. It's very hard to tell which fact is being triggered.

jasonjckn@gmail.com

@sritchie

Copy link
Copy Markdown

I've started reading about monadic parsers, and the definitions here are making a lot more sense. Good stuff!

@sritchie

Copy link
Copy Markdown

Next step is getting into clarsec.

@jasonjckn

jasonjckn commented Jan 21, 2012 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment