[Haskell-cafe] parsing exercise

Sebastian Fischer fischer at nii.ac.jp
Sun Jan 23 06:09:15 CET 2011


I need a function and wonder whether I can copy some existing code so I
don't have to write it myself.

It should split a string into a list of strings:

    splitAtTopLevelCommas :: String -> [String]

I need something similar to `splitOn ","` from the Text package with the

    intercalate "," . splitAtTopLevelCommas = id

But it should split the string only on a few commas, not all. You can think
of the result list as representations of Haskell values, for example

    splitAtTopLevelCommas "True,(1,(2,[3,4])),Just ('a',\")\")"

should yield

    ["True", "(1,(2,[3,4]))", "Just ('a',\")\")"]

I expect writing this function to be quite tedious (ignore commas in parens,
ignore parens in strings, quotation, ...) and would prefer to copy code from
some parsing library. Do you have an idea what I could use? Or how to solve
it from scratch in a few lines?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110123/085d3590/attachment.htm>

More information about the Haskell-Cafe mailing list