Delimited parsers
- Dominant language
- Haskell
- Stars
- 531
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
A common situation is to parse an encoding prefixed by its length. So you first parse the length as an integer `n`, and then you would like to run a (sub)parser `p :: Parser a` only on the next `n` bytes. I could think of two solutions for users today:
- Use `take` to get the `ByteString` and apply `parseOnly p`. However, we lose source position information in case the subparser fails, and we have to keep the whole `ByteString` in memory.
- Wrap `Parser` (e.g., with a few monad transformers) to track things like the number of bytes read; that would allow combinators like the ones I have in mind. However, this is rather heavyweight to implement. Does an existing library already offer this? I also suspect this approach would have more overhead than necessary.
It would be nice for attoparsec to have combinators to delimit the input that a subparser gets to see, like `span` and `splitAt` in [pipes-parse](http://hackage.haskell.org/package/pipes-parse-3.0.8/docs/Pipes-Parse.html).
What do you think of such an addition? Is there a better solution?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.