Defined in header <cparse/Parser.hh>
protected:
void writeTraceMessage();
Writes to std::clog:
- The active cursor's filename, line and column.
- Up to three lines of characters read from the cursor starting at the current position, non-printable characters replaced with spaces.
Intended for debugging a grammar during development. Not called by the base implementation itself — grammars call it explicitly when they want to log context around an unexpected state.
Parameters
None.
Return value
(none)
Exceptions
May throw from Cursor::get() if the stream is in an unrecoverable state. The method uses the throwing Cursor::get internally (not the safe variant), because the trace loop deliberately stops at EOF via the exception.
Notes
This method consumes input. The three-line preview is read via Cursor::get(), which advances the cursor. After calling writeTraceMessage(), the cursor is no longer at the position it reported. If you need to trace a location without disturbing the parse, save and restore the cursor around the call:
Cursor snapshot = getCursor();
writeTraceMessage();
restoreCursor(snapshot);
Output is written to std::clog, not std::cerr, so it can be directed independently in the calling application.
See also
- Parser::getGrammarName — for a grammar label to include alongside trace output.
- Cursor::getFilename, Cursor::getLineNumber, Cursor::getColumnNumber — the location fields printed.

