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

Implement mkParsec—a new method of MonadParsec #514

Merged
merged 1 commit into from Jun 11, 2023
Merged

Implement mkParsec—a new method of MonadParsec #514

merged 1 commit into from Jun 11, 2023

Conversation

brandonchinn178
Copy link
Contributor

@brandonchinn178 brandonchinn178 commented Feb 28, 2023

Close #366.

Implements a new primitive as discussed in #366 (comment), which enables defining new primitives, at the cost of needing to drop (a little) into megaparsec internals.

Copy link
Contributor

@Lev135 Lev135 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to use Reply? It seems that your type of liftConsumer is isomorphic to

(State s e -> Reply s e a) -> m a

and implementation of pLiftConsumer is identical to mkPT.

@brandonchinn178
Copy link
Contributor Author

I wasn't aware of Reply :)

  1. Seems like mkPT would have to be exported
  2. The docs of Reply says it represents the "result at the end of parsing". If we reuse it for this, we'd probably have to tweak the wording there?
  3. Overall, not opposed. I'm just not sure how Reply is used currently, and if it should be reused here

@mrkkrp
Copy link
Owner

mrkkrp commented Jun 11, 2023

@brandonchinn178 So, first of all, I'm sorry it took so long to get to this one. This is a great idea which I believe can greatly empower users of the library. Regarding @Lev135's suggestion, I think it is a very good one. I sketched an alternative implementation and pushed it to this branch (I also took the liberty of rebasing on current master). Can you please check that the mkParsec method is sufficient for doing whatever you did with liftConsumer?

I did not implement breakOn just yet, but I you deem mkParsec usable we can add the example with breakOn back and merge this.

@brandonchinn178
Copy link
Contributor Author

Looks great! Yeah, if you get the breakOn test working, that's sufficient for me!

@mrkkrp mrkkrp changed the title Implement liftConsumer Implement mkParsec—a new method of MonadParsec Jun 11, 2023
This can be used to construct “new primitives” with arbitrary behavior at
the expense of having to dive into Megaparsec's internals.
@mrkkrp mrkkrp merged commit cf5d347 into mrkkrp:master Jun 11, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a new primitive: 'breakOn'
3 participants