I'm trying to learn boost::spirit
. As an example, I'm trying to parse a sequence of words into a vector<string>
. I tried this:
#include <boost/spirit/include/qi.hpp>
#include <boost/foreach.hpp>
namespace qi = boost::spirit::qi;
int main() {
std::vector<std::string> words;
std::string input = "this is a test";
bool result = qi::phrase_parse(
input.begin(), input.end(),
+(+qi::char_),
qi::space,
words);
BOOST_FOREACH(std::string str, words) {
std::cout << "'" << str << "'" << std::endl;
}
}
which gives me this output:
'thisisatest'
but I wanted the following output, where each word is matched separately:
'this'
'is'
'a'
'test'
If possible, I'd like to avoid having to define my own qi::grammar
subclass for this simple case.