How can I pass _a as reference to a sub rule which has an attribute of the same type:
rule(_a)
does not work.
The code looks like:
qi::rule<Iterator, Mdlx(), qi::locals<std::string, long32>, Skipper> mdl; // parent rule
qi::rule<Iterator, Model(long32&), Skipper> model; // sub rule
...
mdl =
-version[at_c<0>(_val) = _1]
// wrong code! pass _b because it has the type long32
//>> -model(_a)[at_c<1>(_val) = _1] // pass local as attribute
>> -model(_b)[at_c<1>(_val) = _1] // pass local as attribute
>> -sequences[at_c<2>(_val) = _1]
>> -global_sequences[at_c<3>(_val) = _1]
>> -textures[at_c<4>(_val) = _1]
>> -materials[at_c<5>(_val) = _1]
>> repeat(_a)[
geoset_animation
]
;
model =
lit("Model")
>> string_literal[at_c<0>(_val) = _1]
>> lit('{')
>> -(
lit("NumGeosetAnims")
>> integer_literal[_r1 = _1] // assign the value to the passed attribute
>> lit(',')
)
>> lit("BlendTime") >> integer_literal[at_c<1>(_val) = _1]
>> lit(',')
>> bounds[at_c<2>(_val) = _1]
>> lit('}')
;
As you can see I want to pass a local as reference to the sub rule which should set the long32 value. The value is then used in the parent rule as local variable _a.
edit: I've found the error in my code. I was passing _a but the first local has type std::string. I had to pass _b instead!
After the clarification of the question, I surmise that you are looking for a feature more like Spirit's Inherited Attributes. Most significantly, these are always passed at invocation, so they need not be default-constructible and can be reference types.
Live On Coliru
Prints