on master help sign in
Fix error messages in takeStartBy/takeEndByEsc

In deintercalate and sepBy as well.

commit97bb9b9f2c55d55ed99367406b9a80d8be7c3a5b authorHarendra Kumar <harendra@composewell.com> dateMon 9 May 2022, 12:00 (4 years ago) parent501be5e
2 files changed+9−10
core/src/Streamly/Internal/Data/Parser.hs+3−3 core/src/Streamly/Internal/Data/Parser/ParserD.hs+6−7
core/src/Streamly/Internal/Data/Parser.hs+3−3
@@ -708,12 +708,12 @@ takeEitherSepBy _cond = undefined -- D.toParserK . D.takeEitherSepBy cond
708708--
709709-- >>> p = Parser.takeStartBy (== ',') Fold.toList
710710-- >>> leadingComma = Stream.parse p . Stream.fromList
711−-- >>> leadingComma "a,b,c,d"
712−-- *** Exception: takeStartBy : token begins with an element which fails the predicate
711+-- >>> leadingComma "a,b"
712+-- *** Exception: ParseError "takeStartBy: missing frame start"
713713-- ...
714714-- >>> leadingComma ",,"
715715-- ","
716−-- >>> leadingComma ",a,b,c,d"
716+-- >>> leadingComma ",a,b"
717717-- ",a"
718718-- >>> leadingComma ""
719719-- ""
core/src/Streamly/Internal/Data/Parser/ParserD.hs+6−7
@@ -723,7 +723,7 @@ takeEndByEsc isEsc isSep (Parser pstep pinitial pextract) =
723723
724724 extract (Left' s) = pextract s
725725 extract (Right' _) =
726− throwM $ ParseError "takeEndByEsc: trailing escape, end of input"
726+ throwM $ ParseError "takeEndByEsc: trailing escape"
727727
728728-- | See 'Streamly.Internal.Data.Parser.takeEndBy_'.
729729--
@@ -765,7 +765,7 @@ takeStartBy cond (Fold fstep finitial fextract) =
765765 return $
766766 case res of
767767 FL.Partial s -> IPartial (Left' s)
768− FL.Done _ -> IError "takeStartBy : bad finitial"
768+ FL.Done _ -> IError "takeStartBy: fold done without input"
769769
770770 {-# INLINE process #-}
771771 process s a = do
@@ -778,8 +778,7 @@ takeStartBy cond (Fold fstep finitial fextract) =
778778 step (Left' s) a =
779779 if cond a
780780 then process s a
781− else error $ "takeStartBy : token begins with an element which "
782− ++ "fails the predicate"
781+ else return $ Error "takeStartBy: missing frame start"
783782 step (Right' s) a =
784783 if not (cond a)
785784 then process s a
@@ -1342,7 +1341,7 @@ deintercalate
13421341 where
13431342
13441343 errMsg p status =
1345− error $ "sepBy: " ++ p ++ " parser cannot "
1344+ error $ "deintercalate: " ++ p ++ " parser cannot "
13461345 ++ status ++ " without input"
13471346
13481347 initial = do
@@ -1392,7 +1391,7 @@ deintercalate
13921391 IDone _ -> errMsg "left" "succeed"
13931392 IError _ -> errMsg "left" "fail"
13941393 FL.Done c -> return $ Done n c
1395− else return $ Error "sepBy: infinite loop"
1394+ else error "deintercalate: infinite loop"
13961395 Error err -> return $ Error err
13971396
13981397 extract (DeintercalateL fs sL) = do
@@ -1469,7 +1468,7 @@ sepBy
14691468 IPartial sp -> return $ Partial n $ SepByInit fs sp
14701469 IDone _ -> errMsg "content" "succeed"
14711470 IError _ -> errMsg "content" "fail"
1472− else return $ Error "sepBy: infinite loop"
1471+ else error "sepBy: infinite loop"
14731472 Error err -> return $ Error err
14741473
14751474 extract (SepByInit fs sp) = do