Defined in header <cparse/Parser.hh>
protected:
bool extractCharacter( std::string::value_type const token );
Attempts to consume exactly one character equal to token. Peeks via Cursor::safePeek(); on match, calls Cursor::get() to advance and returns true. On mismatch, returns false without advancing.
Simpler than extractToken: no backtracking machinery — because only one character is inspected, the peek-then-decide pattern needs no save/restore.
Parameters
| Parameter | Description |
|---|---|
token | The character to match. |
Return value
true if the next character equals token (cursor advanced). false otherwise (cursor unchanged).
Exceptions
May propagate ios_base::failure from Cursor::get() on the match path if the stream is in an unrecoverable state, but the peek is safe — a plain EOF results in safePeek() returning the sentinel '\032', which will not equal any real requested character, and the method returns false.
Notes
Use for single-character punctuation and delimiters — (, ), {, }, ;, ,, = — where backtracking is not needed. For multi-character tokens, use extractToken.
Does not skip whitespace. Call skipWhiteSpaces or skipCommentsBlock first if that is the grammar convention.
Example
skipCommentsBlock();
if (!extractCharacter('('))
{
recordError(ParseError::Kind::Syntax, "expected '('");
return false;
}
// ... parse the parenthesised content ...
skipCommentsBlock();
if (!extractCharacter(')'))
{
recordError(ParseError::Kind::Syntax, "expected ')'");
return false;
}
See also
- Parser::extractToken — multi-character variant.
- Cursor::safePeek — the underlying peek.
- Cursor::get — the underlying consume.

