on master help sign in
Fix error messages in takeStartBy/takeEndByEsc
97bb9b9Harendra Kumar
core/src/Streamly/Internal/Data/Parser.hs+3−3
@@ -708,12 +708,12 @@ takeEitherSepBy _cond = undefined -- D.toParserK . D.takeEitherSepBy cond
708--
708--
709-- >>> p = Parser.takeStartBy (== ',') Fold.toList
709-- >>> p = Parser.takeStartBy (== ',') Fold.toList
710-- >>> leadingComma = Stream.parse p . Stream.fromList
710-- >>> leadingComma = Stream.parse p . Stream.fromList
711−-- >>> leadingComma "a,b,c,d"
711+-- >>> leadingComma "a,b"
712−-- *** Exception: takeStartBy : token begins with an element which fails the predicate
712+-- *** Exception: ParseError "takeStartBy: missing frame start"
713-- ...
713-- ...
714-- >>> leadingComma ",,"
714-- >>> leadingComma ",,"
715-- ","
715-- ","
716−-- >>> leadingComma ",a,b,c,d"
716+-- >>> leadingComma ",a,b"
717-- ",a"
717-- ",a"
718-- >>> leadingComma ""
718-- >>> leadingComma ""
719-- ""
719-- ""
core/src/Streamly/Internal/Data/Parser/ParserD.hs+6−7
@@ -723,7 +723,7 @@ takeEndByEsc isEsc isSep (Parser pstep pinitial pextract) =
723
723
724 extract (Left' s) = pextract s
724 extract (Left' s) = pextract s
725 extract (Right' _) =
725 extract (Right' _) =
726− throwM $ ParseError "takeEndByEsc: trailing escape, end of input"
726+ throwM $ ParseError "takeEndByEsc: trailing escape"
727
727
728-- | See 'Streamly.Internal.Data.Parser.takeEndBy_'.
728-- | See 'Streamly.Internal.Data.Parser.takeEndBy_'.
729--
729--
@@ -765,7 +765,7 @@ takeStartBy cond (Fold fstep finitial fextract) =
765 return $
765 return $
766 case res of
766 case res of
767 FL.Partial s -> IPartial (Left' s)
767 FL.Partial s -> IPartial (Left' s)
768− FL.Done _ -> IError "takeStartBy : bad finitial"
768+ FL.Done _ -> IError "takeStartBy: fold done without input"
769
769
770 {-# INLINE process #-}
770 {-# INLINE process #-}
771 process s a = do
771 process s a = do
@@ -778,8 +778,7 @@ takeStartBy cond (Fold fstep finitial fextract) =
778 step (Left' s) a =
778 step (Left' s) a =
779 if cond a
779 if cond a
780 then process s a
780 then process s a
781− else error $ "takeStartBy : token begins with an element which "
781+ else return $ Error "takeStartBy: missing frame start"
782− ++ "fails the predicate"
783 step (Right' s) a =
782 step (Right' s) a =
784 if not (cond a)
783 if not (cond a)
785 then process s a
784 then process s a
@@ -1342,7 +1341,7 @@ deintercalate
1342 where
1341 where
1343
1342
1344 errMsg p status =
1343 errMsg p status =
1345− error $ "sepBy: " ++ p ++ " parser cannot "
1344+ error $ "deintercalate: " ++ p ++ " parser cannot "
1346 ++ status ++ " without input"
1345 ++ status ++ " without input"
1347
1346
1348 initial = do
1347 initial = do
@@ -1392,7 +1391,7 @@ deintercalate
1392 IDone _ -> errMsg "left" "succeed"
1391 IDone _ -> errMsg "left" "succeed"
1393 IError _ -> errMsg "left" "fail"
1392 IError _ -> errMsg "left" "fail"
1394 FL.Done c -> return $ Done n c
1393 FL.Done c -> return $ Done n c
1395− else return $ Error "sepBy: infinite loop"
1394+ else error "deintercalate: infinite loop"
1396 Error err -> return $ Error err
1395 Error err -> return $ Error err
1397
1396
1398 extract (DeintercalateL fs sL) = do
1397 extract (DeintercalateL fs sL) = do
@@ -1469,7 +1468,7 @@ sepBy
1469 IPartial sp -> return $ Partial n $ SepByInit fs sp
1468 IPartial sp -> return $ Partial n $ SepByInit fs sp
1470 IDone _ -> errMsg "content" "succeed"
1469 IDone _ -> errMsg "content" "succeed"
1471 IError _ -> errMsg "content" "fail"
1470 IError _ -> errMsg "content" "fail"
1472− else return $ Error "sepBy: infinite loop"
1471+ else error "sepBy: infinite loop"
1473 Error err -> return $ Error err
1472 Error err -> return $ Error err
1474
1473
1475 extract (SepByInit fs sp) = do
1474 extract (SepByInit fs sp) = do