(defn parse-ns-excludes [env args]
(reduce
(fn [s [k & filters]]
(if (= k :refer-clojure)
(do
(when (seq (:excludes s))
(throw (error env "Only one :refer-clojure form is allowed per namespace definition")))
(let [valid-kws #{:exclude :rename}
xs
(loop [fs (seq filters)
ret {:excludes #{}
:renames {}}
err (not (even? (count filters)))]
(cond
(true? err)
(throw
(error env "Only [:refer-clojure :exclude (names)] and optionally `:rename {from to}` specs supported"))
(some? fs)
(let [kw (first fs)]
(if (valid-kws kw)
(let [refs (second fs)]
(cond
(not (or (and (= kw :exclude) (sequential? refs) (every? symbol? refs))
(and (= kw :rename) (map? refs) (every? #(every? symbol? %) refs))))
(recur fs ret true)
(= kw :exclude)
(recur (nnext fs) (update-in ret [:excludes] into refs) false)
(= kw :rename)
(recur (nnext fs) (update-in ret [:renames] merge refs) false)))
(recur fs ret true)))
:else ret))]
(merge-with into s xs)))
s))
{:excludes #{}
:renames {}} args))