Skip to content

Commit 2c79b5b

Browse files
committed
Fix ParserK.toParser
1 parent 4021b11 commit 2c79b5b

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

  • core/src/Streamly/Internal/Data/ParserK

core/src/Streamly/Internal/Data/ParserK/Type.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -774,14 +774,14 @@ toParser parser = ParserD.Parser step initial extract
774774
r <- cont None
775775
case r of
776776
-- This is extract so no input has been given, therefore, the
777-
-- translation here is (1 + n) rather than n.
778-
-- XXX How should we visualize (1 + n)?
779-
-- XXX Go forward by 1 element on extract?
780-
Done n b -> assert (n <= 0) (return $ ParserD.SDone (1 + n) b)
777+
-- translation here is (n - 1) rather than n.
778+
-- In ParserD @n@ means go back by @n@ including the current input
779+
-- Since there is no current input we reduce moving by 1.
780+
Done n b -> assert (n <= 0) (return $ ParserD.SDone (n - 1) b)
781781
Error _ e -> return $ ParserD.Error e
782782
Partial _ cont1 -> extract cont1
783783
Continue n cont1 ->
784-
assert (n <= 0) (return $ ParserD.SContinue (1 + n) cont1)
784+
assert (n <= 0) (return $ ParserD.SContinue (n - 1) cont1)
785785

786786
{-# RULES "fromParser/toParser fusion" [2]
787787
forall s. toParser (adapt s) = s #-}

0 commit comments

Comments
 (0)