[Haskell-cafe] "Dynamic" CSV Parsing - Parsec
Bernd Holzmüller
bernd.holzmueller at ics-ag.de
Fri May 7 02:38:11 EDT 2010
Hi Günther,
A simple method is to parameterize a parse function by something you
parsed previously.
For the example you gave, I would try something like this:
import ParseToken
cellContent = do ... -- parses the contents of a cell
cvsParser = do
headings <- sepBy identifier semi
cs <- count (length headings - 1) (do c <- cellContent; semi; return c)
c <- cellContent
return (cs ++ [c])
Of course, you can put the last two lines into a separate function that
is parameterized with the list of headings found.
(Instead of these lines, I would also define an abstraction function
sepByCount p n sep that parses n occurrences of p, each separated by sep.)
Best regards,
Bernd
Am 07.05.2010 00:40, schrieb Günther Schmidt:
> Hello,
>
> I'm trying to build a CSV parser that can dynamically assemble a
> parser from the values of the first line.
>
> As the most simple example the parse of the first line would return a
> parser with which subsequent lines would then be parsed.
> This parser would, for instance, only parse lines with the exact
> number of columns as found in the first line.
>
> Where I eventually want to go is a bit more complicated than this, but
> for now I'd be grateful for suggestions on how to go about the simple
> case.
>
> Best regards
>
> Günther
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list