on master help sign in
Remove SPEC from parseCont
d33205fHarendra Kumar
core/src/Streamly/Internal/Data/Parser/ParserK/Type.hs+9−5
@@ -110,6 +110,10 @@ instance Functor ParseResult where
110--
110--
111newtype Parser a m b = MkParser
111newtype Parser a m b = MkParser
112 { runParser :: forall r.
112 { runParser :: forall r.
113+ -- Using "Input" in runParser is not necessary but it avoids making
114+ -- one more function call to get the input. This could be helpful
115+ -- for cases where we process just one element per call.
116+ --
113 (ParseResult b -> Int -> Input a -> m (Step a m r))
117 (ParseResult b -> Int -> Input a -> m (Step a m r))
114 -- XXX Maintain and pass the original position in the stream. that
118 -- XXX Maintain and pass the original position in the stream. that
115 -- way we can also report better errors. Use a Context structure for
119 -- way we can also report better errors. Use a Context structure for
@@ -453,10 +457,10 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
453 (cont (Success n b) (count + n - off) (Chunk arr))
457 (cont (Success n b) (count + n - off) (Chunk arr))
454 ChunkPartial n pst1 ->
458 ChunkPartial n pst1 ->
455 assert (n < 0 || n >= Array.length arr)
459 assert (n < 0 || n >= Array.length arr)
456− (return $ Partial n (parseCont SPEC (count + n - off) pst1))
460+ (return $ Partial n (parseCont (count + n - off) pst1))
457 ChunkContinue n pst1 ->
461 ChunkContinue n pst1 ->
458 assert (n < 0 || n >= Array.length arr)
462 assert (n < 0 || n >= Array.length arr)
459− (return $ Continue n (parseCont SPEC (count + n - off) pst1))
463+ (return $ Continue n (parseCont (count + n - off) pst1))
460 ChunkError n err ->
464 ChunkError n err ->
461 cont (Failure n err) (count + n - off) (Chunk arr)
465 cont (Failure n err) (count + n - off) (Chunk arr)
462
466
@@ -472,7 +476,7 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
472 (cont (Success (- n) b) (count - n) None)
476 (cont (Success (- n) b) (count - n) None)
473 ParserD.Continue n pst1 ->
477 ParserD.Continue n pst1 ->
474 assert (n >= 0)
478 assert (n >= 0)
475− (return $ Continue (- n) (parseCont SPEC (count - n) pst1))
479+ (return $ Continue (- n) (parseCont (count - n) pst1))
476 ParserD.Error err ->
480 ParserD.Error err ->
477 -- XXX It is called only when there is no input arr. So using 0
481 -- XXX It is called only when there is no input arr. So using 0
478 -- as the position is correct?
482 -- as the position is correct?
@@ -483,8 +487,8 @@ parseDToK pstep initial extract cont !offset !usedCount !input = do
483 -- Just/Nothing cases here. That may help in avoiding the parseContJust
487 -- Just/Nothing cases here. That may help in avoiding the parseContJust
484 -- function call.
488 -- function call.
485 {-# INLINE parseCont #-}
489 {-# INLINE parseCont #-}
486− parseCont _ !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
490+ parseCont !cnt !pst (Chunk arr) = parseContChunk cnt 0 pst arr
487− parseCont _ !cnt !pst None = parseContNothing cnt pst
491+ parseCont !cnt !pst None = parseContNothing cnt pst
488
492
489-- | Convert a raw byte 'Parser' to a chunked 'ParserK'.
493-- | Convert a raw byte 'Parser' to a chunked 'ParserK'.
490--
494--