Created
November 23, 2021 17:28
-
-
Save borkdude/fb42d1997f6e79c445cf1ae213ac9e9f to your computer and use it in GitHub Desktop.
tools-namespace-lite: discover namespaces in pure clojure/bb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns tools-namespace-lite | |
(:require [clojure.java.io :as io])) | |
(defn source? [f] | |
(re-matches #".*\.clj[cs]?$" (str f))) | |
(defn source-files [dir] | |
(filter source? (file-seq (io/file dir)))) | |
(defn find-namespaces-in-file [f] | |
(binding [*reader-resolver* (reify clojure.lang.LispReader$Resolver | |
(resolveAlias [_ sym] sym) | |
(currentNS [_] 'foo)) | |
*default-data-reader-fn* (fn [_t v] v)] | |
(with-open [rdr (io/reader f) | |
rdr (java.io.PushbackReader. rdr) | |
rdr (clojure.lang.LineNumberingPushbackReader. rdr)] | |
(let [nss (->> | |
(repeatedly #(read {:eof ::eof | |
:read-cond :allow} rdr)) | |
(take-while #(not= ::eof %)) | |
(keep (fn [form] | |
(when (and (seq? form) | |
(= 'ns (first form))) | |
(second form)))))] | |
(vec nss))))) | |
(defn find-namespaces-in-dir [dir] | |
(let [sources (source-files dir)] | |
(mapcat find-namespaces-in-file sources))) | |
(find-namespaces-in-dir ".") | |
;; $ bb ~/Dropbox/temp/tools_namespace_lite.clj | |
;; (edamame.test-utils.macros edamame.test-utils.utils edamame.test-utils edamame.core-test doo.runner clojure.core.rrb-vector clojure.core.rrb-vector.interop clojure.core.rrb-vector.transients clojure.core.rrb-vector.protocols clojure.core.rrb-vector.nodes clojure.core.rrb-vector.trees clojure.core.rrb-vector.rrbt clojure.set clojure.walk clojure.string clojure.data clojure.edn edamame.impl.parser edamame.impl.macros edamame.impl.syntax-quote edamame.impl.read-fn edamame.test-utils.utils edamame.core edamame.test-utils edamame.core-test fipp.util fipp.edn fipp.deque fipp.ednize fipp.engine fipp.visit fipp.clojure cljs-test-runner.gen cljs-test-runner.gen cljs.nodejscli cljs.tools.reader.impl.commons cljs.tools.reader.impl.errors cljs.tools.reader.impl.inspect cljs.tools.reader.impl.utils cljs.tools.reader.reader-types cljs.tools.reader.edn cljs.tools.reader cljs.test cljs.pprint cljs.nodejs cljs.tagged-literals cljs.reader cljs.core jx.reporter.karma changelog clojure.core cljs.core edamame.impl.parser edamame.impl.macros edamame.impl.main edamame.impl.syntax-quote edamame.impl.read-fn edamame.core) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment