Parse splats in hashmaps and sets
This commit is contained in:
parent
7390461f2b
commit
ea5d9fa948
|
@ -259,6 +259,14 @@
|
||||||
::token/eof
|
::token/eof
|
||||||
(panic (assoc origin ::errors (::errors parser)) "Unterminated set" ::token/eof)
|
(panic (assoc origin ::errors (::errors parser)) "Unterminated set" ::token/eof)
|
||||||
|
|
||||||
|
::token/splat
|
||||||
|
(let [splatted (parse-expr (advance parser))
|
||||||
|
splat-type (node-type splatted)]
|
||||||
|
(if (contains? #{::ast/word ::ast/synthetic} splat-type)
|
||||||
|
(recur splatted members {::ast/type ::ast/splat
|
||||||
|
:token curr :expr (::ast splatted)})
|
||||||
|
(panic parser "You may only splat words and synthetic expressions")))
|
||||||
|
|
||||||
(let [parsed (parse-expr parser #{::token/comma ::token/newline ::token/rbrace})]
|
(let [parsed (parse-expr parser #{::token/comma ::token/newline ::token/rbrace})]
|
||||||
(recur parsed members (::ast parsed)))))))
|
(recur parsed members (::ast parsed)))))))
|
||||||
|
|
||||||
|
@ -295,6 +303,14 @@
|
||||||
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
(recur expr members {(:value (::ast kw)) (::ast expr)}))
|
||||||
(panic parser "Hashmap entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
(panic parser "Hashmap entries must be single words or keyword+expression pairs." #{::token/rbrace}))
|
||||||
|
|
||||||
|
::token/splat
|
||||||
|
(let [splatted (parse-expr (advance parser))
|
||||||
|
splat-type (node-type splatted)]
|
||||||
|
(if (contains? #{::ast/word ::ast/synthetic} splat-type)
|
||||||
|
(recur splatted members {::ast/type ::ast/splat
|
||||||
|
:token curr :expr (::ast splatted)})
|
||||||
|
(panic parser "You may only splat words and synthetic expressions")))
|
||||||
|
|
||||||
(panic parser "Hashmap entries must be single words or keyword+expression pairs" #{::token/rbrace})))))
|
(panic parser "Hashmap entries must be single words or keyword+expression pairs" #{::token/rbrace})))))
|
||||||
|
|
||||||
(defn- parse-struct [origin]
|
(defn- parse-struct [origin]
|
||||||
|
@ -1026,9 +1042,10 @@
|
||||||
(parser)
|
(parser)
|
||||||
(parse-script)))
|
(parse-script)))
|
||||||
|
|
||||||
(do
|
(comment
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
(def source "[...:c]
|
(def source "${a, b, ...c, d, ...e}
|
||||||
|
#{:a b,...d, :e f, ...g}
|
||||||
|
|
||||||
")
|
")
|
||||||
(def lexed (scanner/scan source))
|
(def lexed (scanner/scan source))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user