[Haskell-cafe] Parsec, updateState, and failure

Dimitry Golubovsky golubovsky at gmail.com
Sat May 31 10:12:18 EDT 2008


Hi,

If a parser which updated user state fails, will such update be reverted?

Suppose we have two parsers combined with <|>

p = p1 <|> p2

p1 has the following:

p1 = try $ do
 ... -- getting something from the input stream
 updateState (\st -> ...) -- updated state based on what gotten from the input
 x <- p3 -- p3 should see updated state and return something
 updateState (\st -> ...) -- updated state again (if p3 succeeded)
 return x

If p3 fails, p1 fails too (second updateState will not be reached).
But what will p2 (tried next) see in the user state? Will it be state
after the first updateState, or will failure of p1 roll the update
back?

Is there any bracket- or try-catch-finally-like mechanism for Parsec?

Thanks.

-- 
Dimitry Golubovsky

Anywhere on the Web


More information about the Haskell-Cafe mailing list