Skip to content

Commit ef32778

Browse files
committed
CLJS-2887: Improve names in core macro specs
1 parent 5f0fabc commit ef32778

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

src/main/cljs/cljs/core/specs/alpha.cljc

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
(s/def ::local-name (s/and simple-symbol? #(not= '& %)))
1717

1818
(s/def ::binding-form
19-
(s/or :sym ::local-name
20-
:seq ::seq-binding-form
21-
:map ::map-binding-form))
19+
(s/or :local-symbol ::local-name
20+
:seq-destructure ::seq-binding-form
21+
:map-destructure ::map-binding-form))
2222

2323
;; sequential destructuring
2424

2525
(s/def ::seq-binding-form
2626
(s/and vector?
27-
(s/cat :elems (s/* ::binding-form)
28-
:rest (s/? (s/cat :amp #{'&} :form ::binding-form))
29-
:as (s/? (s/cat :as #{:as} :sym ::local-name)))))
27+
(s/cat :forms (s/* ::binding-form)
28+
:rest-forms (s/? (s/cat :ampersand #{'&} :form ::binding-form))
29+
:as-form (s/? (s/cat :as #{:as} :as-sym ::local-name)))))
3030

3131
;; map destructuring
3232

@@ -47,16 +47,21 @@
4747
(s/coll-of simple-symbol? :kind vector?)))
4848

4949
(s/def ::map-bindings
50-
(s/every (s/or :mb ::map-binding
51-
:nsk ::ns-keys
52-
:msb (s/tuple #{:as :or :keys :syms :strs} any?)) :kind map?))
50+
(s/every (s/or :map-binding ::map-binding
51+
:qualified-keys-or-syms ::ns-keys
52+
:special-binding (s/tuple #{:as :or :keys :syms :strs} any?)) :kind map?))
5353

5454
(s/def ::map-binding-form (s/merge ::map-bindings ::map-special-binding))
5555

5656
;; bindings
5757

58-
(s/def ::binding (s/cat :binding ::binding-form :init-expr any?))
59-
(s/def ::bindings (s/and vector? (s/* ::binding)))
58+
(defn even-number-of-forms?
59+
"Returns true if there are an even number of forms in a binding vector"
60+
[forms]
61+
(even? (count forms)))
62+
63+
(s/def ::binding (s/cat :form ::binding-form :init-expr any?))
64+
(s/def ::bindings (s/and vector? even-number-of-forms? (s/* ::binding)))
6065

6166
;; let, if-let, when-let
6267

@@ -75,25 +80,25 @@
7580

7681
;; defn, defn-, fn
7782

78-
(s/def ::arg-list
83+
(s/def ::param-list
7984
(s/and
8085
vector?
81-
(s/cat :args (s/* ::binding-form)
82-
:varargs (s/? (s/cat :amp #{'&} :form ::binding-form)))))
86+
(s/cat :params (s/* ::binding-form)
87+
:var-params (s/? (s/cat :ampersand #{'&} :var-form ::binding-form)))))
8388

84-
(s/def ::args+body
85-
(s/cat :args ::arg-list
89+
(s/def ::params+body
90+
(s/cat :params ::param-list
8691
:body (s/alt :prepost+body (s/cat :prepost map?
8792
:body (s/+ any?))
8893
:body (s/* any?))))
8994

9095
(s/def ::defn-args
91-
(s/cat :name simple-symbol?
96+
(s/cat :fn-name simple-symbol?
9297
:docstring (s/? string?)
9398
:meta (s/? map?)
94-
:bs (s/alt :arity-1 ::args+body
95-
:arity-n (s/cat :bodies (s/+ (s/spec ::args+body))
96-
:attr (s/? map?)))))
99+
:fn-tail (s/alt :arity-1 ::params+body
100+
:arity-n (s/cat :bodies (s/+ (s/spec ::params+body))
101+
:attr-map (s/? map?)))))
97102

98103
(s/fdef core/defn
99104
:args ::defn-args
@@ -104,9 +109,9 @@
104109
:ret any?)
105110

106111
(s/fdef core/fn
107-
:args (s/cat :name (s/? simple-symbol?)
108-
:bs (s/alt :arity-1 ::args+body
109-
:arity-n (s/+ (s/spec ::args+body))))
112+
:args (s/cat :fn-name (s/? simple-symbol?)
113+
:fn-tail (s/alt :arity-1 ::params+body
114+
:arity-n (s/+ (s/spec ::params+body))))
110115
:ret any?)
111116

112117
;;;; ns
@@ -118,7 +123,7 @@
118123

119124
(s/def ::ns-refer-clojure
120125
(s/spec (s/cat :clause #{:refer-clojure}
121-
:filters ::filters)))
126+
:refer-filters ::filters)))
122127

123128
(s/def ::refer (s/coll-of simple-symbol?))
124129
(s/def ::refer-macros (s/coll-of simple-symbol?))
@@ -150,7 +155,7 @@
150155
(s/def ::package-list
151156
(s/spec
152157
(s/cat :package simple-symbol?
153-
:classes (s/* simple-symbol?))))
158+
:classes (s/+ simple-symbol?))))
154159

155160
(s/def ::import-list
156161
(s/* (s/alt :class simple-symbol?
@@ -193,10 +198,10 @@
193198
:use-macros ::ns-use-macros)))
194199

195200
(s/def ::ns-form
196-
(s/cat :name simple-symbol?
201+
(s/cat :ns-name simple-symbol?
197202
:docstring (s/? string?)
198203
:attr-map (s/? map?)
199-
:clauses ::ns-clauses))
204+
:ns-clauses ::ns-clauses))
200205

201206
(s/fdef core/ns-special-form
202207
:args ::ns-form)

0 commit comments

Comments
 (0)