Created
December 19, 2013 05:13
-
-
Save jeffcarp/8034734 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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