Parser: many accepts input that ends inside an element
@GuillaumedeVolpiano is already working on this.
Since Nov 20, 2026.
- #3273 by @GuillaumedeVolpiano — open
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend
Research direction
Start with the reproduction using P.many, line, and P.eof, and compare the reported results for parse and parsePos. The issue links #1491 as possibly related; read it for context on parser alternatives and backtracking. Done means malformed final elements fail consistently, with behavior verified against all four inputs in the reproduction.
Written by the indexing model from the issue text.
Description
Package: streamly-core 0.3.3
GHC: 9.12.4
Reproduction
import Data.Functor.Identity
import qualified Streamly.Data.Fold as Fold
import qualified Streamly.Data.Parser as P
import qualified Streamly.Data.Stream as S
-- "many" of ('n', then one or more non-':' characters, then ':'), then eof.
line :: P.Parser Char Identity String
line = P.satisfy (== 'n') *> P.takeWhile1 (/= ':') Fold.toList <* P.satisfy (== ':')
p :: P.Parser Char Identity [String]
p = P.many line Fold.toList <* P.eof
main :: IO ()
main = do
let run s = (runIdentity (S.parse p (S.fromList s)), runIdentity (S.parsePos p (S.fromList s)))
print (run "nab:ncd:")
print (run "nab:ncd")
print (run "nab:x")
print (run "ncd")
| Input | Expected | Actual |
|---|---|---|
nab:ncd: |
Right ["ab","cd"] |
Right ["ab","cd"] |
nab:ncd |
Left: ncd is not a line |
Right ["ab"] |
nab:x |
Left: x is not a line |
Left (ParseError "eof: not at end of input") |
ncd |
Left |
Right [] |
What happens
When the input ends while many is in the middle of an element, the element
fails, many stops with the elements it had, and the input the failed element
had consumed is not given back: eof then succeeds. When the element fails on
a character instead (nab:x), the input is given back and eof fails as
expected.
So a malformed last element goes unnoticed whenever the input stops inside it.
I expected many to backtrack to the start of the failed element in both
cases, as it does for nab:x.
The same happens with parsePos.
Possibly related, though about the alternative of parsers and closed: #1491.
- Dominant language
- Haskell
- Stars
- 926
- Forks
- 71
- Avg merge
- 6h 49m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from composewell/streamly
-
takeInterval yields nothing, dropInterval drops nothingPossibly taken @GuillaumedeVolpiano claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
composewell/streamly#3271 ·
-
aspect:api
Difficulty 4/5 1-2 days Newbie friendliness 48/100
composewell/streamly#3206 ·
-
api:breaking aspect:api aspect:filesystem
Difficulty 4/5 1-2 days Newbie friendliness 35/100
composewell/streamly#3203 ·
-
type:performance
Difficulty 4/5 3-5 days Newbie friendliness 32/100
composewell/streamly#3200 · 2 comments ·
-
type:performance
Difficulty 5/5 Over a week Newbie friendliness 20/100
composewell/streamly#3187 ·
All issues in composewell/streamly
Similar issues
-
bug desktop
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
simplex-chat/simplex-chat#8291 ·
Maintainers usually reply within 1 day
-
[BUG]: C# programs with top-level statements fail to compilePossibly taken @AsyncNigam claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
compiler-explorer/compiler-explorer#9625 · 1 comment ·
Maintainers usually reply within 1 day
-
needs triage type: enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
reflex-0.10Open
Difficulty 1/5 Under an hour Newbie friendliness 62/100
commercialhaskell/stackage#8180 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenZeppelin/canton-contracts#140 ·
Maintainers usually reply within 1 day