[Haskell-cafe] Parsec and network data

brian brianchina60221 at gmail.com
Fri Aug 29 14:34:42 EDT 2008

On Fri, Aug 29, 2008 at 11:15 AM, Donn Cave <donn at avvanta.com> wrote:
> Quoth brian <brianchina60221 at gmail.com>:
> | I want to use Parsec to parse NNTP data coming to me from a handle I
> | get from connectTo.
> I would implement the network service
> input data stream myself, with timeouts

Could you explain a little about how this would look?

If it's reading characters trying to make a String we want to call a
'line', isn't that what the parser is supposed to be doing? If you
were parsing /etc/passwd, would you read each line yourself and give
each one to Parsec?

> So the parser would
> never see any streams or handles or anything, it would just get strings
> to parse.

Well, I think the parser still works with a Stream. For example,
Text/Parsec/ByteString.hs makes ByteString an instance of Stream.

My next try is to make this thing an instance of Stream:
data Connection = Connection
    { connectionHandle :: Handle
    , connectionData   :: C.ByteString

In uncons, the easy case is when connectionData is nonnull. If it is
null, hWaitForInput on the handle. If we get something, read it and
return appropriate stuff. If not, it's a parse error similar to
getting unexpected EOF in a file.

More information about the Haskell-Cafe mailing list