Defined in header <cparse/Cursor.hh> — since cparse 1.3

unsigned long int getNextLineNumber() const noexcept;
unsigned long int getNextColumnNumber() const noexcept;

Return the one-based position of the character that peek() would return — the next one to be read. getLineNumber() / getColumnNumber() name the character read last; this pair names the one after it.

StategetLineNumber():getColumnNumber()getNextLineNumber():getNextColumnNumber()
nothing read yet0:01:1
last read b in ab on line 11:21:3
last read the '\n' ending line 11:32:1

Parameters

None.

Return value

The line or column of the next unread character, one-based. At end of input: the position just past the last character.

Exceptions

noexcept.

Notes

Parser::recordError() uses this pair when it is given no position, so a diagnostic points at the character the grammar stopped at.

Save the pair before consuming a token when a later diagnostic must point at the token's start — for example a quoted field that turns out to be unterminated:

unsigned long const openLine = getCursor().getNextLineNumber();
unsigned long const openCol  = getCursor().getNextColumnNumber();
getCursor().get();                                   // the opening "
// ... end of input before the closing quote:
recordError(ParseError::Kind::Syntax, "unterminated quoted field",
            openLine, openCol);

Adding 1 to getColumnNumber() is not the same: right after a newline it yields the previous line's length + 1.

Both functions are inline and derived from the cursor's existing state; they do not read from the stream.

See also