Repository navigation
Parser: feed the input given back at end of input to the next parser - #3273
Open
GuillaumedeVolpiano wants to merge 1 commit into
Open
GuillaumedeVolpiano wants to merge 1 commit into
GuillaumedeVolpiano wants to merge 1 commit into
Conversation
When the left parser of splitWith, split_ or concatMap finished on extract with a backtrack count, the right parser was extracted at once, without being driven on the input given back. So in "many p <* eof", when the input ended inside an element, eof succeeded even though the input of the failed element was left unconsumed. Return FContinue with the right parser in that case, so that the driver backtracks and feeds it the remaining input. The noErrorUnsafe variants are not changed. Fixes composewell#3270 Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_019RtUYCYCwddhe8t5hVfLiv
Member
|
this may take a bit more time. I am aware of this issue and a few more similar ones and I have a pending change which may be a bit more broad in several parser functions, but I need to find time to get to that. If you are stuck because of this let me know and I can prioritize it. This PR may be a subset of my changes and if it aligns with those we can merge this first. |
Contributor
Author
|
No hurry, in the meantime I've designed an integration of flatparse into streamly, so my code doesn't rely on this anymore. Anyhow, happy to help once we're done with takeInterval if you want me to ;) |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3270.
Problem
many p <* eofaccepts an input that ends inside an element: with the parserof the issue,
nab:ncdgivesRight ["ab"]instead of an error.The issue blames
many, butmanyis correct: when the input ends inside anelement, its
extractreturnsFDone (- cnt)and so gives back the inputconsumed by the failed element. The fault is in the sequencing combinators
splitWith(<*>,<*),split_(*>) andconcatMap(>>=). Inextract, when the left parser returnsFDone nand the right parserinitializes with
IPartial, they call theextractof the right parser atonce. The right parser is never driven on the
nelements given back, soeofsucceeds, and any other parser misses that input.
This affects any left parser that backtracks on
extract, not onlymany.Change
In the
extractofsplitWith,split_andconcatMap, when the left parserreturns
FDone nwithn /= 0, returnFContinue nwith the right parserstate, so that the driver backtracks and feeds it the remaining input. When
n == 0the right parser is extracted as before.The
noErrorUnsafe*variants have the same code and are not changed, as theyare documented not to work with parsers that can fail.
Tests
Ten cases added to the common parser tests, run by the
Data.ParserandData.ParserKtest suites:many p <* eof,many p *> eofandmany p >>= ... eoffail when the input ends inside an element.manywith<*>,*>or>>=receives the incomplete element.manyalone, a well formed input, and an element stopped by a wrong input.Without the change 7 of the 10 fail, with it all pass.
Data.Parser(209examples) and
Data.ParserK(121 examples) pass with GHC 9.12.4. The othertest suites and the benchmarks were not run locally.
🤖 Generated with the help of Claude Code