2

Possible Duplicate:
I can’t get Boost Spirit Lex and Qi to work together when qi returns an attribute

I've got a pretty simple problem that I can't seem to figure out. I won't bother posting the full code because I'm pretty sure that you won't need to see it to know want the problem is.

Lets say I want to parse a file that looks like this:

"dp",1,1
"dp",2,2

You want each data line to be a struct and put them into a vector.

namespace node {
    struct dp { int a; int b; };
    std::vector<dp> data;
}

I add them to Fusion.

BOOST_FUSION_ADAPT_STRUCT(obj::dp,(int,a)(int,b))
BOOST_FUSION_ADAPT_STRUCT(node::data,(std::vector<node::dp>,data))

My parsing grammar looks like this:

_dp %= lit("\"dp\",") >> int >> ',' >> int;
_d %= *_dp;

My rules are:

// in node namespace 
qi::rule<Iterator,data(),Skipper> _d;
qi::rule<Iterator,dp(),Skipper> _dp;

The problem is that...

_d %= *_dp;

Doesn't compile, but if I put anything in front of it, it does.

_d %= 'a' >> *_dp;

Of coarse this won't parse because the input data doesn't have an 'a' but you get the point.

How would you handle something like this?

Community
  • 1
  • 1
Richard
  • 125
  • 1
  • 5
  • 1
    Try `_d %= eps >> *_dp;`. If it works it'll be an error related with `BOOST_FUSION_ADAPT_STRUCT` with only one member. I remember [sehe](http://stackoverflow.com/users/85371/sehe) has explained it several times, but I can't find any of his answers right now. I personally would use `qi::rule(),Skipper> _d;` removing the adaptation of `data`. –  Nov 07 '12 at 16:11
  • [Here](http://stackoverflow.com/a/7772861/1252091) is an answer that solves the error mentioned above and includes two links to the boost spirit mailing list. –  Nov 07 '12 at 16:24
  • Thanks, that was it; I just got rid of data and used std::vector() instead, which makes it look cleaner in my opinion. I was looking forever through spirit's documentation but never saw this issue in it. If you want to post the answer I mark it as accepted. – Richard Nov 07 '12 at 18:04
  • @llonesmiz Oh aha. Thanks for doing the leg work there. Having a look whether it is a dupe. So it is. Closing as dupe :) – sehe Nov 07 '12 at 20:06

0 Answers0