[Haskell-cafe] Re: Parsec, updateState, and failure
aslatter at gmail.com
Sat May 31 13:20:23 EDT 2008
On Sat, May 31, 2008 at 12:12 PM, Achim Schneider <barsoap at web.de> wrote:
> "Dimitry Golubovsky" <golubovsky at gmail.com> wrote:
>> If a parser which updated user state fails, will such update be
> I have no idea, I gave up before investigating that far.
> You want to avoid state at any cost, even more so if the state would
> influence parsing: spaghetti and headaches lay ahead. In the end I did
> three passes: two times parsec and one time something similar to
If you really really wanted state that doesn't un-roll when parsing
fails, this should work (but is untested):
> type MyParser = ParsecT String () (State MyState)
> runMyParser :: MyParser a -> String -> SourceName -> MyState -> (Either ParseError a, MyState)
> runMyParser m in name state = flip runState state $ runPT m in name
You can then use 'get' and 'set'.
But as you suggest, that way may be madness.
More information about the Haskell-Cafe