[Haskell-cafe] parsing exercise
rpglover64 at gmail.com
Sun Jan 23 06:32:50 CET 2011
You might want to check out parsec, and the chapter related to it in RWH.
On Sun, Jan 23, 2011 at 12:09 AM, Sebastian Fischer <fischer at nii.ac.jp>wrote:
> 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?
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe