-
Notifications
You must be signed in to change notification settings - Fork 85
Move backtracking into OneOf
#108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If I understand correctly, this is a huge change of behavior for end-users of the library. Until now, the input was freely available to reuse somewhere else if parsing did fail, but it can now be partially consumed. Issues can be caught with appropriate tests, but many may trip on this otherwise. Aside a prominent documentation/communication about the change, maybe there's a safer way to handle the transition? For example by adding a |
@tgrapperon Thanks for the feedback!
We do realize the behavior change is significant, but believe the impact to be small and we will call it out in the release notes. Of all the parsers we've written we only found one to have a problem with this change, and that's the XCTest log parser in our benchmarks. The problem was that a parser was written in a very strange way that assumed a
While this was true of many of the parsers in the library, there has never been any guarantee that a parser defined outside of the library would undo its work, nor have we documented that parsers undo their work (all documentation around backtracking is additive in this PR). In the end, expecting a parser to undo upon failure isn't something we could ever truly trust it to do. Moving this logic to only
We could keep the other backtracking behavior in for now with the plan to remove it in the future, but that feels like we're just kicking the can down the road and will have the same problem whenever we do change the behavior. We'd like to rip the band-aid off early. Would you like to run any parsers you've written on |
Thanks for the response @stephencelis! I agree. I was just worried by the transition, not the behavior. Fortunately, the library often works on derived types like I have a case where I'm trying to parse a I wrote very few parsers with an explicit This is a good change overall, and I can't wait for what's coming in the next weeks/months! |
I did test it on our project and it did perform as expected 👍🏽 |
In general I think this is fine. One additional "good citizen" might be |
Might be worth adding relevant documentation about |
This PR significantly changes how backtracking is done in the library, hopefully for the better!
Peek
andNot
)OneOf
Up till now it's been the responsibility of the parser to "be a good citizen" and clean up after itself on failure. This means if a parser failed to do so, you could get into a bad state or make a bad assumption.
By centralizing this work in
OneOf
, most parsers are freed of this responsibility and no longer have to worry about undoing changes to input. That is now simply be the responsibility ofOneOf
instead.