#include #include #include #include #include namespace parsers { namespace qi = boost::spirit::qi; namespace ascii = boost::spirit::ascii; namespace ph = boost::phoenix; template struct gram_1:qi::grammar { gram_1():gram_1::base_type(start) { start %= qi::raw[(ascii::string("abc") >> ascii::string("def") ) [std::cout << qi::_1 << std::endl]]; } qi::rule start; }; template struct gram_2:qi::grammar { gram_2():gram_2::base_type(start) { start %= qi::raw['"' >> *ascii::string("abc") >> '"']; } qi::rule start; }; } template bool do_parse(const char *p, const P & parser) { std::string in(p); std::string::iterator first(in.begin()); std::string result; bool r = phrase_parse(first,in.end(),parser,result); if( r) { std::cout << "parse of \"" << in << "\" produced $" << result << "$\n"; } else { std::cout << "parse of \"" << in << "\" failed\n"; } return r; } int main() { char *av[] = {"","abcdef","\"abcabcabc\""}; parsers::gram_1 g_1; parsers::gram_2 g_2; do_parse(av[1],g_1); do_parse(av[2],g_2); return 0; }