@@ -2153,7 +2153,7 @@ groupByRollingEither
21532153-- Right "string"
21542154--
21552155-- >>> Stream.parsePos (Parser.listEqBy (==) "mismatch") $ Stream.fromList "match"
2156- -- Left (ParseErrorPos 2 "listEqBy: mismatch occurred ")
2156+ -- Left (ParseErrorPos 2 "listEqBy: mismatch after matching 2 elements ")
21572157--
21582158{-# INLINE listEqBy #-}
21592159listEqBy :: Monad m => (a -> a -> Bool ) -> [a ] -> Parser a m [a ]
@@ -2196,33 +2196,37 @@ streamEqByInternal fname cmp (D.Stream sstep state) = Parser step initial extrac
21962196 initial = do
21972197 r <- sstep defState state
21982198 case r of
2199- D. Yield x s -> return $ IPartial (Just' x, s)
2199+ D. Yield x s -> return $ IPartial (Just' x, s, 0 )
22002200 D. Stop -> return $ IDone ()
22012201 -- Need Skip/Continue in initial to loop right here
2202- D. Skip s -> return $ IPartial (Nothing' , s)
2202+ D. Skip s -> return $ IPartial (Nothing' , s, 0 )
22032203
2204- step (Just' x, st) a =
2204+ step (Just' x, st, n ) a =
22052205 if x `cmp` a
22062206 then do
22072207 r <- sstep defState st
22082208 return
22092209 $ case r of
2210- D. Yield x1 s -> SContinue 1 (Just' x1, s)
2210+ D. Yield x1 s -> SContinue 1 (Just' x1, s, n + 1 )
22112211 D. Stop -> SDone 1 ()
2212- D. Skip s -> SContinue 0 (Nothing' , s)
2213- else return $ SError (fname ++ " : mismatch occurred" )
2214- step (Nothing' , st) a = do
2212+ D. Skip s -> SContinue 0 (Nothing' , s, n + 1 )
2213+ else return $ SError
2214+ (fname ++ " : mismatch after matching " ++ show n ++ " elements" )
2215+ step (Nothing' , st, n) a = do
22152216 r <- sstep defState st
22162217 return
22172218 $ case r of
22182219 D. Yield x s -> do
22192220 if x `cmp` a
2220- then SContinue 1 (Nothing' , s)
2221- else SError (fname ++ " : mismatch occurred" )
2221+ then SContinue 1 (Nothing' , s, n + 1 )
2222+ else SError
2223+ (fname ++ " : mismatch after matching "
2224+ ++ show n ++ " elements" )
22222225 D. Stop -> SDone 0 ()
2223- D. Skip s -> SContinue 0 (Nothing' , s)
2226+ D. Skip s -> SContinue 0 (Nothing' , s, n )
22242227
2225- extract _ = return $ FError (fname ++ " : end of input" )
2228+ extract (_, _, n) = return $ FError
2229+ (fname ++ " : end of input after matching " ++ show n ++ " elements" )
22262230
22272231-- | Like 'listEqBy' but uses a stream instead of a list and does not return
22282232-- the stream.
0 commit comments