on master help sign in
Rename slicesepby to slicesepbyP, some formatting changes
commit86745a756d39c7764f93098304c13f59f0bbdb3d authorAnurag Hooda <anuraghooda@composewell.com> dateThu 14 Jan 2021, 18:34 (6 years ago) parent5ccf51d
6 files changed+28−40
benchmark/Streamly/Benchmark/Data/Parser.hs+4−5 benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+5−5 src/Streamly/Internal/Data/Parser.hs+7−7 src/Streamly/Internal/Data/Parser/ParserD.hs+4−4 test/Streamly/Test/Data/Parser.hs+8−6 test/Streamly/Test/Data/Parser/ParserD.hs−13
benchmark/Streamly/Benchmark/Data/Parser.hs+4−5
@@ -161,11 +161,10 @@ split_ value =
161161 (PR.drainWhile (<= value))
162162 )
163163
164−{-# INLINE sliceSepBy #-}
165−sliceSepBy :: MonadCatch m
164+{-# INLINE sliceSepByP #-}
165+sliceSepByP :: MonadCatch m
166166 => Int -> SerialT m Int -> m()
167−sliceSepBy value = IP.parse (PR.sliceSepBy (>= value) (PR.many FL.drain
168− (PR.satisfy (const True))))
167+sliceSepByP value = IP.parse (PR.sliceSepByP (>= value) (PR.fromFold FL.drain))
169168
170169{-# INLINE teeAllAny #-}
171170teeAllAny :: MonadCatch m
@@ -287,7 +286,7 @@ o_1_space_serial value =
287286 , benchIOSink value "splitApBefore" $ splitApBefore value
288287 , benchIOSink value "splitApAfter" $ splitApAfter value
289288 , benchIOSink value "splitWith" $ splitWith value
290− , benchIOSink value "sliceSepBy" $ sliceSepBy value
289+ , benchIOSink value "sliceSepByP" $ sliceSepByP value
291290 , benchIOSink value "many" many
292291 , benchIOSink value "many (wordBy even)" $ manyWordByEven
293292 , benchIOSink value "some" some
benchmark/Streamly/Benchmark/Data/Parser/ParserD.hs+5−5
@@ -100,10 +100,10 @@ someAlt xs = do
100100 x <- IP.parseD (AP.some (PR.satisfy (> 0))) xs
101101 return $ Prelude.length x
102102
103−{-#INLINE sliceSepBy #-}
104−sliceSepBy :: MonadCatch m => Int -> SerialT m Int -> m ()
105−sliceSepBy value = IP.parseD (PR.sliceSepBy (>= value) (PR.many FL.drain
106− (PR.satisfy (const True))))
103+{-#INLINE sliceSepByP #-}
104+sliceSepByP :: MonadCatch m => Int -> SerialT m Int -> m ()
105+sliceSepByP value = IP.parseD (PR.sliceSepByP (>= value) (PR.fromFold FL.drain))
106+
107107{-# INLINE manyTill #-}
108108manyTill :: MonadCatch m => Int -> SerialT m Int -> m Int
109109manyTill value =
@@ -218,7 +218,7 @@ o_1_space_serial value =
218218 , benchIOSink value "many" many
219219 , benchIOSink value "many (wordBy even)" $ manyWordByEven
220220 , benchIOSink value "some" some
221− , benchIOSink value "sliceSepBy" $ sliceSepBy value
221+ , benchIOSink value "sliceSepByP" $ sliceSepByP value
222222 , benchIOSink value "manyTill" $ manyTill value
223223 , benchIOSink value "tee (all,any)" $ teeAllAny value
224224 , benchIOSink value "teeFst (all,any)" $ teeFstAllAny value
src/Streamly/Internal/Data/Parser.hs+7−7
@@ -85,7 +85,7 @@ module Streamly.Internal.Data.Parser
8585 , takeWhile1
8686 , drainWhile
8787
88− , sliceSepBy
88+ , sliceSepByP
8989 , sliceBeginWith
9090 , sliceSepWith
9191 , escapedSliceSepBy
@@ -476,24 +476,24 @@ takeWhile1 cond = K.toParserK . D.takeWhile1 cond
476476drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
477477drainWhile p = takeWhile p FL.drain
478478
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
480480-- @cond@ succeeds or the parser stops.
481481--
482482-- This is a generalized slicing parser which can be used to implement other
483483-- parsers e.g.:
484484--
485485-- @
486−-- sliceSepByMax cond n p = sliceBy cond (take n p)
487−-- sliceSepByBetween cond m n p = sliceBy cond (takeBetween m n p)
486+-- sliceSepByMax cond n p = sliceSepByP cond (take n p)
487+-- sliceSepByBetween cond m n p = sliceSepByP cond (takeBetween m n p)
488488-- @
489489--
490490-- /Internal/
491491--
492−{-# INLINABLE sliceSepBy #-}
493−sliceSepBy ::
492+{-# INLINABLE sliceSepByP #-}
493+sliceSepByP ::
494494 MonadCatch m =>
495495 (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
497497
498498-- | Like 'sliceSepBy' but does not drop the separator element, instead
499499-- 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
5353 , lookAhead
5454 , takeWhile
5555 , takeWhile1
56− , sliceSepBy
56+ , sliceSepByP
5757 -- , sliceSepByBetween
5858 , sliceBeginWith
5959 -- , sliceSepWith
@@ -483,13 +483,13 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
483483 extract Nothing = throwM $ ParseError "takeWhile1: end of input"
484484 extract (Just s) = fextract s
485485
486−-- | See 'Streamly.Internal.Data.Parser.sliceSepBy'.
486+-- | See 'Streamly.Internal.Data.Parser.sliceSepByP'.
487487--
488488-- /Internal/
489489--
490−sliceSepBy :: MonadCatch m =>
490+sliceSepByP :: MonadCatch m =>
491491 (a -> Bool) -> Parser m a b -> Parser m a b
492−sliceSepBy cond (Parser pstep pinitial pextract) =
492+sliceSepByP cond (Parser pstep pinitial pextract) =
493493
494494 Parser step initial pextract
495495
test/Streamly/Test/Data/Parser.hs+8−6
@@ -311,16 +311,18 @@ takeProperties =
311311-- where
312312-- list_length = Prelude.length ls
313313
314−sliceSepBy :: Property
315−sliceSepBy =
314+sliceSepByP :: Property
315+sliceSepByP =
316316 forAll (listOf (chooseInt (min_value, max_value ))) $ \ls ->
317− case S.parse (P.sliceSepBy predicate prsr) (S.fromList ls) of
318− Right parsed_list -> checkListEqual parsed_list (Prelude.takeWhile
319− (not. predicate) ls)
317+ case S.parse (P.sliceSepByP predicate prsr) (S.fromList ls) of
318+ Right parsed_list ->
319+ checkListEqual parsed_list (tkwhl ls)
320320 Left _ -> property False
321321 where
322322 predicate = (>= 100)
323323 prsr = P.many FL.toList (P.satisfy (const True))
324+ tkwhl ls = Prelude.takeWhile (not . predicate) ls
325+
324326
325327takeWhile :: Property
326328takeWhile =
@@ -704,7 +706,7 @@ main =
704706 -- prop "lookAhead . take n >> lookAhead . take n = lookAhead . take n" lookAheadPass
705707 -- prop "Fail when stream length exceeded" lookAheadFail
706708 -- 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
708710 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
709711 prop ("P.takeWhile1 = Prelude.takeWhile if taken something,"
710712 ++ " else check why failed") takeWhile1
test/Streamly/Test/Data/Parser/ParserD.hs−13
@@ -335,18 +335,6 @@ groupBy =
335335 | null lst = []
336336 | otherwise = head $ List.groupBy cmp lst
337337
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−
350338sliceSepByMax :: Property
351339sliceSepByMax =
352340 forAll (chooseInt (min_value, max_value)) $ \n ->
@@ -710,7 +698,6 @@ main =
710698 prop "P.takeWhile = Prelude.takeWhile" Main.takeWhile
711699 prop "P.takeWhile1 = Prelude.takeWhile if taken something, else check why failed" takeWhile1
712700 prop "P.groupBy = Prelude.head . Prelude.groupBy" groupBy
713− prop "P.sliceSepBy = Prelude.takeWhile (not . predicate)" sliceSepBy
714701 prop "P.sliceSepByMax = Prelude.take n (Prelude.takeWhile (not . predicate)" sliceSepByMax
715702 prop "many (P.wordBy ' ') = words'" wordBy
716703 prop "parse 0, then 1, else fail" splitWith