struct coordinate {
int x;
int y;
int z;
};
BOOST_FUSION_ADAPT_STRUCT(
coordinate,
(int, x)
(int, y)
(int, z)
)
template <typename Iterator>
struct coordinate_grammar : qi::grammar<Iterator, coordinate(), ascii::space_type>
{
coordinate_grammar()
:
coordinate_grammar::base_type(start),
optional_x(-(qi::int_ >> ':')),
optional_z(-('@' >> qi::int_)),
start(optional_x >> qi::int_ >> optional_z)
{
}
qi::rule<Iterator, int, ascii::space_type> optional_x;
qi::rule<Iterator, int, ascii::space_type> optional_z;
qi::rule<Iterator, coordinate(), ascii::space_type> start;
};
I would like to set 0
as the default value of x
, and 1000
as the default value of z
.
Input --> Desired Output:
200:400@300
-->[200,400,300]
200:400
-->[200,400,1000]
400@300
-->[0,400,300]
400
-->[0,400,1000]
How do I need to modify the rule syntax to provide a default value when a value has not been specified for the optional (optional_x
and optional_z
) parsers?