@@ -426,28 +426,33 @@ serialWith func (Parser stepL initialL extractL)
427 -- Note: For the composed parse to terminate, the left parser has to be
427 -- Note: For the composed parse to terminate, the left parser has to be
428 -- a terminating parser returning a Done at some point.
428 -- a terminating parser returning a Done at some point.
429− step (SeqParseL st) a =
429+ step (SeqParseL st) a = do
430− (\resL initR ->
430+ -- Important: Please do not use Applicative here. See
431+ -- https://github.com/composewell/streamly/issues/1033 and the problem
432+ -- defined in split_ for more info.
431 case resL of
434 case resL of
432 -- Note: We need to buffer the input for a possible Alternative
435 -- Note: We need to buffer the input for a possible Alternative
433 -- e.g. in ((,) <$> p1 <*> p2) <|> p3, if p2 fails we have to
436 -- e.g. in ((,) <$> p1 <*> p2) <|> p3, if p2 fails we have to
434 -- backtrack and start running p3. So we need to keep the input
437 -- backtrack and start running p3. So we need to keep the input
435 -- buffered until we know that the applicative cannot fail.
438 -- buffered until we know that the applicative cannot fail.
436− Partial n s -> Continue n (SeqParseL s)
439+ Partial n s -> return $ Continue n (SeqParseL s)
437− Continue n s -> Continue n (SeqParseL s)
440+ Continue n s -> return $ Continue n (SeqParseL s)
438− Done n b ->
441+ Done n b -> do
439− case initR of
443+ return $ case initR of
440 IPartial sr -> Continue n $ SeqParseR (func b) sr
444 IPartial sr -> Continue n $ SeqParseR (func b) sr
441 IDone br -> Done n (func b br)
445 IDone br -> Done n (func b br)
442 IError err -> Error err
446 IError err -> Error err
443− Error err -> Error err) <$> stepL st a <*> initialR
447+ Error err -> return $ Error err
445− step (SeqParseR f st) a =
449+ step (SeqParseR f st) a = do
446− (\case
451+ return $ case resR of
447 Partial n s -> Partial n (SeqParseR f s)
452 Partial n s -> Partial n (SeqParseR f s)
448 Continue n s -> Continue n (SeqParseR f s)
453 Continue n s -> Continue n (SeqParseR f s)
449 Done n b -> Done n (f b)
454 Done n b -> Done n (f b)
450− Error err -> Error err) <$> stepR st a
455+ Error err -> Error err
452 extract (SeqParseR f sR) = fmap f (extractR sR)
457 extract (SeqParseR f sR) = fmap f (extractR sR)
453 extract (SeqParseL sL) = do
458 extract (SeqParseL sL) = do
@@ -1147,4 +1152,3 @@ instance (MonadThrow m, MonadState s m) => MonadState s (Parser m a) where
1147instance (MonadThrow m, MonadIO m) => MonadIO (Parser m a) where
1152instance (MonadThrow m, MonadIO m) => MonadIO (Parser m a) where
1148 {-# INLINE liftIO #-}
1153 {-# INLINE liftIO #-}
1149 liftIO = fromEffect . liftIO
1154 liftIO = fromEffect . liftIO