Defined in header <cparse/Parser.hh>
protected:
void recordError( ParseError::Kind kind,
std::string const& message,
unsigned long int line = 0,
unsigned long int col = 0 );
Appends a ParseError to the internal error vector. Fills filename from the active cursor's getFilename(). If line or col are zero, fills them from the active cursor's getNextLineNumber() / getNextColumnNumber() — the character the grammar stopped at. After a failed extractToken() or extractCharacter() that is the first character that did not match; at end of input, the position just past the last character.
Does not terminate the parse — call exit() separately if the error is fatal.
Parameters
| Parameter | Description |
|---|---|
kind | One of the ParseError::Kind enumerators. |
message | The diagnostic text. No format prescribed. |
line | Optional. 0 (default) means "the line of the next unread character". |
col | Optional. 0 (default) means "the column of the next unread character". |
Return value
(none)
Exceptions
May propagate std::bad_alloc from the internal std::vector::push_back. Does not throw otherwise.
Notes
Since cparse 1.3. Before it, the default was the character consumed last — one position early, and 0:0 for an error on the first character.
Pass explicit line and col when the diagnostic refers to text already consumed — a token you have read and then rejected, or a construct that started earlier in the file. Before consuming it, save getNextLineNumber() / getNextColumnNumber(); right after consuming a one-character opener, getLineNumber() / getColumnNumber() name that opener. For an unterminated block, capture the opener's coordinates on the way in:
if (extractCharacter('{'))
{
unsigned long const braceLine = getCursor().getLineNumber();
unsigned long const braceCol = getCursor().getColumnNumber();
enterScope();
// ... parse contents ...
if (!extractCharacter('}'))
{
recordError(ParseError::Kind::Syntax,
"unterminated block starting here",
braceLine, braceCol);
// leaveScope() intentionally omitted — see Parser::enterScope
}
else
{
leaveScope();
}
}
The filename cannot be overridden — it is always taken from the active cursor. This is why diagnostics emitted while a pushCursor context is active carry the pushed cursor's name.
See also
- ParseError — the record structure being appended.
- Parser::exit — call after
recordErrorwhen the error is fatal. - Parser::errors — read the collector.
- Cursor::getLineNumber, Cursor::getColumnNumber — fallback source when
line/colare zero.

