[Haskell-cafe] Need help with learning Parsec

C K Kashyap ckkashyap at gmail.com
Mon Jul 23 12:09:00 CEST 2012


Thank you so much Christian for your feedback ... I shall incorporate them.

Regards,
Kashyap

On Mon, Jul 23, 2012 at 3:17 PM, Christian Maeder
<Christian.Maeder at dfki.de>wrote:

> Am 22.07.2012 17:21, schrieb C K Kashyap:
>
>  I've updated the parser here -
>> https://github.com/ckkashyap/**LearningPrograms/blob/master/**
>> Haskell/Parsing/xml_3.hs<https://github.com/ckkashyap/LearningPrograms/blob/master/Haskell/Parsing/xml_3.hs>
>>
>> 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
> withoutExplictCloseTag.
>
> 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
> using:
>   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)
>
> C.
>
> [...]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120723/d3bb0322/attachment.htm>


More information about the Haskell-Cafe mailing list