I am trying to parse a log file of test results with the following grammer.
template<typename Iterator>
struct test_step_parse: qi::grammar<Iterator, TestResults(), ascii::space_type> {
test_step_parse() : test_step_parse::base_type(rqmts) {
using qi::lit;
using qi::lexeme;
using qi::omit;
using qi::int_;
using qi::eol;
using qi::char_;
test_step = lit("Test Step No.") >> int_;
pass_or_fail = lit("-") >> (string("Passed") | string("Failed"));
fdor_rqmts = -lit("OID")
>> lit("FDOR")
>> -lit("OID")
>> int_
>> *(-omit[char_(",/\\")] >> -(lit("FDOR") ^ lit("OID")) >> int_)
;
sard_rqmts = -lit("OID")
>> lit("SARD")
>> -lit("OID")
>> int_
>> *(-omit[char_(",/\\")] >> -(lit("SARD") ^ -lit("OID")) >> int_)
;
comment = lit("Comment:") >> lexeme[*(char_ - eol)] ;
rqmts = test_step
>> pass_or_fail
>> omit[*(char_ - lit("REQUIREMENT VERIFIED:"))]
>> lit("REQUIREMENT VERIFIED:")
>> (fdor_rqmts ^ sard_rqmts)
>> omit[+char_("=")]
>> -comment
;
BOOST_SPIRIT_DEBUG_NODE(test_step);
BOOST_SPIRIT_DEBUG_NODE(pass_or_fail);
BOOST_SPIRIT_DEBUG_NODE(fdor_rqmts);
BOOST_SPIRIT_DEBUG_NODE(sard_rqmts);
BOOST_SPIRIT_DEBUG_NODE(comment);
BOOST_SPIRIT_DEBUG_NODE(rqmts);
}
qi::rule<Iterator, TestResults(), ascii::space_type> rqmts;
qi::rule<Iterator, int(), ascii::space_type> test_step;
qi::rule<Iterator, std::string(), ascii::space_type> pass_or_fail;
qi::rule<Iterator, std::string(), ascii::space_type> comment;
qi::rule<Iterator, std::vector<int>(), ascii::space_type> fdor_rqmts;
qi::rule<Iterator, std::vector<int>(), ascii::space_type> sard_rqmts;
};
The grammer parses ok. However, when trying to auto-populating my user-defined struct, the attribute for the rule "comment" of type std::string is being passed into the vector as ascii numerals.
This is my user-defined struct:
struct TestResults {
int test_step_no;
std::string pass_or_fail;
std::vector<int> FDOR;
std::vector<int> SARD;
std::string comment;
};
BOOST_FUSION_ADAPT_STRUCT(
atp::TestResults,
(int, test_step_no)
(std::string, pass_or_fail)
(std::vector<int>, FDOR)
(std::vector<int>, SARD)
(std::string, comment)
)
The debug out put indicates that the rules are exposing the correct types, but somehow they are not getting placed in the struct correctly.
Any ideas what I am doing wrong? Sorry for any misuse of terminology etc.
Using gcc 4.6.3 and boost 1-47. Thank you.
Update: To clarify, so I am expecting to parse the following:
std::string test_test =
"Test Step No. 953-Failed\n"
"==============================================================================\n"
"STEP 7.7:\n"
"Test step, etc.\n"
"===============================================================================\n"
"REQUIREMENT VERIFIED: FDOR 12345"
" SARD 12345, 12356\n"
"===============================================================================\n"
"Comment: Didn't work.\n"
;
Using the debugger, it appears that all rules are exposing their attributes correctly:
<rqmts>
<try>Test Step No. 953-Fa</try>
<test_step>
<try>Test Step No. 953-Fa</try>
<success>-Failed\n============</success>
<attributes>[953]</attributes>
</test_step>
<pass_or_fail>
<try>-Failed\n============</try>
<success>\n===================</success>
<attributes>[[F, a, i, l, e, d]]</attributes>
</pass_or_fail>
<fdor_rqmts>
<try> FDOR 12345 </try>
<success> </success>
<attributes>[[12345]]</attributes>
</fdor_rqmts>
<sard_rqmts>
<try> </try>
<success>\n===================</success>
<attributes>[[12345, 12356]]</attributes>
</sard_rqmts>
<comment>
<try>Comment: Didn't work</try>
<success>\n</success>
<attributes>[[D, i, d, n, ', t, , w, o, r, k, .]]</attributes>
</comment>
<success>\n</success>
<attributes>[[953, [F, a, i, l, e, d], [12345], [68, 105, 100, 110, 39, 116, 32, 119, 111, 114, 107, 46], []]]</attributes>
</rqmts>
So everything seems to be working except that the "comments" attribute (std::string) is being stuffed in the "SARD" attribute (vector ), as a vector of ascii numerals, i.e,
[68, 105, 100, 110, 39, 116, 32, 119, 111, 114, 107, 46] = "Didn't work."