Move ns & import to parse-script

This commit is contained in:
Scott Richmond 2022-08-04 16:54:13 -04:00
parent 969c321ffb
commit 5300ca5e3b

View File

@ -440,30 +440,7 @@
(parse-expr parser))] (parse-expr parser))]
(recur parsed exprs (::ast parsed))))))) (recur parsed exprs (::ast parsed)))))))
(defn parse-script [origin]
(loop [parser (accept-many #{::token/newline ::token/semicolon} origin)
exprs []
current_expr nil]
(case (token-type parser)
::token/eof
(let [es (add-member exprs current_expr)]
(if (empty? es)
(panic parser "Scripts must have at least one expression")
(assoc parser ::ast {::ast/type ::ast/script
:token (current origin) :exprs es})))
(::token/semicolon ::token/newline)
(recur
(accept-many #{::token/semicolon ::token/newline} parser)
(add-member exprs current_expr)
nil)
(let [parsed
(if current_expr
(panic parser "Expected end of expression" #{::token/semicolon ::token/newline})
(parse-expr parser))]
(recur parsed exprs (::ast parsed))))))
(defn- parse-synthetic [parser] (defn- parse-synthetic [parser]
(loop [parser parser (loop [parser parser
@ -1064,6 +1041,34 @@
:clauses (get-in clauses [::ast :clauses])})) :clauses (get-in clauses [::ast :clauses])}))
(panic parser "Expected { after receive")))) (panic parser "Expected { after receive"))))
(defn parse-script [origin]
(loop [parser (accept-many #{::token/newline ::token/semicolon} origin)
exprs []
current_expr nil]
(case (token-type parser)
::token/eof
(let [es (add-member exprs current_expr)]
(if (empty? es)
(panic parser "Scripts must have at least one expression")
(assoc parser ::ast {::ast/type ::ast/script
:token (current origin) :exprs es})))
::token/ns (parse-ns parser)
::token/import (parse-import parser)
(::token/semicolon ::token/newline)
(recur
(accept-many #{::token/semicolon ::token/newline} parser)
(add-member exprs current_expr)
nil)
(let [parsed
(if current_expr
(panic parser "Expected end of expression" #{::token/semicolon ::token/newline})
(parse-expr parser))]
(recur parsed exprs (::ast parsed))))))
(defn- parse-expr (defn- parse-expr
([parser] (parse-expr parser sync-on)) ([parser] (parse-expr parser sync-on))
([parser sync-on] ([parser sync-on]
@ -1120,10 +1125,6 @@
::token/cond (parse-cond parser) ::token/cond (parse-cond parser)
::token/ns (parse-ns parser)
::token/import (parse-import parser)
::token/ref (parse-ref parser) ::token/ref (parse-ref parser)
::token/loop (parse-loop parser) ::token/loop (parse-loop parser)