Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created January 28, 2012 19:39
Show Gist options
  • Select an option

  • Save amalloy/1695538 to your computer and use it in GitHub Desktop.

Select an option

Save amalloy/1695538 to your computer and use it in GitHub Desktop.
(defn ignore-comments [s]
(-> (reduce (fn [[state output] c]
(case state
:normal (if (= c \/)
[:after-slash output]
[:normal (str output c)])
:after-slash (case c
\* [:comment output]
\/ [:after-slash (str output "/")]
[:normal (str output "/" c) nil])
:comment (if (= c \*)
[:after-star output]
[:comment output])
:after-star (case c
\/ [:normal output]
\* [:after-star output]
[:comment output])))
[:normal "" nil]
s)
(second)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment