Skip to content

Instantly share code, notes, and snippets.

@jefftrull
Created April 18, 2016 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefftrull/0d7ecfef151c39885a7633d7547df8e6 to your computer and use it in GitHub Desktop.
Save jefftrull/0d7ecfef151c39885a7633d7547df8e6 to your computer and use it in GitHub Desktop.
*qi::string is compatible with both std::string (concatenation) and std::vector<std::string> (push_back) attributes
#include <string>
#include <vector>
#include <boost/spirit/include/qi.hpp>
using string_it_t = std::string::const_iterator;
int main() {
using namespace boost::spirit;
using namespace boost::spirit::qi;
rule<string_it_t, std::string()> r;
rule<string_it_t, std::vector<std::string>()> r2;
r = +qi::string("foo") ;
r2 = +qi::string("foo") ;
std::string testcase("foofoofoofoo");
std::string result;
auto beg = testcase.cbegin();
parse(beg, testcase.cend(), r, result);
std::cout << "result: " << result << "\n";
std::vector<std::string> result2;
beg = testcase.cbegin();
parse(beg, testcase.cend(), r2, result2);
std::cout << "result2:\n";
for( auto const& s : result2 ) {
std::cout << s << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment