|
16 | 16 | (s/def ::local-name (s/and simple-symbol? #(not= '& %)))
|
17 | 17 |
|
18 | 18 | (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)) |
22 | 22 |
|
23 | 23 | ;; sequential destructuring
|
24 | 24 |
|
25 | 25 | (s/def ::seq-binding-form
|
26 | 26 | (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))))) |
30 | 30 |
|
31 | 31 | ;; map destructuring
|
32 | 32 |
|
|
47 | 47 | (s/coll-of simple-symbol? :kind vector?)))
|
48 | 48 |
|
49 | 49 | (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?)) |
53 | 53 |
|
54 | 54 | (s/def ::map-binding-form (s/merge ::map-bindings ::map-special-binding))
|
55 | 55 |
|
56 | 56 | ;; bindings
|
57 | 57 |
|
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))) |
60 | 65 |
|
61 | 66 | ;; let, if-let, when-let
|
62 | 67 |
|
|
75 | 80 |
|
76 | 81 | ;; defn, defn-, fn
|
77 | 82 |
|
78 |
| -(s/def ::arg-list |
| 83 | +(s/def ::param-list |
79 | 84 | (s/and
|
80 | 85 | 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))))) |
83 | 88 |
|
84 |
| -(s/def ::args+body |
85 |
| - (s/cat :args ::arg-list |
| 89 | +(s/def ::params+body |
| 90 | + (s/cat :params ::param-list |
86 | 91 | :body (s/alt :prepost+body (s/cat :prepost map?
|
87 | 92 | :body (s/+ any?))
|
88 | 93 | :body (s/* any?))))
|
89 | 94 |
|
90 | 95 | (s/def ::defn-args
|
91 |
| - (s/cat :name simple-symbol? |
| 96 | + (s/cat :fn-name simple-symbol? |
92 | 97 | :docstring (s/? string?)
|
93 | 98 | :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?))))) |
97 | 102 |
|
98 | 103 | (s/fdef core/defn
|
99 | 104 | :args ::defn-args
|
|
104 | 109 | :ret any?)
|
105 | 110 |
|
106 | 111 | (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)))) |
110 | 115 | :ret any?)
|
111 | 116 |
|
112 | 117 | ;;;; ns
|
|
118 | 123 |
|
119 | 124 | (s/def ::ns-refer-clojure
|
120 | 125 | (s/spec (s/cat :clause #{:refer-clojure}
|
121 |
| - :filters ::filters))) |
| 126 | + :refer-filters ::filters))) |
122 | 127 |
|
123 | 128 | (s/def ::refer (s/coll-of simple-symbol?))
|
124 | 129 | (s/def ::refer-macros (s/coll-of simple-symbol?))
|
|
150 | 155 | (s/def ::package-list
|
151 | 156 | (s/spec
|
152 | 157 | (s/cat :package simple-symbol?
|
153 |
| - :classes (s/* simple-symbol?)))) |
| 158 | + :classes (s/+ simple-symbol?)))) |
154 | 159 |
|
155 | 160 | (s/def ::import-list
|
156 | 161 | (s/* (s/alt :class simple-symbol?
|
|
193 | 198 | :use-macros ::ns-use-macros)))
|
194 | 199 |
|
195 | 200 | (s/def ::ns-form
|
196 |
| - (s/cat :name simple-symbol? |
| 201 | + (s/cat :ns-name simple-symbol? |
197 | 202 | :docstring (s/? string?)
|
198 | 203 | :attr-map (s/? map?)
|
199 |
| - :clauses ::ns-clauses)) |
| 204 | + :ns-clauses ::ns-clauses)) |
200 | 205 |
|
201 | 206 | (s/fdef core/ns-special-form
|
202 | 207 | :args ::ns-form)
|
|
0 commit comments