Why this parser leave 'b'
in attributes, even if option wasn't matched?
using namespace boost::spirit::qi;
std::string str = "abc";
auto a = char_("a");
auto b = char_("b");
qi::rule<std::string::iterator, std::string()> expr;
expr = +a >> -(b >> +a);
std::string res;
bool r = qi::parse(
str.begin(),
str.end(),
expr >> lit("bc"),
res
);
It parses successfully, but res is "ab"
.
If parse "abac"
with expr alone, option is matched and attribute is "aba"
.
Same with "aac"
, option doesn't start to match and attribute is "aa"
.
But with "ab"
, attribute is "ab"
, even though b gets backtracked, and, as in example, matched with next parser.
UPD
With expr.name("expr");
and debug(expr);
I got
<expr>
<try>abc</try>
<success>bc</success>
<attributes>[[a, b]]</attributes>
</expr>