Parse structs
This commit is contained in:
parent
6b9fc590a6
commit
21af8acf2e
|
@ -222,10 +222,10 @@
|
||||||
(add-member members current_member) nil)
|
(add-member members current_member) nil)
|
||||||
|
|
||||||
(::token/rbracket ::token/rparen)
|
(::token/rbracket ::token/rparen)
|
||||||
(panic parser (str "Mismatched enclosure in set: " (::token/lexeme curr)))
|
(panic parser (str "Mismatched enclosure in hashmap: " (::token/lexeme curr)))
|
||||||
|
|
||||||
::token/eof
|
::token/eof
|
||||||
(panic (assoc origin ::errors (::errors parser)) "Unterminated set" ::token/eof)
|
(panic (assoc origin ::errors (::errors parser)) "Unterminated hashmap" ::token/eof)
|
||||||
|
|
||||||
::token/word
|
::token/word
|
||||||
(if (not current_member) (let [parsed (parse-word parser) word (get-in parsed [::ast :word])]
|
(if (not current_member) (let [parsed (parse-word parser) word (get-in parsed [::ast :word])]
|
||||||
|
@ -234,8 +234,6 @@
|
||||||
|
|
||||||
::token/keyword
|
::token/keyword
|
||||||
(if (not current_member) (let [kw (parse-atom parser) expr (parse-expr kw #{::token/comma ::token/newline ::token/rbrace})]
|
(if (not current_member) (let [kw (parse-atom parser) expr (parse-expr kw #{::token/comma ::token/newline ::token/rbrace})]
|
||||||
(println "found keyword/expr pair:" (:value kw))
|
|
||||||
(pp/pprint (::ast expr))
|
|
||||||
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
||||||
(panic parser "Hashmap entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
(panic parser "Hashmap entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
||||||
|
|
||||||
|
@ -270,8 +268,6 @@
|
||||||
|
|
||||||
::token/keyword
|
::token/keyword
|
||||||
(if (not current_member) (let [kw (parse-atom parser) expr (parse-expr kw #{::token/comma ::token/newline ::token/rbrace})]
|
(if (not current_member) (let [kw (parse-atom parser) expr (parse-expr kw #{::token/comma ::token/newline ::token/rbrace})]
|
||||||
(println "found keyword/expr pair:" (:value kw))
|
|
||||||
(pp/pprint (::ast expr))
|
|
||||||
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
||||||
(panic parser "Struct entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
(panic parser "Struct entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
||||||
|
|
||||||
|
@ -610,11 +606,7 @@
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
(def source "fn foo {
|
(def source "@{:foo :bar, :bar 42}")
|
||||||
(foo, bar, baz) -> {:foo}
|
|
||||||
}
|
|
||||||
|
|
||||||
")
|
|
||||||
(def lexed (scanner/scan source))
|
(def lexed (scanner/scan source))
|
||||||
(def tokens (:tokens lexed))
|
(def tokens (:tokens lexed))
|
||||||
(def p (parser tokens))
|
(def p (parser tokens))
|
||||||
|
@ -626,7 +618,7 @@
|
||||||
(println "*** *** NEW PARSE *** ***")
|
(println "*** *** NEW PARSE *** ***")
|
||||||
|
|
||||||
(-> p
|
(-> p
|
||||||
(parse-fn)
|
(parse-expr)
|
||||||
(::ast)
|
(::ast)
|
||||||
(pp)))
|
(pp)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user