I'd like to use a factory function in a semantic action, but I haven't been able to find the right recipe using phoenix or fusion.
My spirit-qi rule that would look something like:
object = type_identifier >> arg_list;
and I'd like to have Fusion perform something like:
object = Factory(type_identifier)(arg_list)
instead of using BOOST_FUSION_ADAPT_STRUCT
to create a structure containing type_identifier
and arg_list
.
How can something like this be done? Thanks.
Yes. In principle there are three approaches:
qi::int_ [ qi::_val = boost::phoenix::construct<type_identifier>(qi::_1) ]
)use attribute transformation traits [See Customization of Spirit's Attribute Handling in the docs). In this case you'd simply have
qi::rule<It, Mytype()> r = qi::_int;
and the corresponding trait (assign_to_attribute_from_value<MyType, imt>
) handles the assignment