I would like to generate output like this
common, int, optional
video, double, optional
by karma with the structure
struct attr_struct
{
std::vector<std::string> name;
std::vector<std::string> type;
std::vector<std::string> use;
};
So I defined some rules for it
#include<iostream>
#include<string>
#include<vector>
#include<boost/fusion/adapted/struct.hpp>
#include<boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;
namespace karma = boost::spirit::karma;
struct attr_struct
{
std::vector<std::string> name;
std::vector<std::string> type;
std::vector<std::string> use;
};
BOOST_FUSION_ADAPT_STRUCT
(
attr_struct,
(std::vector<std::string>, name)
(std::vector<std::string>, type)
(std::vector<std::string>, use)
);
struct attr_grammar
: karma::grammar<std::back_insert_iterator<std::string>, attr_struct()>
{
attr_grammar() : attr_grammar::base_type(query)
{
key = karma::delimit(", ") [karma::string << karma::string
<< karma::string] << karma::eol;
query = key; //this one work
//query = key % karma::eol; //oops, can't compile #1
//query = +key; //this one can't compile either #2
//can't compile either #3
//query = +(karma::string << ", " << karma::string
// << ", " << karma::string << karma::eol);
//* and % also can't make the job done
}
private :
typedef std::back_insert_iterator<std::string> sink_type;
karma::rule<sink_type, attr_struct()> key;
karma::rule<sink_type, attr_struct()> query;
};
It can't work, what should I do?
Thank you very much