Issue #6 new

Buffer fills and alternation

Mike Spivey
created an issue

Apologies for the absence of a test case, but I am comparing your code with my own implementation, not running it. Your implementation of plus is as follows:

{{{

plus :: Parser a -> Parser a -> Parser a plus a b = Parser $ \i0 a0 m0 kf ks -> let kf' i1 a1 m1 _ _ = addS i0 a0 m0 i1 a1 m1 $ \ i2 a2 m2 -> runParser b i2 a2 m2 kf ks in noAdds i0 a0 m0 $ \i2 a2 m2 -> runParser a i2 a2 m2 kf' ks }}}

The purpose of the noAdds is to set the state component A to empty, so that we can track buffer fills done during execution of parser a (bad choice of names, btw, since a is being used for 3 different things in these 5 lines). Then the addS is used to provide the same data to the execution of b. But here's the point: if a succeeds and calls its success continuation, then the previous contents of A are not restored. So if this alternation is nested inside an outer one, the outer one's tracking of buffer fills will be off.

A test case could use an expression like

(P >> (Q <+> R) >> S) <+> T

where P succeeds with a buffer fill, Q succeeds (with the side effect of setting the A component to empty), S fails, and T does not now see the effect of the buffer fill done by P.

If this makes sense to you, and I succeed in provoking a similar bug in my own code, I'll let you know.

Comments (1)

  1. Log in to comment