display cleaned, ready to split into multiple files

This commit is contained in:
IGI-111
2015-04-03 18:03:07 +02:00
parent e66fad749f
commit 46430779b3
3 changed files with 66 additions and 9 deletions

39
CSVParser.hs Normal file
View File

@@ -0,0 +1,39 @@
module CSVParser (
parseCSV
)where
import Text.ParserCombinators.Parsec
csvFile :: GenParser Char st [[String]]
csvFile = do
result <- many line
eof
return result
line :: GenParser Char st [String]
line = do
result <- cells
_ <- eol
return result
cells :: GenParser Char st [String]
cells = do
first <- cellContent
next <- remainingCells
return (first : next)
remainingCells :: GenParser Char st [String]
remainingCells =
(char ',' >> cells) -- Found comma? More cells coming
<|> return [] -- No comma? Return [], no more cells
cellContent :: GenParser Char st String
cellContent =
many (noneOf ",\n")
eol :: GenParser Char st Char
eol = char '\n'
parseCSV :: String -> Either ParseError [[String]]
parseCSV input = parse csvFile "(unknown)" input