I'm trying to parse either an additive expression of the form "A+C", or "A" alone. After a few tests I realized that the problem is apparently my use of the optional parser, so to exemplify:
qi::rule<string::iterator, string()> Test;
Test =
(
qi::string("A")[qi::_val= qi::_1]
>> -(
qi::string("B")[qi::_val += qi::_1]
>> qi::string("C")[qi::_val += qi::_1]
)
)
;
string s1, s2;
s1 = "AB";
bool a= qi::parse(s1.begin(), s1.end(), Test, s2);
The idea is to parse 'A' or "ABC", but if the s1 value is "AB" without 'C', the value of a is true. I believe that although I put parenthesis after the operator '-' and then I use the ">>" operator, the 'C' part is considered optional, and not the B>>C as a whole. Any ideas?