mrkkrp / megaparsec

Industrial-strength monadic parser combinator library
Other
915 stars 86 forks source link

Add `drop` to `Text.Megaparsec` #540

Open sol opened 1 year ago

sol commented 1 year ago

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 commented 1 year ago

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

sol commented 1 year ago

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

mrkkrp commented 1 year ago

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 :thinking: