Boost logo

Boost Users :

Subject: Re: [Boost-users] [Boost.Spirit] Synthesised attributes and sub-rules
From: Vitaly Budovski (vbudovski+news_at_[hidden])
Date: 2010-10-14 08:56:54


On 14 October 2010 22:36, Hartmut Kaiser <hartmut.kaiser_at_[hidden]> wrote:
> That should be easy, see below.
>
>    start = a_rule | b_rule | c_rule;
>
>    qi::rule<Iterator, std::vector<int>()> a_rule;
>    qi::rule<Iterator, std::vector<int>()> b_rule;
>    qi::rule<Iterator, std::vector<int>()> c_rule;
>
>
> HTH
> Regards Hartmut
> ---------------
> http://boost-spirit.com

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.

I was able to eventually achieve my goal by specifying each of the
rules like so:

qi::rule<Iterator, std::vector<int> &> 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?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net