[Haskell-cafe] Need help with learning Parsec
Christian.Maeder at dfki.de
Mon Jul 23 11:47:22 CEST 2012
Am 22.07.2012 17:21, schrieb C K Kashyap:
> I've updated the parser here -
> The whole thing is less than 100 lines and it can handle comments as well.
This code is still not nice: Duplicate code in openTag and
The "toplevel-try" in
try withoutExplictCloseTag <|> withExplicitCloseTag
should be avoided by factoring out the common prefix.
Again, I would avoid notFollowedBy by using many1.
tag <- try(char '<' >> many1 (letter <|> digit))
In quotedChar you do not only want to escape the quote but at least the
backslash, too. You could allow to escape any character by a backslash
quotedChar c =
try (char '\\' >> anyChar) <|> noneOf [c, '\\']
Writing a separate parser stripLeadingSpaces is overkill. Just use
"spaces >> parseXML"
(or apply "dropWhile isSpace" to the input string)
More information about the Haskell-Cafe