How might I assume a "default value" when parsing using boost::spirit?
- by tJener
Let's say I have a grammar defined to something like:
a b c d
where c, and d are optional and default to 14 if not given. Can I get it to automatically return the 14 if the value isn't given?
The closest I've come is like the following:
qi::rule<Iterator, std::vector<int>(), ascii::space_type> some_rule;
some_rule %= >> int_ >> int_ >> -int_ >> -int_;
// ...
some_other_rule = some_rule[&some_callback_for_int_vectors];
which will then get 0 for the optional values that didn't show up (I believe). I then change consecutive 0s at the end into 14. Not only is this horribly wrong, but its also just not elegant. Is there a better way to do this?