Skip to content

Instantly share code, notes, and snippets.

@gintenlabo
Created October 30, 2013 09:50
Show Gist options
  • Save gintenlabo/7229846 to your computer and use it in GitHub Desktop.
Save gintenlabo/7229846 to your computer and use it in GitHub Desktop.
Boost version: 1.54.0
#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main() {
auto word = qi::raw[+qi::graph];
auto rule = qi::omit[*qi::space] >> word >> qi::omit[+qi::space];
std::string s = " hoge fuga";
auto iter = s.begin();
std::vector<std::string> results;
bool success = qi::parse(iter, s.end(), rule, results);
if (success) {
for (auto const& result : results) {
std::cout << result << std::endl;
}
} else {
std::cout << "parse error\n";
}
}
#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main() {
auto word = qi::raw[+qi::graph];
auto rule = qi::omit[*qi::space] >> word >> qi::omit[+qi::space] >> word;
std::string s = " hoge fuga";
auto iter = s.begin();
std::vector<std::string> results;
bool success = qi::parse(iter, s.end(), rule, results);
if (success) {
for (auto const& result : results) {
std::cout << result << std::endl;
}
} else {
std::cout << "parse error\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment