I like to call this a "fixed-input" parser.
I can tell you how pipes-parse
will do it. You can see a preview of what I'm about to describe in pipes-parse
in the parseN
and parseWhile
functions of the library. Those are actually for generic inputs, but I wrote similar ones for example String
parsers as well here and here.
The trick is really simple, you insert a fake end of input marker where you want the parser to stop, run the parser (which will fail if it hits the fake end of input marker), then remove the end of input marker.
Obviously, that's not as easy as I make it sound, but it's the general principle. The tricky parts are:
Doing it in such a way that it still streams. The one I linked doesn't do that, yet, but the way you do this in a streaming way is to insert a pipe upstream that counts bytes flowing through it and then inserts the end-of-input marker at the correct spot.
Not interfering with existing end of input markers
This trick can be adapted for pipes-attoparsec
, but I think the best solution would be for attoparsec
to directly include this feature. However, if that solution is not available, then we can restrict the input that is fed to the attoparsec
parser.