inhabitedtype / angstrom

Parser combinators built for speed and memory efficiency
Other
637 stars 74 forks source link

Add parse_incomplete_bigstring #165

Closed dinosaure closed 5 years ago

dinosaure commented 5 years ago

This code function is to able to replace this kind of bad code:

let[@warning "-8"] Angstrom.Unbuffered.Partial { continue; _ }= Angstrom.Unbuffered.parse p in
continue x ~off:0 ~len:(Bigstringaf.length x) Angstrom.Unbuffered.Incomplete
seliopou commented 5 years ago

I'm not sure how useful this function is. It'll help avoid the specific case you've mentioned, but parsing necessarily requires the user to write a loop. This saves you one iteration of the loop but then you have to still write and enter the loop.

Put another way, where is that first bigstring coming from? If there's more input that's needed, will it come from the same place? I think the answer to that is probably yes. If there's a common situation where the sources are different though, I'd be interested in learning about it.

dinosaure commented 5 years ago

You can see an example here where I want to provide a non-blocking interface to parse header of e-mail with angstrom. The code is little bit un-readable at this point however.

And, in other side, I have a serious question. Why you did not come to Marrakesh 😥 ?

seliopou commented 5 years ago

I think that this function wouldn't be necessary if you turned decode into a recursive function, started a new parse in the Done case, called decode recursively after doing that, and fed input in the partial case only. That also (to me) makes more sense since you feed input under the case where the parser tells you it need more input.

seliopou commented 5 years ago

Closing for now, assuming no further discussion is necessary.

dinosaure commented 5 years ago

Thanks for your review on mrmime :+1: