2

いくつかの階層データをboost::utree構造に解析しようとしましたが、expextedとして機能していないようです。これが私がすることです:

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<...>(...)) ...

ここで、traverseData()はoperator <<(cout、utree)の単なる呼び出しです。これは私が得るものです:

(21 "hello" 34 "some" "strange" 12 "world")

それでも、utreeにphrase_parse()にフィードされた文字列のネストされた性質を反映させたいと思います。好き:

(21 "hello"(34 "some") "strange"(12 "world"))

この種の出力を取得するにはどうすればよいですか?

PS VisualStudio2010でブースト1.49.0を使用

4

1 に答える 1

3

It was rather simple... I just had to change the declaration of the 'outer' qi rule to:

qi::rule<const char*, utree::list_type(), chars::space_type> outer;

thus changing the rule's attribute type to utree::list_type. Yet I have no idea why this works...

And in boost 1.47.0 there is another bug with utree failing to propagate its attribute value when used in conjunction with semantic actions.

于 2012-06-06T15:08:13.370 に答える