Instead of returning a `Producer` from your `Parser`, just consume the parsed stream directly using `toParser` or `toParser_` from `Pipes.Parse`:

toParser :: Monad m => Consumer (Maybe a) m r -> Parser a m r
    toParser_ :: Monad m => Consumer a m X -> Parser a m ()

For your code example specifically, you would probably want:

    zoom (Pipes.Parse.span (/= "end")) (toParser_ Pipes.Prelude.print)


On 7/30/14, 1:26 PM, David McBride wrote:
In a larger program I have to parse events, and one of the events has a start and end delimiter and then an unknown number of events in between. Sounds like a job for pipes-parse. Here's some stripped down code to show what I intended.

{-# LANGUAGE OverloadedStrings, LambdaCase  #-}

import Pipes
import Pipes.Parse
import Pipes.Prelude

import Data.Text

import Control.Monad.State.Strict

import Control.Lens

getnums :: (Functor m, Monad m) => Parser Text m (Producer Text m ())
getnums = do
  draw >>= \case
    (Just "start") -> do

      nums <- zoom (Pipes.Parse.span (/= "end")) $ do
        undefined  :: Parser Text m (Producer Text m ())

      void skip

      return nums
    _       -> undefined

testgetnums :: IO ()
testgetnums = do
(p,rest) <- runStateT getnums $ Pipes.each ["start","1","2","3","4","end","morestuff"]
  runEffect $ p >-> Pipes.Prelude.print
-- expected to print out roughly -> 1 2 3 4, with a rest producer that has morestuff in it.

My goal is to end up with a producer that produces the numbers, without the start or end events. I could just use drawAll and put its result into Pipes.each, but it seems like I should be able to use zoom (span (/= "end")) to get a parser that just has the numbers in it, and then somehow turn that into a producer that I can return.

Am I even taking the right approach to this? Or should I be turning to pipes group somehow? I tried that and felt like I didn't even get close to a solution.
--
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] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[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