[Haskell-cafe] parsing exercise
Alex Rozenshteyn
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.
http://book.realworldhaskell.org/read/using-parsec.html
On Sun, Jan 23, 2011 at 12:09 AM, Sebastian Fischer <fischer at nii.ac.jp>wrote:
> Hello,
>
> 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
> property
>
> 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?
>
> Sebastian
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
--
Alex R
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110123/c9ba91a4/attachment.htm>
More information about the Haskell-Cafe
mailing list