Defined in header <cparse/Parser.hh>
protected:
virtual bool skipComments();
The base implementation is a no-op returning false. Override to skip whatever your grammar treats as comments — //, #, /* */, --, """...""", whatever.
Parameters
None.
Return value
Base implementation: always false (nothing was consumed).
Overrides: true if a comment was consumed at the current position, false otherwise.
Exceptions
Base implementation does not throw. Overrides may throw or catch freely.
Notes
The base is deliberately empty so grammars that have no comments do not pay any cost. A typical override for a C-style grammar handles both // and /* */:
bool skipComments() override
{
Cursor& c = getCursor();
if (extractToken("//"))
{
while (c.isValid() && c.safePeek() != '\n')
c.get();
return true;
}
if (extractToken("/*"))
{
while (c.isValid() && !extractToken("*/"))
c.get();
return true;
}
return false;
}
skipComments() is called by skipCommentsBlock() in a loop that alternates with skipWhiteSpaces() — comments and whitespace can appear in any order and any number.
Do not call extractToken for the closer inside a block-comment override loop without checking isValid() first — an unterminated block comment would loop forever. The example above guards against this correctly.
See also
- Parser::skipWhiteSpaces — the paired whitespace skipper.
- Parser::skipCommentsBlock — the loop that calls both.

