megaparsec icon indicating copy to clipboard operation
megaparsec copied to clipboard

Export initialState

Open kirelagin opened this issue 3 years ago • 2 comments

One useful feature that megaparsec has compared to parsec is the ability to get the remainder of the input. In fact, I think it is so useful that it would make sense to expose this functionality explicitly.

In the meantime, it is accessible via runParser', however it is not easy to use given that this function requires the initial state, which is pretty tricky and boilerplate-y to construct. I think, it would be helpful to export initialState used by runParser in order to:

  1. Better support the use case of getting the remaining input.
  2. In general, simplify the initial state creation to allow the user to just override the fields in the default state that they want.

kirelagin avatar Apr 25 '21 17:04 kirelagin

Why not. Would you like to open a PR for that?

mrkkrp avatar Apr 25 '21 18:04 mrkkrp

Although there is a problem: hspec-megaparsec already exports a very similar function called initialState. If we export initialState from Megaparsec it may break existing code. Perhaps we could call it differently though.

mrkkrp avatar Apr 29 '21 13:04 mrkkrp

+1 for this request. It makes little sense to export runParserT' without a no-boilerplate way for the user to construct a State input.

olafklinke avatar Nov 08 '22 15:11 olafklinke