[Haskell-cafe] Network parsing and parsec

John Goerzen jgoerzen at complete.org
Thu Sep 15 12:09:25 EDT 2005


The recent thread on binary parsing got me to thinking about more
general network protocol parsing with parsec.  A lot of network
protocols these days are text-oriented, so seem a good fit for parsec.

However, the difficulty I come up time and again is: parsec normally
expects to parse as much as possible at once.

With networking, you must be careful not to attempt to read more data
than the server hands back, or else you'll block.

I've had some success with hGetContents on a socket and feeding it into
extremely carefully-crafted parsers, but that is error-prone and ugly.

Here's the problem.  With a protocol such as IMAP, there is no way to
know until a server response is being parsed, how many lines (or bytes)
of data to read.  Ideally, I would be able to slrup in more data as I
go, but that doesn't seem to be very practical in Parsec either.


More information about the Haskell-Cafe mailing list