Skip to content

Instantly share code, notes, and snippets.



Created Dec 19, 2013
What would you like to do?
(use '
(defn debug [expr str]
(println str expr)
(identity expr)))
(defn basic-comment? [str]
(not (empty? (re-seq #"^\s*\/\/" str))))
(defn starts-comment? [str]
(not (empty? (re-seq #"\/\*" str))))
(defn ends-comment? [str]
(not (empty? (re-seq #"\*\/" str))))
(defn block-comment? [is-comment str]
(and (not (ends-comment? str))) (or is-comment (starts-comment? str)))
(defn foo [num-lines raw-lines is-comment]
(let [line (first raw-lines)]
(if (empty? raw-lines)
(if (every? not ((juxt clojure.string/blank? basic-comment? (partial block-comment? is-comment)) line))
(foo (inc num-lines) (rest raw-lines) (debug (block-comment? is-comment line) "block-comment? line"))
(foo num-lines (rest raw-lines) (debug (block-comment? is-comment line) "block-comment? line"))))))
(with-open [rdr (reader "test1.txt")]
(foo 0 (line-seq rdr) false))
;(count (filter
; #(not (or (clojure.string/blank? %) (basic-comment? %)))
; (line-seq rdr))))
; "/\\*(?:.|[\\n\\r])*?\\*/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.