Add splats to tuple patterns in parser
This commit is contained in:
parent
24f85966a2
commit
07c21494cf
|
@ -625,11 +625,13 @@
|
||||||
(case (token-type parser)
|
(case (token-type parser)
|
||||||
::token/rparen
|
::token/rparen
|
||||||
(let [ms (add-member members current_member)]
|
(let [ms (add-member members current_member)]
|
||||||
|
(if (not-any? #(= (::ast/type %) ::ast/splat) (drop-last ms))
|
||||||
(assoc (advance parser) ::ast
|
(assoc (advance parser) ::ast
|
||||||
{::ast/type ::ast/tuple
|
{::ast/type ::ast/tuple
|
||||||
:token (current origin)
|
:token (current origin)
|
||||||
:length (count ms)
|
:length (count ms)
|
||||||
:members ms}))
|
:members ms})
|
||||||
|
(panic parser "A splat my only appear once in a tuple pattern, at the end of the pattern.")))
|
||||||
|
|
||||||
|
|
||||||
(::token/comma ::token/newline)
|
(::token/comma ::token/newline)
|
||||||
|
@ -643,6 +645,10 @@
|
||||||
::token/eof
|
::token/eof
|
||||||
(panic (assoc origin ::errors (::errors parser)) "Unterminated tuple" ::token/eof)
|
(panic (assoc origin ::errors (::errors parser)) "Unterminated tuple" ::token/eof)
|
||||||
|
|
||||||
|
::token/splat
|
||||||
|
(let [splatted (parse-splat-pattern parser)]
|
||||||
|
(recur splatted members (::ast splatted)))
|
||||||
|
|
||||||
(let [parsed (parse-pattern parser)]
|
(let [parsed (parse-pattern parser)]
|
||||||
(recur parsed members (::ast parsed)))))))
|
(recur parsed members (::ast parsed)))))))
|
||||||
|
|
||||||
|
@ -1107,7 +1113,7 @@
|
||||||
|
|
||||||
(do
|
(do
|
||||||
(def pp pp/pprint)
|
(def pp pp/pprint)
|
||||||
(def source "let [a, b, (c, d), ...e] = [1, 2, (4, 5), 6]")
|
(def source "let (a, ...b) = :foo")
|
||||||
|
|
||||||
(println "")
|
(println "")
|
||||||
(println "")
|
(println "")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user