c++ - nested utree with boost::spirit::qi? -
i try parse hierarchical data boost::utree structure, yet doesnt seem work expexted. do:
qi::rule<const char*, utree(), chars::space_type> inner, outer; outer %= '<' > qi::int_ > *inner > '>'; inner %= outer | qi::as_string[qi::lexeme[+(chars::alnum - '>')]]; const char txt[] = "<21 hello <34 some> strange <12 world>>"; const char* txtit = txt; try { if (qi::phrase_parse(txtit, txt + strlen(txt), outer, chars::space, data)) { std::cout << "numbers parsed" << std::endl; hgrammar::traversedata()(data); } //return; data.clear(); }catch(qi::expectation_failure<...>(...)) ... where traversedata() call operator<<(cout, utree). get:
( 21 "hello" 34 "some" "strange" 12 "world" )
yet want utree reflect nested nature of string feeded phrase_parse(). like:
( 21 "hello" ( 34 "some" ) "strange" ( 12 "world" ) )
how sort of output?
ps used boost 1.49.0 visual studio 2010
it rather simple... had change declaration of 'outer' qi rule to:
qi::rule<const char*, utree::list_type(), chars::space_type> outer; thus changing rule's attribute type utree::list_type. yet have no idea why works...
and in boost 1.47.0 there bug utree failing propagate attribute value when used in conjunction semantic actions.
Comments
Post a Comment