Skip to content
Prev Previous commit
Next Next commit
added csv example
  • Loading branch information
Jason Jackson committed Jun 4, 2011
commit 6d037f45286e44efd82b0b367fee883393be96b5
28 changes: 28 additions & 0 deletions doc/csv.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(ns csv
(:use
[eu.dnetlib.clojure.clarsec]
[eu.dnetlib.clojure.monad]))

;; Parsing simplified XML:
;;
;; Sample Input:

(def input
"Year,Make,Model,Length
1997,Ford,Model-350,234
2000,Mercury,\"Model 800\",238")

(def cell (<|> stringLiteral
(stringify (many (none-of ",\n")))))
(def line (sep-by cell comma))
(def csv (sep-by line eol))

(defn -main []
(prn (:value (parse csv input))))

;; Output:
;;
;; (("Year" "Make" "Model" "Length")
;; ("1997" "Ford" "Model-350" "234")
;; ("2000" "Mercury" "Model 800" "238"))