Skip to content

Commit

Permalink
Fix bugs in important one shot ParserK drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Oct 10, 2024
1 parent 7d7c814 commit ddfe7ae
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions core/src/Streamly/Internal/Data/StreamK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,9 @@ parseBreak parser input = do
assertM(n1 >= 0 && n1 <= length backBuf)
let (s1, _) = backTrackSingular n1 backBuf nil
in return (Right b, s1)
ParserK.Error _ err -> return (Left (ParseError err), nil)
ParserK.Error _ err ->
let strm = fromList (Prelude.reverse backBuf)
in return (Left (ParseError err), strm)

seekErr n =
error $ "parseBreak: Partial: forward seek not implemented n = "
Expand Down Expand Up @@ -1529,7 +1531,12 @@ parseBreak parser input = do
assertM(n1 >= 0 && n1 <= bufLen)
let (s1, _) = backTrackSingular n1 backBuf s
pure (Right b, s1)
ParserK.Error _ err -> return (Left (ParseError err), nil)
ParserK.Error _ err ->
let strm =
append
(fromList (Prelude.reverse backBuf))
(cons element stream)
in return (Left (ParseError err), strm)

go
:: [a]
Expand Down Expand Up @@ -1622,7 +1629,9 @@ parseBreakChunksGeneric parser input = do
assertM(n1 >= 0 && n1 <= sum (Prelude.map GenArr.length backBuf))
let (s1, _) = backTrackGenericChunks n1 backBuf nil
in return (Right b, s1)
ParserK.Error _ err -> return (Left (ParseError err), nil)
ParserK.Error _ err ->
let strm = fromList (Prelude.reverse backBuf)
in return (Left (ParseError err), strm)

seekErr n len =
error $ "parseBreak: Partial: forward seek not implemented n = "
Expand Down Expand Up @@ -1672,7 +1681,12 @@ parseBreakChunksGeneric parser input = do
assertM(n1 <= sum (Prelude.map GenArr.length (arr:backBuf)))
let (s1, _) = backTrackGenericChunks n1 (arr:backBuf) stream
in return (Right b, s1)
ParserK.Error _ err -> return (Left (ParseError err), nil)
ParserK.Error _ err ->
let strm =
append
(fromList (Prelude.reverse backBuf))
(cons arr stream)
in return (Left (ParseError err), strm)

go
:: [GenArr.Array a]
Expand Down

0 comments on commit ddfe7ae

Please sign in to comment.