Parse do expressions/pipelines
This commit is contained in:
parent
174eb2d6a5
commit
89f813c2f3
|
@ -538,6 +538,24 @@
|
||||||
|
|
||||||
(panic parser "Expected name or clause after fn"))))
|
(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
|
(defn- parse-expr
|
||||||
([parser] (parse-expr parser sync-on))
|
([parser] (parse-expr parser sync-on))
|
||||||
([parser sync-on]
|
([parser sync-on]
|
||||||
|
@ -584,6 +602,8 @@
|
||||||
|
|
||||||
::token/fn (parse-fn parser)
|
::token/fn (parse-fn parser)
|
||||||
|
|
||||||
|
::token/do (parse-do parser)
|
||||||
|
|
||||||
;; TODO: improve handling of comments?
|
;; TODO: improve handling of comments?
|
||||||
;; Scanner now just skips comments
|
;; Scanner now just skips comments
|
||||||
;; ::token/comment (advance parser)
|
;; ::token/comment (advance parser)
|
||||||
|
@ -606,13 +626,10 @@
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
(def source "
|
(def source "do foo
|
||||||
|
> bar
|
||||||
fn maybe_foo (mf) -> if eq (mf, :foo)
|
> baz
|
||||||
then (:ok, :foo)
|
foo
|
||||||
else (:error, mf)
|
|
||||||
|
|
||||||
|
|
||||||
")
|
")
|
||||||
(def lexed (scanner/scan source))
|
(def lexed (scanner/scan source))
|
||||||
(def tokens (:tokens lexed))
|
(def tokens (:tokens lexed))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user