Improve and expose parse-script
This commit is contained in:
parent
4c186bae3a
commit
e890c44fbd
|
@ -260,13 +260,12 @@
|
||||||
(parse-expr parser))]
|
(parse-expr parser))]
|
||||||
(recur parsed exprs (::ast parsed)))))))
|
(recur parsed exprs (::ast parsed)))))))
|
||||||
|
|
||||||
(defn- parse-script [parser]
|
(defn parse-script [parser]
|
||||||
(loop [
|
(loop [
|
||||||
parser (accept-many #{::token/newline ::token/semicolon} parser)
|
parser (accept-many #{::token/newline ::token/semicolon} parser)
|
||||||
exprs []
|
exprs []
|
||||||
current_expr nil
|
current_expr nil
|
||||||
]
|
]
|
||||||
(let [curr (current parser)]
|
|
||||||
(case (token-type parser)
|
(case (token-type parser)
|
||||||
::token/eof (let [es (add-member exprs current_expr)]
|
::token/eof (let [es (add-member exprs current_expr)]
|
||||||
(if (empty? es)
|
(if (empty? es)
|
||||||
|
@ -285,7 +284,7 @@
|
||||||
(parse-expr parser)
|
(parse-expr parser)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
(recur parsed exprs (::ast parsed)))))))
|
(recur parsed exprs (::ast parsed))))))
|
||||||
|
|
||||||
(defn- parse-synthetic [parser]
|
(defn- parse-synthetic [parser]
|
||||||
(loop [parser parser
|
(loop [parser parser
|
||||||
|
@ -423,7 +422,7 @@
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
(def source "let quux = if {foo} then bar else baz")
|
(def source "nil")
|
||||||
(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))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user