I'd like to parse a sequence of integers into an std::vector<int>
, using boost::spirit
. The integers may be separated by a semicolon or a newline.
But this grammar doesn't compile:
typedef std::vector<int> IntVec;
template <typename Iterator, typename Skipper>
struct MyGrammar : qi::grammar<Iterator, IntVec(), Skipper> {
MyGrammar() : MyGrammar::base_type(start) {
start = +(qi::int_
>> (";" | qi::no_skip(qi::eol)));
}
qi::rule<Iterator, IntVec(), Skipper> start;
};
To be clear, I want to parse the following input, for example,
1; 2; 3
4 ; 5
into one vector (1,2,3,4,5)
. How can I do that and why does my version not compile?
Can I somehow write the separator ("semicolon or newline") as its own rule? What would its return type be? Some kind of null
value?