Re: [Boost-users] [Boost.Spirit] Synthesised attributes and sub-rules
On 14 October 2010 22:36, Hartmut Kaiser
wrote: That should be easy, see below.
start = a_rule | b_rule | c_rule;
qi::rule
a_rule; qi::rule b_rule; qi::rule c_rule; I think I tried something like that, but it didn't work. Unless I'm mistaken, each of those rules will create their own std::vector<int> instance, so the values will not end up inserted into the vector specified in the grammar parameter.
No, it should work. The vector attribute is propagated to the alternatives, where it is filled.
I was able to eventually achieve my goal by specifying each of the rules like so:
qi::rule
a_rule; and in the main grammar I passed the _val into them.
start = a_rule(_val) | b_rule(_val) | c_rule(_val)
Then I referenced the arguments with _r1 in the sub-rules.
Does that look correct? Is there a better way?
That should work as well. This might be a tick better in terms of performance, even. But I'm guessing here, I have not done any measurements. Regards Hartmut --------------- http://boost-spirit.com
participants (1)
-
Hartmut Kaiser