
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
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Alex R