Add list splats

This commit is contained in:
Scott Richmond 2022-05-20 17:35:16 -04:00
parent bb3d145e5d
commit 9d645e3b4b

View File

@ -225,6 +225,14 @@
::token/eof ::token/eof
(panic (assoc origin ::errors (::errors parser)) "Unterminated list" ::token/eof) (panic (assoc origin ::errors (::errors parser)) "Unterminated list" ::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/rbracket})] (let [parsed (parse-expr parser #{::token/comma ::token/newline ::token/rbracket})]
(recur parsed members (::ast parsed))))))) (recur parsed members (::ast parsed)))))))
@ -1018,11 +1026,9 @@
(parser) (parser)
(parse-script))) (parse-script)))
(comment (do
(def pp pp/pprint) (def pp pp/pprint)
(def source " (def source "[...:c]
let #{foo, :bar 23} = #{:foo 42, :bar 23}
") ")
(def lexed (scanner/scan source)) (def lexed (scanner/scan source))