kschiess / parslet

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

Should allow unconsumed input after a successful match #63

Closed belkadan closed 12 years ago

belkadan commented 12 years ago

I'm trying to use Parslet to repeatedly parse statements in an input stream. For better error recovery, I don't want to just use repeat; if one statement is malformed, I want to be able to recover by, say, throwing away all characters up to a delimiter, then resuming my normal "next statement" mode.

There seems to be no good way to do this without replicating most of apply (or VM::run). Even just a flag to not error on unconsumed input would be nice, but something more fully-formed would probably include reusing a Parslet::Source (which you can't do just by passing it to parse, because it will try to wrap it in another Parslet::Source instance).

kschiess commented 12 years ago

Not sure what you really want from parslet here. I understand the following: You would like to be able to skip invalid input, but haven't figured out the syntax for it yet, nor the exact mechanism. And you would like to be able to override Parslet::Source, but there is a bug in #parse.

I will consider this to be a bug report for the latter and start thinking about the former when I get to it.

belkadan commented 12 years ago

No, not really. The problem is that parse will fail if there is any unconsumed input. If I want to handle things line-by-line, though, I currently have to split the input stream ahead of time. I'd like to be able to say parse and have it not error if there's a successful prefix parse.

kschiess commented 12 years ago

Valid requests, hope these commits help with your problem.

belkadan commented 12 years ago

Perfect, thanks!