I have trouble with boost spirit skippers.
I need to parse a file like that :
ROW int
int [int, int]
int [int, int]
...
I am able to parse it without problem (thanks to stackoverflow ;) only if I add an '_' after the first int.
In fact, I think the skipper eat the end of line after the first int, so the first and second (on second line) look as only one int. I don't understand how to keep eol but eat spaces. I've found examples to use a custom parser like here and here.
I tried qi::blank, custom parser with one single rule lit(' ') No matter what skipper I use, space and eol are always eat.
My grammar is :
a line :
struct rowType
{
unsigned int number;
std::list<unsigned int> list;
};
the full problem stored in a structure :
struct problemType
{
unsigned int ROW;
std::vector<rowType> rows;
};
the row parser :
template<typename Iterator>
struct row_parser : qi::grammar<Iterator, rowType(), qi::space_type>
{
row_parser() : row_parser::base_type(start)
{
list = '[' >> -(qi::int_ % ',') >> ']';
start = qi::int_ >> list;
}
qi::rule<Iterator, rowType(), qi::space_type> start;
qi::rule<Iterator, std::list<unsigned int>(), qi::space_type> list;
};
and the problem parser :
template<typename Iterator>
struct problem_parser : qi::grammar<Iterator,problemType(),qi::space_type>
{
problem_parser() : problem_parser::base_type(start)
{
using boost::phoenix::bind;
using qi::lit;
start = qi::int_ >> lit('_') >> +(row);
//BOOST_SPIRIT_DEBUG_NODE(start);
}
qi::rule<Iterator, problemType(),qi::space_type> start;
row_parser<Iterator> row;
};
And I use it like that:
main() {
static const problem_parser<spirit::multi_pass<base_iterator_type> > p;
...
spirit::qi::phrase_parse(first, last ,
p,
qi::space,
pb);
}
Of course, the qi::space is my problem, and a way to solve my problem would be to don't use a skipper, but phrase_parse requires one, and then my parser requires one.
I'm stuck since some hours now... I think it's something obvious I have misunderstood.
Thanks for your help.