
sm4 wrote:
Oops - seems formatting got in the way.
Hope this is better:
Ooops, I missed your reply. Its better to post spirit related questions to spirit's mailing list. I'm re-posting this there.
----------------------------------------------------------------------------------------- #include
#include #include #include #include #include #include #include <iostream> #include <string>
using namespace boost::spirit; using namespace boost::spirit::qi; using namespace boost::spirit::ascii; using namespace boost::spirit::arg_names;
namespace phoenix = boost::phoenix;
using phoenix::at_c;
struct key_val { std::string key; std::string value; };
BOOST_FUSION_ADAPT_STRUCT( key_val, (std::string, key) (std::string, value) )
template <typename Iterator> struct my_grammar : grammar
{ my_grammar() : my_grammar::base_type(start) { quoted_string %= lexeme['"' >> +(char_ - '"') >> '"']; key %= quoted_string; value %= quoted_string; start = key [at_c<0>(_val) = _1] >> ':' >> value [at_c<1>(_val) = _1] ; }
rule
key; rule quoted_string; rule value; rule
start; };
int main() { typedef std::string::const_iterator citerator; std::string str = "\"x\": \"25\" ";
citerator iter = str.begin(); citerator end = str.end();
my_grammar<citerator> my_parser; key_val kv; phrase_parse(iter, end, my_parser, kv, space); // ASSERTs
return 0; }
-----------------------------------------------------------------------------------------
-- Joel de Guzman http://www.boostpro.com http://spirit.sf.net