My goal is to have my qi::grammar return an attribute. I\'m having significant difficulty doing this with a spirit::lexer though.
I\'d expe
I ended up realizing that the struct I defined is being used in spirit as a tuple. Because spirit will try to minimize the groups (like, an optional<int, int> is an optional<int>). Therefore, I guessed that a tuple<A> will be converted to an A. Which seems to be the case.
I was able to further reduce the test case of broken code to the following:
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/qi.hpp>
#include <string>
struct ident {
std::string a;
};
BOOST_FUSION_ADAPT_STRUCT(ident,
(std::string, a)
)
int main() {
boost::spirit::qi::rule<const char*, ident()> r;
r = boost::spirit::lexeme["abc"];
}
From the following mailing list postings (1, 2) that I found, I can work around this issue by doing:
r = boost::spirit::lexeme["abc"] >> boost::spirit::eps;
While not really elegant, it solves the problem at least. If someone else has a method to do the single element struct, I'd be greatly interested though.