How might I assume a "default value" when parsing using boost::spirit?
Posted
by tJener
on Stack Overflow
See other posts from Stack Overflow
or by tJener
Published on 2010-03-17T06:59:23Z
Indexed on
2010/03/17
7:01 UTC
Read the original article
Hit count: 223
boost-spirit
|c++
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?
© Stack Overflow or respective owner