Created
May 18, 2017 00:57
-
-
Save Zetzumarshen/1ec8b45d7f82f3b6e4803f3383949055 to your computer and use it in GitHub Desktop.
CSV Parser using parsec/haskell
This file contains 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
import Text.ParserCombinators.Parsec | |
import System.IO | |
csvFile = endBy line eol | |
line = sepBy cell (char ',') | |
cell = many (noneOf ",\n") | |
eol = char '\n' | |
parseCSV :: String -> Either ParseError [[String]] | |
parseCSV input = parse csvFile "(unknown)" input | |
main = do | |
handle <- openFile "test.csv" ReadMode | |
contents <- hGetContents handle | |
case parseCSV contents of | |
Left x -> print x | |
Right results -> print results | |
hClose handle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment