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

Add drop to Text.Megaparsec #540

Open
sol opened this issue Aug 9, 2023 · 3 comments
Open

Add drop to Text.Megaparsec #540

sol opened this issue Aug 9, 2023 · 3 comments

Comments

@sol
Copy link

sol commented Aug 9, 2023

I'd love to have Text.Megaparsec to export

-- | Advance by / ignore `n` input tokens
drop :: MonadParsec e s m => Int -> m ()
drop n = P.skipCount n $ P.token Just mempty

(or possibly implement it with getOffset / setOffset, if that results in the exact same parser state, not sure)

@mrkkrp
Copy link
Owner

mrkkrp commented Aug 9, 2023

IIUC you want this as a new primitive? (Because there is already skipCount in parser-combinators.)

@sol
Copy link
Author

sol commented Aug 9, 2023

I think skipCount requires a parser as an argument, whereas I want to unconditionally drop / ignore a specified number of tokens.

@mrkkrp
Copy link
Owner

mrkkrp commented Aug 9, 2023

I think now mkParsec can now be used to implement any primitive, including what you propose here. I think it would even make sense to re-implement some of the methods of MonadParsec in terms of mkParsec and thus reduce the number of methods of that class 🤔

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

No branches or pull requests

2 participants