Skip to content
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

New combinator: withRecovery #224

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

New combinator: withRecovery #224

wants to merge 2 commits into from

Conversation

jamesdbrock
Copy link
Member

Add a recovery parser combinator.

Resolves #223


Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

@jamesdbrock jamesdbrock force-pushed the jbrock-withRecovery branch 4 times, most recently from 46b825a to 34b10c1 Compare April 19, 2023 08:31
@jamesdbrock
Copy link
Member Author

I think this withRecovery function could give us a lot of what we want, even without a multiple-error feature. But let's wait a bit and see how #222 goes.

@jamesdbrock jamesdbrock marked this pull request as ready for review April 19, 2023 08:38
@jamesdbrock jamesdbrock force-pushed the jbrock-withRecovery branch from 34b10c1 to cb1c33f Compare April 20, 2023 07:36
@jamesdbrock jamesdbrock force-pushed the jbrock-withRecovery branch from cb1c33f to fda0dc8 Compare April 20, 2023 07:45
@jamesdbrock
Copy link
Member Author

https://markkarpov.com/tutorial/megaparsec.html#reporting-multiple-parse-errors

“One prerequisite for having a multi-error parser is that it should be possible to skip over a problematic part of input and resume parsing from a position that is known to be good.”

Right now, we have no support for multiple errors, so if the user wants to see multiple withRecovery errors then the user must do something like return all the errors in the parsers’s return type.

Another option is that the user could use runParserT with a runStateT monad transformer to save an Array ParseError.

flip runStateT [] $ runParserT "bad bad bad" do
many do
  skipSpaces
  withRecovery 
    (\err -> do
      lift $ modify (\errors -> snoc errors err)
      takeWhile (not <<< isSpace)
    )
    string "good"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

withRecovery
1 participant