Boost :: spirit, How to get the value for the placeholder

I am trying to create a parser that takes a line of the form "/ integer / (/ integer /)" and creates std :: tuple Right now I have:

qi::rule<string::iterator,std::tuple<int,int>()> parser = (qi::int_ >> '(' >> qi::int_ >> ')')[_val = std::make_tuple(qi::_1,qi::_2)] 

which does not compile, because qi :: _ placeholders do not have the correct types. How to "extract" a base value from a placeholder?

+4
source share
1 answer

Erm, you can just use the automatic distribution of attributes (aka. "Auto rule"):

 #include <boost/spirit/include/qi.hpp> #include <boost/fusion/adapted.hpp> #include <tuple> namespace qi = boost::spirit::qi; main( int argc, char* argv[] ) { qi::rule<std::string::iterator,std::tuple<int,int>()> parser; parser = (qi::int_ >> '(' >> qi::int_ >> ')') ; } 

Note the additional header for adapting std::tuple to the Fusion sequence.

+2
source

All Articles