Alright, so making your own skipper isn't too bad. And it elegantly solves this commenting problem, just as Mike M said. I define my rules in a struct called Parser
that is templated with an Iterator
. Had to make some adjustments to use the skipper. First, here is the skipper which is defined in Parser
with all my other rules:
typedef qi::rule<Iterator> Skipper;
Skipper skipper;
So skipper
is a rule of type Skipper
. Here is what my Parser
struct looked like originally, where it was using the ascii::space
rule of type ascii::space_type
as its skipper, which IS NOT the same type as qi::rule<Iterator>
that skipper
is based on!
struct Parser : qi::grammar<Iterator, std::vector<Category>(), ascii::space_type>
{
qi::rule<Iterator, std::vector<Category>(), ascii::space_type> root;
...
So every instance of ascii::space_type
in the rule templates must be replaced with Skipper
! That includes other rules besides the root
that is shown here, such as param
and category
from my question. Leaving any remnant of the old ascii::space_type
behind gives cryptic compiler errors.
struct Parser : qi::grammar<Iterator, std::vector<Category>(), qi::rule<Iterator>>
{
typedef qi::rule<Iterator> Skipper;
Skipper skipper;
qi::rule<Iterator, std::vector<Category>(), Skipper> root;
...
The original skipper was merely space
, mine is now an alternative of space
and comment
. No old functionality (space skipping) is lost.
skipper = space | comment;
Then the phrase_parse
call needs to be adjusted from this old version that used ascii::space
:
bool r = phrase_parse(iter, end, parser, ascii::space, result);
to
bool r = phrase_parse(iter, end, parser, parser.skipper, result);
And now comments disappear as easily as white space. Awesome.