[Haskell-cafe] Need help with learning Parsec

Simon Hengel sol at typeful.net
Thu Jul 19 15:34:47 CEST 2012


On Thu, Jul 19, 2012 at 06:45:05PM +0530, Sai Hemanth K wrote:
> gettext =  (many1 $ noneOf "><") >>= (return . Body)

You can simplify this to:


    import Control.Applicative hiding ((<|>))

    gettext = Body <$> many1 (noneOf "><")


And some of your other parsers can be simplified as well:

    innerXML = xml <|> gettext

    openTag :: Parser String
    openTag = char '<' *> many (noneOf ">") <* char '>'

    endTag :: String -> Parser String
    endTag str = string "</" *> string str <* char '>'



More information about the Haskell-Cafe mailing list