on master help sign in
Rename ParserChunked to ChunkParser
666eb07Ranjeet Kumar Ranjan
core/src/Streamly/Internal/Data/Parser/Chunked.hs+4−4
@@ -10,7 +10,7 @@
10
10
11module Streamly.Internal.Data.Parser.Chunked
11module Streamly.Internal.Data.Parser.Chunked
12 (
12 (
13− ParserChunked (..) -- XXX rename to ChunkParser
13+ ChunkParser (..) -- XXX rename to ChunkParser
14 , fromParserD
14 , fromParserD
15 , parseBreak
15 , parseBreak
16 , K.fromPure
16 , K.fromPure
@@ -29,7 +29,7 @@ where
29import Control.Monad.IO.Class (MonadIO(..))
29import Control.Monad.IO.Class (MonadIO(..))
30import GHC.Types (SPEC(..))
30import GHC.Types (SPEC(..))
31import Streamly.Internal.Data.Array.Type (Array(..))
31import Streamly.Internal.Data.Array.Type (Array(..))
32−import Streamly.Internal.Data.Parser.Chunked.Type (ParserChunked (..))
32+import Streamly.Internal.Data.Parser.Chunked.Type (ChunkParser (..))
33import Streamly.Internal.Data.Parser.ParserD.Type (Initial(..), Step(..))
33import Streamly.Internal.Data.Parser.ParserD.Type (Initial(..), Step(..))
34import Streamly.Internal.Data.Stream.Type (Stream)
34import Streamly.Internal.Data.Stream.Type (Stream)
35import Streamly.Internal.Data.SVar.Type (defState)
35import Streamly.Internal.Data.SVar.Type (defState)
@@ -85,7 +85,7 @@ parserDone (K.Failure n e) _ _ = return $ K.Error n e
85{-# INLINE_NORMAL parseBreak #-}
85{-# INLINE_NORMAL parseBreak #-}
86parseBreak
86parseBreak
87 :: (Monad m, Unbox a)
87 :: (Monad m, Unbox a)
88− => ParserChunked a m b
88+ => ChunkParser a m b
89 -> Stream m (Array a)
89 -> Stream m (Array a)
90 -> m (Either ParseError b, Stream m (Array a))
90 -> m (Either ParseError b, Stream m (Array a))
91parseBreak parser input = do
91parseBreak parser input = do
@@ -312,6 +312,6 @@ parseDToK pstep initial extract offset usedCount input cont = do
312-- /Pre-release/
312-- /Pre-release/
313--
313--
314{-# INLINE_LATE fromParserD #-}
314{-# INLINE_LATE fromParserD #-}
315−fromParserD :: (MonadIO m, Unbox a) => D.Parser a m b -> ParserChunked a m b
315+fromParserD :: (MonadIO m, Unbox a) => D.Parser a m b -> ChunkParser a m b
316fromParserD (D.Parser step initial extract) =
316fromParserD (D.Parser step initial extract) =
317 K.MkParser $ parseDToK step initial extract
317 K.MkParser $ parseDToK step initial extract
core/src/Streamly/Internal/Data/Parser/Chunked/Type.hs+12−12
@@ -26,7 +26,7 @@ module Streamly.Internal.Data.Parser.Chunked.Type
26 (
26 (
27 Step (..)
27 Step (..)
28 , ParseResult (..)
28 , ParseResult (..)
29− , ParserChunked (..)
29+ , ChunkParser (..)
30 , fromPure
30 , fromPure
31 , fromEffect
31 , fromEffect
32 , die
32 , die
@@ -98,7 +98,7 @@ instance Functor ParseResult where
98-- input without a result or return a result with no further input to be
98-- input without a result or return a result with no further input to be
99-- consumed.
99-- consumed.
100--
100--
101−newtype ParserChunked a m b = MkParser
101+newtype ChunkParser a m b = MkParser
102 { runParser :: forall r.
102 { runParser :: forall r.
103 -- XXX Maintain and pass the original position in the stream. that
103 -- XXX Maintain and pass the original position in the stream. that
104 -- way we can also report better errors. Use a Context structure for
104 -- way we can also report better errors. Use a Context structure for
@@ -130,7 +130,7 @@ newtype ParserChunked a m b = MkParser
130-- XXX rewrite this using ParserD, expose rmapM from ParserD.
130-- XXX rewrite this using ParserD, expose rmapM from ParserD.
131-- | Maps a function over the output of the parser.
131-- | Maps a function over the output of the parser.
132--
132--
133−instance Functor m => Functor (ParserChunked a m) where
133+instance Functor m => Functor (ChunkParser a m) where
134 {-# INLINE fmap #-}
134 {-# INLINE fmap #-}
135 fmap f parser = MkParser $ \n st arr pk ->
135 fmap f parser = MkParser $ \n st arr pk ->
136 let pk1 res = pk (fmap f res)
136 let pk1 res = pk (fmap f res)
@@ -147,7 +147,7 @@ instance Functor m => Functor (ParserChunked a m) where
147-- /Pre-release/
147-- /Pre-release/
148--
148--
149{-# INLINE fromPure #-}
149{-# INLINE fromPure #-}
150−fromPure :: b -> ParserChunked a m b
150+fromPure :: b -> ChunkParser a m b
151fromPure b = MkParser $ \n st arr pk -> pk (Success n b) st arr
151fromPure b = MkParser $ \n st arr pk -> pk (Success n b) st arr
152
152
153-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
153-- | See 'Streamly.Internal.Data.Parser.fromEffect'.
@@ -155,7 +155,7 @@ fromPure b = MkParser $ \n st arr pk -> pk (Success n b) st arr
155-- /Pre-release/
155-- /Pre-release/
156--
156--
157{-# INLINE fromEffect #-}
157{-# INLINE fromEffect #-}
158−fromEffect :: Monad m => m b -> ParserChunked a m b
158+fromEffect :: Monad m => m b -> ChunkParser a m b
159fromEffect eff =
159fromEffect eff =
160 MkParser $ \n st arr pk -> eff >>= \b -> pk (Success n b) st arr
160 MkParser $ \n st arr pk -> eff >>= \b -> pk (Success n b) st arr
161
161
@@ -163,7 +163,7 @@ fromEffect eff =
163-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.serialWith'
163-- this operation does not fuse, use 'Streamly.Internal.Data.Parser.serialWith'
164-- when fusion is important.
164-- when fusion is important.
165--
165--
166−instance Monad m => Applicative (ParserChunked a m) where
166+instance Monad m => Applicative (ChunkParser a m) where
167 {-# INLINE pure #-}
167 {-# INLINE pure #-}
168 pure = fromPure
168 pure = fromPure
169
169
@@ -200,7 +200,7 @@ instance Monad m => Applicative (ParserChunked a m) where
200-- /Pre-release/
200-- /Pre-release/
201--
201--
202{-# INLINE die #-}
202{-# INLINE die #-}
203−die :: String -> ParserChunked a m b
203+die :: String -> ChunkParser a m b
204die err = MkParser (\n st arr pk -> pk (Failure n err) st arr)
204die err = MkParser (\n st arr pk -> pk (Failure n err) st arr)
205
205
206-- | Monad composition can be used for lookbehind parsers, we can make the
206-- | Monad composition can be used for lookbehind parsers, we can make the
@@ -245,7 +245,7 @@ die err = MkParser (\n st arr pk -> pk (Failure n err) st arr)
245-- does not fuse, use 'Streamly.Internal.Data.Parser.concatMap' when you need
245-- does not fuse, use 'Streamly.Internal.Data.Parser.concatMap' when you need
246-- fusion.
246-- fusion.
247--
247--
248−instance Monad m => Monad (ParserChunked a m) where
248+instance Monad m => Monad (ChunkParser a m) where
249 {-# INLINE return #-}
249 {-# INLINE return #-}
250 return = pure
250 return = pure
251
251
@@ -264,11 +264,11 @@ instance Monad m => Monad (ParserChunked a m) where
264 {-# INLINE fail #-}
264 {-# INLINE fail #-}
265 fail = die
265 fail = die
266#endif
266#endif
267−instance Monad m => Fail.MonadFail (ParserChunked a m) where
267+instance Monad m => Fail.MonadFail (ChunkParser a m) where
268 {-# INLINE fail #-}
268 {-# INLINE fail #-}
269 fail = die
269 fail = die
270
270
271−instance MonadIO m => MonadIO (ParserChunked a m) where
271+instance MonadIO m => MonadIO (ChunkParser a m) where
272 {-# INLINE liftIO #-}
272 {-# INLINE liftIO #-}
273 liftIO = fromEffect . liftIO
273 liftIO = fromEffect . liftIO
274
274
@@ -289,7 +289,7 @@ instance MonadIO m => MonadIO (ParserChunked a m) where
289-- does not fuse, use 'Streamly.Internal.Data.Parser.alt' when you need
289-- does not fuse, use 'Streamly.Internal.Data.Parser.alt' when you need
290-- fusion.
290-- fusion.
291--
291--
292−instance Monad m => Alternative (ParserChunked a m) where
292+instance Monad m => Alternative (ChunkParser a m) where
293 {-# INLINE empty #-}
293 {-# INLINE empty #-}
294 empty = die "empty"
294 empty = die "empty"
295
295
@@ -322,7 +322,7 @@ instance Monad m => Alternative (ParserChunked a m) where
322-- | 'mzero' is same as 'empty', it aborts the parser. 'mplus' is same as
322-- | 'mzero' is same as 'empty', it aborts the parser. 'mplus' is same as
323-- '<|>', it selects the first succeeding parser.
323-- '<|>', it selects the first succeeding parser.
324--
324--
325−instance Monad m => MonadPlus (ParserChunked a m) where
325+instance Monad m => MonadPlus (ChunkParser a m) where
326 {-# INLINE mzero #-}
326 {-# INLINE mzero #-}
327 mzero = die "mzero"
327 mzero = die "mzero"
328
328
test/Streamly/Test/Data/Parser/Chunked.hs+1−1
@@ -685,7 +685,7 @@ some =
685-------------------------------------------------------------------------------
685-------------------------------------------------------------------------------
686
686
687parse :: (Monad f, Unbox a) =>
687parse :: (Monad f, Unbox a) =>
688− P.ParserChunked a f b -> S.Stream f (A.Array a) -> f (Either ParseError b)
688+ P.ChunkParser a f b -> S.Stream f (A.Array a) -> f (Either ParseError b)
689parse parser stream = fmap fst (P.parseBreak parser stream)
689parse parser stream = fmap fst (P.parseBreak parser stream)
690
690
691applicative :: Property
691applicative :: Property