Parse do expressions/pipelines

This commit is contained in:
Scott Richmond 2022-04-05 15:54:28 -04:00
parent 174eb2d6a5
commit 89f813c2f3

View File

@ -538,6 +538,24 @@
(panic parser "Expected name or clause after fn"))))
(defn- parse-do [parser]
(let [first (advance parser)]
(loop [parser first
exprs []]
(println "parsing do")
(pp/pprint parser)
(pp/pprint exprs)
(let [expr (parse-expr parser)
expr+newline (accept ::token/newline expr)
next (token-type expr+newline)]
(println "current ast " (::ast expr))
(println "next token " next)
(if (= ::token/pipeline next)
(recur (advance expr+newline) (conj exprs (::ast expr)))
(assoc expr ::ast {::ast/type ::ast/pipeline
:exprs (conj exprs (::ast expr))})
)))))
(defn- parse-expr
([parser] (parse-expr parser sync-on))
([parser sync-on]
@ -584,6 +602,8 @@
::token/fn (parse-fn parser)
::token/do (parse-do parser)
;; TODO: improve handling of comments?
;; Scanner now just skips comments
;; ::token/comment (advance parser)
@ -606,13 +626,10 @@
(comment
(def pp pp/pprint)
(def source "
fn maybe_foo (mf) -> if eq (mf, :foo)
then (:ok, :foo)
else (:error, mf)
(def source "do foo
> bar
> baz
foo
")
(def lexed (scanner/scan source))
(def tokens (:tokens lexed))