Attoparsec was created specifically for streaming, thus its parsing functions take into account that some portion of the pattern may yet to have arrived and its combinators avoid taking input greedily unintentionally.

It is not clear to me that megaparsec is capable of that. There is a package attoparsec-parsec package, which reimplements parsec's combinators in a way attoparsec can use, but I do not see a version of that for megaparsec. You would have to write every megaparsec combinator into an equivalent attoparsec to create such a package.

On Mon, Jun 28, 2021 at 11:37 AM Dmitriy Matrosov <sgf.dma@gmail.com> wrote:
Hi.

I've used attoparsec before and it can return 'Partial' result containing
continuation, which is able to continue parsing if provided with more input.
E.g.

     > let A.Partial c1 = A.parse (A.string "mac address") "mac "; in c1 "address"
     Done "" "mac address"

Does the same thing possible with megaparsec?

After looking through library API, i haven't find a way to do this.
'runParser' (which seems the only way to run megaparsec parser) fails on
incomplete (text) input.

And if that's not possible, how should i deal with chunked input?
E.g. i read from a socket with 'recv' and i don't want to read all
data at once. How can i suspend parsing for a time, read next chunk and
continue?

Thanks.

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners