|
Boost : |
Subject: Re: [boost] [spirit] semantic action for mismatches?
From: caustik (caustik_at_[hidden])
Date: 2011-01-07 22:54:30
On Fri, Jan 7, 2011 at 6:12 PM, Joel de Guzman <joel_at_[hidden]>wrote:
> On 1/8/2011 9:57 AM, caustik wrote:
>
>> On Fri, Jan 7, 2011 at 5:30 PM, Joel de Guzman<joel_at_[hidden]
>> >wrote:
>>
>> On 1/8/2011 7:54 AM, 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?
>>>>
>>>>
>>> Sure:
>>>
>>> r = p | eps[cleanup];
>>>
>>> If p fails with side-effects from its direct or indirect semantic
>>> actions, the cleanup semantic action can roll them back.
>>> <http://spirit.sf.net>
>>>
>>
>>
>> hmmm...
>>
>> Brilliant. You sir, are a gentleman and a scholar.
>>
>
> <blush> That was an easy way to earn that comment :-)
>
>
hmm I'll have to make you work a little harder then..
So, how about if you want the rule "r" to still mismatch? Since eps always
matches, the rule "r" as a whole succeeds. Also, how do you access the
result of "p" from inside "cleanup"?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk