Permalink
Browse files

Merge pull request #2 from Wonko7/master

Add clojurescript support
  • Loading branch information...
2 parents 8ca1006 + 4cda045 commit 631e47174c000dcfa0bdd83ff741c37eb66ae156 Joe Yates committed Jan 14, 2014
Showing with 27 additions and 21 deletions.
  1. +14 −12 src/sloccount/files.clj
  2. +13 −9 src/sloccount/line_types.clj
@@ -30,6 +30,7 @@
;; File type inference
(defn clojure-file-name? [filename] (.endsWith filename ".clj"))
+(defn clojurescript-file-name? [filename] (.endsWith filename ".cljs"))
(defn css-file-name? [filename] (.endsWith filename ".css"))
(defn html-file-name? [filename] (re-find #"\.html?$" filename))
(defn javascript-file-name? [filename] (.endsWith filename ".js"))
@@ -68,19 +69,20 @@
(defn file-type [file]
(let [filename (.toString file)]
(or
- (and (clojure-file-name? filename) :clojure)
- (and (css-file-name? filename) :css)
- (and (html-file-name? filename) :html)
- (and (javascript-file-name? filename) :javascript)
- (and (mason-html-file-name? filename) :mason-html)
+ (and (clojure-file-name? filename) :clojure)
+ (and (clojurescript-file-name? filename) :clojurescript)
+ (and (css-file-name? filename) :css)
+ (and (html-file-name? filename) :html)
+ (and (javascript-file-name? filename) :javascript)
+ (and (mason-html-file-name? filename) :mason-html)
(and (mason-javascript-file-name? filename) :mason-javascript)
- (and (perl-file-name? filename) :perl)
- (and (ruby-file-name? filename) :ruby)
- (and (sql-file-name? filename) :sql)
- (and (text-file-name? filename) :text)
- (and (xml-file-name? filename) :xml)
- (and (yaml-file-name? filename) :yaml)
- (and (file-empty? file) :empty)
+ (and (perl-file-name? filename) :perl)
+ (and (ruby-file-name? filename) :ruby)
+ (and (sql-file-name? filename) :sql)
+ (and (text-file-name? filename) :text)
+ (and (xml-file-name? filename) :xml)
+ (and (yaml-file-name? filename) :yaml)
+ (and (file-empty? file) :empty)
(file-type-from-contents file))))
(defn files-of-type [path type]
@@ -37,16 +37,20 @@
;; line-types Returns a seq of keywords indicating line types
(defmulti line-types sloccount.files/file-type :default :text)
-(defmethod line-types :clojure [file]
+(defn clojure-file-parse [file clojure-dialect]
(with-open [rdr (reader file)]
- (map
- (fn [line]
- (cond
- (blank? line) :blank
- (.startsWith line "#!/") :shebang
- (.startsWith line ";") :comment
- true :clojure))
- (doall (line-seq rdr)))))
+ (map (fn [line]
+ (cond (blank? line) :blank
+ (.startsWith line "#!/") :shebang
+ (.startsWith line ";") :comment
+ :else clojure-dialect))
+ (-> rdr line-seq doall))))
+
+(defmethod line-types :clojure [file]
+ (clojure-file-parse file :clojure))
+
+(defmethod line-types :clojurescript [file]
+ (clojure-file-parse file :clojurescript))
(defmethod line-types :mason-html [file]
(let [state (atom :html)]

0 comments on commit 631e471

Please sign in to comment.