/*============================================================================= Copyright (c) 2011 Thomas Bernard http://spirit.sourceforge.net/ Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ //[reference_includes #include #include #include #include #include #include #include #include #include #include #include #include #include //] // Data structure definitions struct base_type { base_type(const std::string &name) : name(name) {} std::string name; virtual std::ostream &output(std::ostream &os) const { os<<"Base : "< parse_string; rule(), space_type> kwd_rule; // Our string parsing helper parse_string %= '"'> *(char_-'"') > '"'; namespace phx=boost::phoenix; //[ kwd rule kwd_rule = kwd("derived1")[ ('=' > parse_string > int_ ) [phx::push_back(_val,phx::new_(_1,_2))] ] / kwd("derived2")[ ('=' > parse_string > int_ ) [phx::push_back(_val,phx::new_(_1,_2))]] / kwd("derived3")[ ('=' > parse_string > int_ > double_) [phx::push_back(_val,phx::new_(_1,_2,_3))] ] ; //] using boost::spirit::qi::phrase_parse; using boost::spirit::qi::ascii::space; // The result vector std::vector result; char const input[]="derived2 = \"object1\" 10 derived3= \"object2\" 40 20.0 "; char const* f(input); char const* l(f + strlen(f)); if (phrase_parse(f, l, kwd_rule, space,result) && (f == l)) std::cout << "ok" << std::endl; else std::cout << "fail" << std::endl; using namespace boost::phoenix::arg_names; std::for_each(result.begin(),result.end(),std::cout<<*arg1<