Prevent duplicate keys in struct/dict patterns
This commit is contained in:
parent
df511ce5eb
commit
80fe4d370d
|
@ -549,16 +549,22 @@
|
||||||
(let [curr (current parser)]
|
(let [curr (current parser)]
|
||||||
(case (token-type parser)
|
(case (token-type parser)
|
||||||
::token/rbrace
|
::token/rbrace
|
||||||
(let [ms (add-member members current_member)]
|
(let [current-key (first (keys current_member))]
|
||||||
(assoc (advance parser) ::ast
|
(if (current-key members)
|
||||||
{::ast/type ::ast/dict
|
(panic parser (str "Dict patterns may not duplicate keys: " current-key))
|
||||||
:token (current origin)
|
(let [ms (add-member members current_member)]
|
||||||
:members ms}))
|
(assoc (advance parser) ::ast
|
||||||
|
{::ast/type ::ast/dict
|
||||||
|
:token (current origin)
|
||||||
|
:members ms}))))
|
||||||
|
|
||||||
(::token/comma ::token/newline)
|
(::token/comma ::token/newline)
|
||||||
(recur
|
(let [current-key (first (keys current_member))]
|
||||||
(accept-many #{::token/comma ::token/newline} parser)
|
(if (current-key members)
|
||||||
(add-member members current_member) nil)
|
(panic parser (str "Dict patterns may not duplicate keys: " current-key))
|
||||||
|
(recur
|
||||||
|
(accept-many #{::token/comma ::token/newline} parser)
|
||||||
|
(add-member members current_member) nil)))
|
||||||
|
|
||||||
(::token/rbracket ::token/rparen)
|
(::token/rbracket ::token/rparen)
|
||||||
(panic parser (str "Mismatched enclosure in dict pattern: " (::token/lexeme curr)))
|
(panic parser (str "Mismatched enclosure in dict pattern: " (::token/lexeme curr)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user