Created
January 8, 2012 04:37
-
-
Save jasonjckn/1577224 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
(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)))) |
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.
I've started reading about monadic parsers, and the definitions here are making a lot more sense. Good stuff!
Next step is getting into clarsec.
The amazing thing about clarsec, is the implementation is so crude that its
easy to understand.
Reading haskell's parsec library is probably hundreds of lines of code --
because it supports error handling, other advance stuff.
i'm working on my compiler right now -- it's been a lot of fun.
…On Sat, Jan 21, 2012 at 2:57 PM, Sam Ritchie < ***@***.*** > wrote:
Next step is getting into clarsec.
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1577224
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yo fool, send me your email! I think that description only prints for TODO facts, like