Re: [Spirit Development][Qi] Bug parsing arrays with the OR operator.

"Hartmut Kaiser" <[email protected]> Tue, 4 Jan 2011 18:32:11 -0600
Newsgroups gmane.comp.parsers.spirit.devel
Message-ID <[email protected]>
> I posted this bug a while back, but it seems that it was fixed, and has
> now come up again.
> 
> When parsing branches of a variant, if the first branch fails, then _val
> should be reset to what it was before the branch was taken.
> 
> Consider the following example:
> 
> input "hello"
> rule %= ((string("hello") >> eps[_pass = false]) | eps) >> string("hello")
> 
> When the first branch ((string("hello") >> eps[_pass = false]) | eps) is
> parsed, the first part of the first branch will pass, appending "hello"
> onto val.  The second part of the branch will then fail, and we will go
> the the second alternative of the variant which passes.
> _val should currently equal "", but it instead contains "hello" and the
> iterator is set a the beginning of the input stream again.  We then parse
> the last part of the rule, which just matches the input string, and adds
> "hello" to _val.
> 
> In trunk this results in the output "hellohello" instead of the correct
> output "hello".

That's the correct and expected behavior. The alternative parser does not
reset the attribute before executing the diferent alternatives. You need to
explicitly utilize hold[] to add attribute commit/rollback where needed. See
the docs (trunk) or the recent discussion on the ML.

Regards Hartmut
---------------
http://boost-spirit.com




------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl