kschiess / parslet

A small PEG based parser library. See the Hacking page in the Wiki as well.
kschiess.github.com/parslet
MIT License
805 stars 95 forks source link

Incremental parser / do not error on incomplete data #195

Closed HoneyryderChuck closed 5 years ago

HoneyryderChuck commented 5 years ago

First, congrats for your gem. Very useful!

I'm writing an HTTP/1 response parser with it. It works, but only when I send the full payload.

I have smth like this:

rule(:response) {
  response_line >> crlf >>
  header.repeat.as(:headers) >> crlf >>
  data.as(:data)
}
root :response

But if I pass an incomplete payload, I get:

parser.parse("HTTP/1.1 200 OK\r\n")
Parslet::ParseFailed: Failed to match sequence (RESPONSE_LINE CRLF headers:(HEADER{0, }) CRLF data:DATA) at line 1 char 16.

I'd like to be able to feed bytes to the parser and get the parameters as they're being discovered, Eventually changing the root as I receive them.

kschiess commented 5 years ago

Hi HoneyryderChuck,

Thanks for using parslet. Unfortunately this is not a help forum, but rather the projects issue tracker. I would suggest you ask on Stackoverflow to get support.

Cheers, kaspar

HoneyryderChuck commented 5 years ago

https://stackoverflow.com/questions/53163596/parslet-how-to-buffer-parse-incrementally-data