on master help sign in
Rename slicesepby to slicesepbyP, some formatting changes
86745a7Anurag Hooda
benchmark/Streamly/Benchmark/Data/Parser.hs+4−5
@@ -161,11 +161,10 @@ split_ value =
161 (PR.drainWhile (<= value))
161 (PR.drainWhile (<= value))
162 )
162 )
163
163
164−{-# INLINE sliceSepBy #-}
164+{-# INLINE sliceSepByP #-}
165−sliceSepBy :: MonadCatch m
165+sliceSepByP :: MonadCatch m
166 => Int -> SerialT m Int -> m()
166 => Int -> SerialT m Int -> m()
167−sliceSepBy value = IP.parse (PR.sliceSepBy (>= value) (PR.many FL.drain
167+sliceSepByP value = IP.parse (PR.sliceSepByP (>= value) (PR.fromFold FL.drain))
168− (PR.satisfy (const True))))
169
168
170{-# INLINE teeAllAny #-}
169{-# INLINE teeAllAny #-}
171teeAllAny :: MonadCatch m
170teeAllAny :: MonadCatch m
@@ -287,7 +286,7 @@ o_1_space_serial value =
287 , benchIOSink value "splitApBefore" $ splitApBefore value
286 , benchIOSink value "splitApBefore" $ splitApBefore value
288 , benchIOSink value "splitApAfter" $ splitApAfter value
287 , benchIOSink value "splitApAfter" $ splitApAfter value
289 , benchIOSink value "splitWith" $ splitWith value
288 , benchIOSink value "splitWith" $ splitWith value
290− , benchIOSink value "sliceSepBy" $ sliceSepBy value
289+ , benchIOSink value "sliceSepByP" $ sliceSepByP value
291 , benchIOSink value "many" many
290 , benchIOSink value "many" many
292 , benchIOSink value "many (wordBy even)" $ manyWordByEven
291 , benchIOSink value "many (wordBy even)" $ manyWordByEven
293 , benchIOSink value "some" some
292 , benchIOSink value "some" some
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+5−5
@@ -100,10 +100,10 @@ someAlt xs = do
100 x <- IP.parseD (AP.some (PR.satisfy (> 0))) xs
100 x <- IP.parseD (AP.some (PR.satisfy (> 0))) xs
101 return $ Prelude.length x
101 return $ Prelude.length x
102
102
103−{-#INLINE sliceSepBy #-}
103+{-#INLINE sliceSepByP #-}
104−sliceSepBy :: MonadCatch m => Int -> SerialT m Int -> m ()
104+sliceSepByP :: MonadCatch m => Int -> SerialT m Int -> m ()
105−sliceSepBy value = IP.parseD (PR.sliceSepBy (>= value) (PR.many FL.drain
105+sliceSepByP value = IP.parseD (PR.sliceSepByP (>= value) (PR.fromFold FL.drain))
106− (PR.satisfy (const True))))
106+
107{-# INLINE manyTill #-}
107{-# INLINE manyTill #-}
108manyTill :: MonadCatch m => Int -> SerialT m Int -> m Int
108manyTill :: MonadCatch m => Int -> SerialT m Int -> m Int
109manyTill value =
109manyTill value =
@@ -218,7 +218,7 @@ o_1_space_serial value =
218 , benchIOSink value "many" many
218 , benchIOSink value "many" many
219 , benchIOSink value "many (wordBy even)" $ manyWordByEven
219 , benchIOSink value "many (wordBy even)" $ manyWordByEven
220 , benchIOSink value "some" some
220 , benchIOSink value "some" some
221− , benchIOSink value "sliceSepBy" $ sliceSepBy value
221+ , benchIOSink value "sliceSepByP" $ sliceSepByP value
222 , benchIOSink value "manyTill" $ manyTill value
222 , benchIOSink value "manyTill" $ manyTill value
223 , benchIOSink value "tee (all,any)" $ teeAllAny value
223 , benchIOSink value "tee (all,any)" $ teeAllAny value
224 , benchIOSink value "teeFst (all,any)" $ teeFstAllAny value
224 , benchIOSink value "teeFst (all,any)" $ teeFstAllAny value
src/Streamly/Internal/Data/Parser.hs+7−7
@@ -85,7 +85,7 @@ module Streamly.Internal.Data.Parser
85 , takeWhile1
85 , takeWhile1
86 , drainWhile
86 , drainWhile
87
87
88− , sliceSepBy
88+ , sliceSepByP
89 , sliceBeginWith
89 , sliceBeginWith
90 , sliceSepWith
90 , sliceSepWith
91 , escapedSliceSepBy
91 , escapedSliceSepBy
@@ -476,24 +476,24 @@ takeWhile1 cond = K.toParserK . D.takeWhile1 cond
476drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
476drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
477drainWhile p = takeWhile p FL.drain
477drainWhile p = takeWhile p FL.drain
478
478
479−-- | @sliceSepBy cond parser@ parses a slice of the input using @parser@ until
479+-- | @sliceSepByP cond parser@ parses a slice of the input using @parser@ until
480-- @cond@ succeeds or the parser stops.
480-- @cond@ succeeds or the parser stops.
481--
481--
482-- This is a generalized slicing parser which can be used to implement other
482-- This is a generalized slicing parser which can be used to implement other
483-- parsers e.g.:
483-- parsers e.g.:
484--
484--
485-- @
485-- @
486−-- sliceSepByMax cond n p = sliceBy cond (take n p)
486+-- sliceSepByMax cond n p = sliceSepByP cond (take n p)
487−-- sliceSepByBetween cond m n p = sliceBy cond (takeBetween m n p)
487+-- sliceSepByBetween cond m n p = sliceSepByP cond (takeBetween m n p)
488-- @
488-- @
489--
489--
490-- /Internal/
490-- /Internal/
491--
491--
492−{-# INLINABLE sliceSepBy #-}
492+{-# INLINABLE sliceSepByP #-}
493−sliceSepBy ::
493+sliceSepByP ::
494 MonadCatch m =>
494 MonadCatch m =>
495 (a -> Bool) -> Parser m a b -> Parser m a b
495 (a -> Bool) -> Parser m a b -> Parser m a b
496−sliceSepBy cond = K.toParserK . D.sliceSepBy cond . K.fromParserK
496+sliceSepByP cond = K.toParserK . D.sliceSepByP cond . K.fromParserK
497
497
498-- | Like 'sliceSepBy' but does not drop the separator element, instead
498-- | Like 'sliceSepBy' but does not drop the separator element, instead
499-- separator is emitted as a separate element in the output.
499-- separator is emitted as a separate element in the output.
src/Streamly/Internal/Data/Parser/ParserD.hs+4−4
@@ -53,7 +53,7 @@ module Streamly.Internal.Data.Parser.ParserD
53 , lookAhead
53 , lookAhead
54 , takeWhile
54 , takeWhile
55 , takeWhile1
55 , takeWhile1
56− , sliceSepBy
56+ , sliceSepByP
57 -- , sliceSepByBetween
57 -- , sliceSepByBetween
58 , sliceBeginWith
58 , sliceBeginWith
59 -- , sliceSepWith
59 -- , sliceSepWith
@@ -483,13 +483,13 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
483 extract Nothing = throwM $ ParseError "takeWhile1: end of input"
483 extract Nothing = throwM $ ParseError "takeWhile1: end of input"
484 extract (Just s) = fextract s
484 extract (Just s) = fextract s
485
485
486−-- | See 'Streamly.Internal.Data.Parser.sliceSepBy'.
486+-- | See 'Streamly.Internal.Data.Parser.sliceSepByP'.
487--
487--
488-- /Internal/
488-- /Internal/
489--
489--
490−sliceSepBy :: MonadCatch m =>
490+sliceSepByP :: MonadCatch m =>
491 (a -> Bool) -> Parser m a b -> Parser m a b
491 (a -> Bool) -> Parser m a b -> Parser m a b
492−sliceSepBy cond (Parser pstep pinitial pextract) =
492+sliceSepByP cond (Parser pstep pinitial pextract) =
493
493
494 Parser step initial pextract
494 Parser step initial pextract
495
495
test/Streamly/Test/Data/Parser.hs+8−6
@@ -311,16 +311,18 @@ takeProperties =
311-- where
311-- where
312-- list_length = Prelude.length ls
312-- list_length = Prelude.length ls
313
313
314−sliceSepBy :: Property
314+sliceSepByP :: Property
315−sliceSepBy =
315+sliceSepByP =
316 forAll (listOf (chooseInt (min_value, max_value ))) $ \ls ->
316 forAll (listOf (chooseInt (min_value, max_value ))) $ \ls ->
317− case S.parse (P.sliceSepBy predicate prsr) (S.fromList ls) of
317+ case S.parse (P.sliceSepByP predicate prsr) (S.fromList ls) of
318+ Right parsed_list ->
318− Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile
319+ checkListEqual parsed_list (tkwhl ls)
319− (not. predicate) ls)
320 Left _ -> property False
320 Left _ -> property False
321 where
321 where
322 predicate = (>= 100)
322 predicate = (>= 100)
323 prsr = P.many FL.toList (P.satisfy (const True))
323 prsr = P.many FL.toList (P.satisfy (const True))
324+ tkwhl ls = Prelude.takeWhile (not . predicate) ls
325+
324
326
325takeWhile :: Property
327takeWhile :: Property
326takeWhile =
328takeWhile =
@@ -704,7 +706,7 @@ main =
704 -- prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
706 -- prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
705 -- prop "Fail when stream length exceeded" lookAheadFail
707 -- prop "Fail when stream length exceeded" lookAheadFail
706 -- prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
708 -- prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n, else fail" lookAhead
707− prop "P.sliceSepBy test" Main.sliceSepBy
709+ prop "P.sliceSepByP test" Main.sliceSepByP
708 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
710 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
709 prop ("P.takeWhile1 = Prelude.takeWhile if taken something,"
711 prop ("P.takeWhile1 = Prelude.takeWhile if taken something,"
710 ++ " else check why failed") takeWhile1
712 ++ " else check why failed") takeWhile1
test/Streamly/Test/Data/Parser/ParserD.hs−13
@@ -335,18 +335,6 @@ groupBy =
335 | null lst = []
335 | null lst = []
336 | otherwise = head $ List.groupBy cmp lst
336 | otherwise = head $ List.groupBy cmp lst
337
337
338−sliceSepBy :: Property
339−sliceSepBy =
340− forAll (listOf (chooseInt (min_value, max_value ))) $ \ls ->
341− case S.parseD (P.sliceSepBy predicate prsr) (S.fromList ls) of
342− Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile
343− (not. predicate) ls)
344− Left _ -> property False
345− where
346− predicate = (>= 100)
347− prsr = P.many FL.toList (P.satisfy (const True))
348−
349−
350sliceSepByMax :: Property
338sliceSepByMax :: Property
351sliceSepByMax =
339sliceSepByMax =
352 forAll (chooseInt (min_value, max_value)) $ \n ->
340 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -710,7 +698,6 @@ main =
710 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
698 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
711 prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
699 prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
712 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
700 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
713− prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
714 prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
701 prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
715 prop "many (P.wordBy ' ') = words'" wordBy
702 prop "many (P.wordBy ' ') = words'" wordBy
716 prop "parse 0, then 1, else fail" splitWith
703 prop "parse 0, then 1, else fail" splitWith