Factor out keyword parsing, parse bare words

This commit is contained in:
Scott Richmond 2022-02-14 17:32:29 -05:00
parent 40db886843
commit 98b147f5b8

View File

@ -178,15 +178,39 @@
))) )))
(defn- parse-word [parser curr]
(let [next (next parser)]
(case (::token/type next)
::token/lparen ::oops
::token/keyword ::oops
(assoc (advance parser) ::ast {::ast/type ::ast/word :word (::token/lexeme curr)})
)))
(defn- parse-keyword [parser token]
(let [next (next parser)]
(case (::token/type next)
::token/lparen ::oops
(parse-atom parser token))))
(defn- parse-expr [parser] (defn- parse-expr [parser]
(loop [parser parser] (loop [parser parser]
(let [token (current parser)] (let [token (current parser)]
(println "Parsing expr " (::token/type token)) (println "Parsing expr " (::token/type token))
(case (::token/type token) (case (::token/type token)
(::token/number ::token/string ::token/keyword) (::token/number ::token/string)
(parse-atom parser token) (parse-atom parser token)
::token/keyword (parse-keyword parser token)
::token/word (parse-word parser token)
(::token/nil ::token/true ::token/false) (::token/nil ::token/true ::token/false)
(parse-atomic-word parser token) (parse-atomic-word parser token)
@ -200,7 +224,7 @@
)))) ))))
(def source "{1; 2; :foo}\n{1}") (def source "foo")
(def tokens (:tokens (scanner/scan source))) (def tokens (:tokens (scanner/scan source)))