1

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.

sehe
  • 374,641
  • 47
  • 450
  • 633
KentH
  • 1,204
  • 1
  • 14
  • 23
  • If you provide a small sample we can help answer the question in more concrete fashion – sehe Jul 17 '14 at 06:48

1 Answers1

2

Yes. In principle there are three approaches:

  1. rely on the public constructor
  2. use a semantic action (e.g. qi::int_ [ qi::_val = boost::phoenix::construct<type_identifier>(qi::_1) ])
  3. 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

sehe
  • 374,641
  • 47
  • 450
  • 633
  • The transformation_attribute trait was exactly what I needed. The [parse_date](http://www.boost.org/doc/libs/1_55_0/libs/spirit/example/qi/parse_date.cpp) example was very helpful -- but I didn't know what to grep for. Thanks a bunch! – KentH Jul 18 '14 at 04:22