Like, many of these other questions, I'm trying to parse a simple grammar into a tree of structs using Boost.Spirit.Qi.
I'll try to distill what I'm trying to do to the simplest possible case. I have:
struct Integer {
int value;
};
BOOST_FUSION_ADAPT_STRUCT(Integer, (int, value))
Later, inside of a grammar struct, I have the following member variable:
qi::rule<Iterator, Integer> integer;
which I am defining with
integer = qi::int_;
When I try to actually parse an integer, however, using
qi::phrase_parse(iter, end, g, space, myInteger);
myInteger.value
is always uninitialized after a successful parse.
Similarly, I have tried the following definitions (obviously the ones that don't compile are wrong):
integer = qi::int_[qi::_val = qi::_1]; //compiles, uninitialized value
integer = qi::int_[qi::_r1 = qi::_1]; //doesn't compile
integer = qi::int_[phoenix::bind(&Integer::value, qi::_val) = qi::_1]; //doesn't
integer = qi::int_[phoenix::at_c<0>(qi::_val) = qi::_1]; //doesn't
Clearly I am misunderstanding something about Spirit, Phoenix, or something else. My understanding is that qi::_1
is the first attribute of qi::int_
, here, and should represent the parsed integer, when the part in the square brackets gets executed as a function object. I am then assuming that the function object will take the enclosing integer
attribute qi::_val
and try and assign the parsed integer to it. My guess was that because of my BOOST_FUSION_ADAPT_STRUCT
call, the two would be compatible, and that certainly seems to be the case from a static analysis perspective, but the data is not being preserved.
Is there a reference(&) designation I am missing somewhere or something?
Integer
that takes a value for avalue
, then defined myinteger
parser asinteger = qi::long_long[qi::_val = phx::construct<Integer>(qi::_1)];
– Cartesianqi::rule<Iterator, Integer, ascii::space_type> integer;
, which looks like it breaks if I replaceInteger
withInteger()
, and all the examples have the trailing()
, which I neglected. So perhaps the template arguments to therule
were getting screwed up. Digging. – Cartesian