aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-05-09 18:34:05 +0000
committerStuart Sierra <mail@stuartsierra.com>2009-05-09 18:34:05 +0000
commitde4df718178084ffe32d6a40b449892cd3d57d50 (patch)
tree52b8a985134c5743873ea40a494fc14f5a84c149
parent3d662f2faebe4757128e236f5238f68878806a6f (diff)
find_namespaces.clj: handle files where (comment...) precedes (ns...)
-rw-r--r--src/clojure/contrib/find_namespaces.clj21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/clojure/contrib/find_namespaces.clj b/src/clojure/contrib/find_namespaces.clj
index ded33f2a..174820d4 100644
--- a/src/clojure/contrib/find_namespaces.clj
+++ b/src/clojure/contrib/find_namespaces.clj
@@ -39,14 +39,27 @@
(sort-by #(.getAbsolutePath %)
(filter clojure-source-file? (file-seq dir))))
+(defn comment?
+ "Returns true if form is a (comment ...)"
+ [form]
+ (and (list? form) (= 'comment (first form))))
+
+(defn ns-decl?
+ "Returns true if form is a (ns ...) declaration."
+ [form]
+ (and (list? form) (= 'ns (first form))))
+
(defn read-ns-decl
"Attempts to read a (ns ...) declaration from rdr, and returns the
- unevaluated form. Returns nil if read fails, or if the first form
- is not a ns declaration."
+ unevaluated form. Returns nil if read fails or if a ns declaration
+ cannot be found. The ns declaration must be the first Clojure form
+ in the file, except for (comment ...) forms."
[#^PushbackReader rdr]
(try (let [form (read rdr)]
- (when (and (list? form) (= 'ns (first form)))
- form))
+ (cond
+ (ns-decl? form) form
+ (comment? form) (recur rdr)
+ :else nil))
(catch Exception e nil)))
(defn read-file-ns-decl