parseItem :: Parser String
parseItem = do
manyTill anyChar $
(try $ lookAhead $ string "\n *") <|>
(try $ string "\n\n")
parseText :: Parser [String]
parseText =
string "\n *" >> -- remove this if text *can't* contain a leading '\n *'
sepBy1 parseItem (string "\n *")
I removed the HTML stuff because for whatever reason I couldn't get blaze-html
to install on my machine. But in principle it should be essentially the same thing. This parses strings delimited by the string "\n *" and ended by the string "\n\n". I don't know if have a leading \n
is what you want but that is easy to fix.
Also, I don't know if the empty string is valid. You should change sepBy1
to sepBy
if it is.
As for the error you were getting: you have string ""
inside of many
. Not only does this give the error you got, it doesn't make any sense! The parser string ""
will always succeed without consuming anything, since the empty string is a prefix of all strings and "" ++ x == x
. If you try to do this multiple times then you will never finish parsing.
Besides all that, your parseList
should parse your language. It essentially does the same thing that sepBy
does. I just think sepBy
is cleaner :)