[Haskell-beginners] parse block comments

Francesco Ariis fa-ml at ariis.it
Sat Mar 18 21:47:15 UTC 2017


On Sat, Mar 18, 2017 at 09:11:20PM +0000, mike h wrote:
> Hi,
> 
> Below is code I’m building up  for simple monadic and applicative parsers
> from first principles.

Hello Mike,
    You might want to check `manyTill` from Parsec to get an idea:

    manyTill :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
    manyTill p end      = scan
        where
              scan  = do { end; return [] } <|>
                      do { x <- p; xs <- scan; return (x:xs) }


The 'trick' lies in <|> (alternative). Does that help?


More information about the Beginners mailing list