Then, if you don't care about the leftovers and some limitations
handling errors, you could use the Attoparsec parser directly in your
pipe. You can see here something similar I did for `Binary` decoding
here:

https://github.com/jdnavarro/pipes-p2p/blob/master/src/Pipes/Network/P2P.hs#L297

You might want to wait for more people on the list to weight in on
this because I'm not sure that's idiomatic enough. It works for me,
but perhaps there are better ways.

BTW, this "pay for what you eat" approach is one of the things I like
most about `pipes`. You can start with simple vanilla `pipes` and
then, as needs arise, you upgrade to `pipes-parse`, `pipes-attoparsec`
or `pipes-safe`. With other lazy-IO alternatives you have to use the
full stack from the very beginning.


On Thu, Mar 13, 2014 at 10:48 PM, Kai Wang <[email protected]> wrote:
> Indeed, I don't care about the leftovers. Does this mean that my pipeline
> should look like this:
>
> myPipe :: Socket
>        -> Output Word8
>        -> Effect ErrorT ((ParsingError, Producer ByteString m ()) m) ()
> myPipe s o = loop >-> toOutput o
>   where
>     loop = forever $ (errorP . parsed myParser $ fromSocket s 4096)
>     myParser = undefined -- some attoparsec parser
>
> On Thursday, March 13, 2014 12:49:20 PM UTC-7, Danny Navarro wrote:
>>
>> Another thing to consider is whether you want to handle parsing errors
>> and the leftovers. If you just want the parsing pipe to terminate when
>> errors occur and you don't care about the leftovers when (or if) the
>> pipe is done parsing, you may not need `pipes-parse` at all, and could
>> get away just using `pipes` and `pipes-concurrency`.
>>
>> On Thu, Mar 13, 2014 at 8:02 PM, Renzo Carbonara <[email protected]>
>> wrote:
>> > On Thu, Mar 13, 2014 at 3:41 PM, Kai Wang <[email protected]> wrote:
>> >> Hi:
>> >>
>> >> Suppose I have a Bytestring producer, I want to use
>> >> pipes-attoparsec/binary/etc to parse this producer, and send the result
>> >> to a
>> >> pipes-concurrent output mailbox. What's the idiomatic to achieve this
>> >> result? Is using "parse :: A.Parser a b -> P.Parser a m (Either
>> >> ParsingError
>> >> b)" (from pipes-attoparsec) the correct approach for this situation? or
>> >> should I stick with "parsed :: A.Parser a b -> P.Producer a m r ->
>> >> P.Producer b m (Either (ParsingError P.Producer a m r) r)" (also from
>> >> pipes-attoparsec)
>> >
>> > Kai,
>> >
>> >
>> > It depends on the contents of your original `ByteString` producer and
>> > on how you want to deal with parsing errors.
>> >
>> > If your original `ByteString` producer contains consecutive raw
>> > entries that can be parsed with nothing else in between them, then
>> > `Pipes.Attoparsec.parsed` will work; you'll just have to take care of
>> > matching the `Either (ParsingError, Producer a m r) r` return type
>> > from this new producer with the other `Proxy`s in your pipeline. For
>> > example, `pipes-concurrency`'s `toOutput`'s return value is
>> > incompatible with said return type, but you could use
>> > `Pipes.Lift.errorP` to reconcile them.
>> >
>> > Otherwise, if your original `ByteString` producer contains additional
>> > content in between each raw entry or you want to deal with parsing
>> > errors locally, then you should rely on `Pipes.Attoparsec.parse` and
>> > the infrastructure provided by `pipes-parse.
>> >
>> >
>> > Regards,
>> >
>> > Renzo Carbonara.
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Haskell Pipes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an email to [email protected].
>> > To post to this group, send email to [email protected].
>
> --
> You received this message because you are subscribed to the Google Groups
> "Haskell Pipes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to