Skip to content

Instantly share code, notes, and snippets.

@jeffcarp
Created December 19, 2013 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffcarp/8034734 to your computer and use it in GitHub Desktop.
Save jeffcarp/8034734 to your computer and use it in GitHub Desktop.
(use 'clojure.java.io)
(defn debug [expr str]
(do
(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)
num-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