Using Megaparsec 5.
Following this guide, I can achieve a back-tracking user-state by combining StateT
and ParsecT
(non-defined types should be obvious/irrelevant):
type MyParser a = StateT UserState (ParsecT Dec T.Text Identity) a
if I run a parser p :: MyParser a
, like this:
parsed = runParser (runStateT p initialUserState) "" input
The type of parsed
is:
Either (ParseError Char Dec) (a, UserState)
Which means, in case of error, the user state is lost.
Is there any way to have it in both cases?
EDIT: Could I perhaps, in case of error, use a custom error component instead of Dec (a feature introduced in 5.0) and encapsulate the user state in there?