Parsec Haskell Lists
Posted
by Martin
on Stack Overflow
See other posts from Stack Overflow
or by Martin
Published on 2010-04-24T17:14:29Z
Indexed on
2010/04/24
17:53 UTC
Read the original article
Hit count: 323
I'm using Text.ParserCombinators.Parsec and Text.XHtml to parse an input and get a HTML output.
If my input is:
* First item, First level ** First item, Second level ** Second item, Second level * Second item, First level
My output should be:
<ul><li>First item, First level <ul><li>First item, Second level </li><li>Second item, Second level </li></ul></li><li>Second item, First level</li></ul>
I wrote this, but obviously does not work recursively
list= do{ s <- many1 item;return (olist << s) }
item= do{
(count 1 (char '*'))
;s <- manyTill anyChar newline
;return ( li << s)
}
Any ideas? the recursion can be more than two levels
Thanks!
© Stack Overflow or respective owner