Skip to content

Commit 7fcd2df

Browse files
committed
CLJ-2960 Specs for checked keys
Signed-off-by: Alex Miller <alex.miller@cognitect.com>
1 parent 1e94df5 commit 7fcd2df

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/main/clojure/clojure/core/specs/alpha.clj

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,34 @@
2020

2121
;; map destructuring
2222

23-
(s/def ::keys (s/coll-of ident? :kind vector?))
24-
(s/def ::syms (s/coll-of symbol? :kind vector?))
25-
(s/def ::strs (s/coll-of simple-symbol? :kind vector?))
23+
(s/def ::non-binding-elements (s/cat :ampersand #{'&} ::non-binding-element (s/+ ident?)))
24+
(s/def ::keys-form (s/and vector? (s/cat :bindings (s/* ident?) :nonbinding (s/? ::non-binding-elements))))
25+
(s/def ::syms-form (s/and vector? (s/cat :bindings (s/* symbol?) :nonbinding (s/? ::non-binding-elements))))
26+
(s/def ::strs-form (s/and vector? (s/cat :bindings (s/* simple-symbol?) :nonbinding (s/? ::non-binding-elements))))
27+
28+
(s/def ::keys ::keys-form)
29+
(s/def ::syms ::syms-form)
30+
(s/def ::strs ::strs-form)
31+
(s/def ::keys! ::keys-form)
32+
(s/def ::syms! ::syms-form)
33+
(s/def ::strs! ::strs-form)
2634
(s/def ::or (s/map-of simple-symbol? any?))
2735
(s/def ::as ::local-name)
2836

2937
(s/def ::map-special-binding
30-
(s/keys :opt-un [::as ::or ::keys ::syms ::strs]))
38+
(s/keys :opt-un [::as ::or ::keys ::syms ::strs ::keys! ::syms! ::strs!]))
3139

3240
(s/def ::map-binding (s/tuple ::binding-form any?))
3341

3442
(s/def ::ns-keys
3543
(s/tuple
36-
(s/and qualified-keyword? #(-> % name #{"keys" "syms"}))
37-
(s/coll-of simple-symbol? :kind vector?)))
44+
(s/and qualified-keyword? #(-> % name #{"keys" "syms" "keys!" "syms!"}))
45+
::syms-form))
3846

3947
(s/def ::map-bindings
4048
(s/every (s/or :map-binding ::map-binding
4149
:qualified-keys-or-syms ::ns-keys
42-
:special-binding (s/tuple #{:as :or :keys :syms :strs} any?)) :kind map?))
50+
:special-binding (s/tuple #{:as :or :keys :syms :strs :keys! :syms! :strs!} any?)) :kind map?))
4351

4452
(s/def ::map-binding-form (s/merge ::map-bindings ::map-special-binding))
4553

0 commit comments

Comments
 (0)