Boost logo

Boost :

Subject: Re: [boost] [spirit] semantic action for mismatches?
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2011-01-08 12:19:37


> I might give that a shot as I can't seem to get local variables to solve
> my problem. I would expect these two commands to have the same result
> (albeit unnecessarily assigning the _a variable, which just gets tossed
> away anyway), but apparently they are not?
>
> r = p[_a = _1]
> r = p

Automatic attribute propagation from the rhs expression to the lhs rule is
disabled as soon as semantic actions are involved. If you want to enforce
attribute propagation anyways, write:

    rule<...> r;
    r %= p[...];

If the rhs has no semantic actions attached, operator=() behaves exactly
like operator%=().

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

>
> On Sat, Jan 8, 2011 at 8:36 AM, Eric Niebler <eric_at_[hidden]> wrote:
>
> > On 1/7/2011 6:54 PM, caustik wrote:
> > > I've come to notice that there seems to be a missing bit of symmetry
> > > in spirit with regards to semantic actions.
> > >
> > > If a rule matches, and thus executes it's semantic action(s), but a
> > > rule which includes that rule mismatches, there seems to be no way to
> "unwind"
> > > the code executed down the chain. For example, if one of your
> > > semantic actions allocates memory or increments a reference count,
> > > how do you free
> > /
> > > release that reference in the mismatch scenario? I've thought about
> > > using something like a shared_ptr, but it seems like that gets
> > > pretty sloppy
> > and
> > > unnatural. Is there something you can think of that would work?
> >
> > Just for reference, xpressive doesn't have this problem because
> > actions are executed lazily. When a sub-pattern matches, its action is
> > placed on a queue. If the pattern matching engine then needs to
> > backtrack, the action is un-queued. Only when the *whole* pattern
> > matches successfully is the entire action sequence executed ... in
> order, of course.
> >
> > --
> > Eric Niebler
> > BoostPro Computing
> > http://www.boostpro.com
> > _______________________________________________
> > Unsubscribe & other changes:
> > http://lists.boost.org/mailman/listinfo.cgi/boost
> >
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk