I don't understand the difference between these two operators. Let's take an example parsing inputs like "AA,BB,CC,DD"
into vector of strings.
namespace qi = boost::spirit::qi;
class my_grammar : public qi::grammar<string::const_iterator, string()>
{
public:
my_grammar() : base_type(start) {
using qi::_1;
using qi::char_;
start = *(char_ - qi::lit(','));
}
qi::rule<string::const_iterator, string()> start;
};
As far as I know, the a %= b
is equivalent to a = b[_val = _1]
. That's clear. But on the other hand, the parser *(char_ - qi::lit(','))
has a synthesised attribute of type std::string
to which the matched sequence will be assigned. The result of using start = *(char_ - qi::lit(','))
is the same. So what's the case for using operator %=
?