[Haskell-cafe] Re: Lazy parser with parsec.

Wagner Ferenc wferi at niif.hu
Mon Mar 26 15:20:21 EDT 2007

David Brown <haskell2 at davidb.org> writes:

> Does anyone know of any existing Parser parsers that don't consume
> their entire input, or am I probably best off making my own parser.

Thomas Zielonka published his Parsec combinator lazyMany on this list
a couple of times, Google for it.  Here is my application of his idea:

lazyMany :: Parser a -> SourceName -> String -> [a]
lazyMany    p           filename      contents = lm state0
    where Right state0 = parse getParserState filename contents -- get an initial state
          lm state = either (error . show) id (parse p' "" "")
              where p' = setParserState state >> choice [eof >> return [],
                                                         do x <- p
                                                            state' <- getParserState
                                                            return (x:lm state')]

More information about the Haskell-Cafe mailing list