Defined in header <cparse/Parser.hh>

protected:
void restoreCursor( Cursor const& crs );

Assigns crs to the active cursor via Cursor::operator= and calls Cursor::restore() to seek the underlying stream back to the saved position.

Used internally by extractToken to back out of a partial match.

Parameters

ParameterDescription
crsThe saved cursor to restore from. Typically the return of a previous storeCursor call, or an explicit copy of the active cursor.

Return value

(none)

Exceptions

May throw if Cursor::restore() throws — the underlying seek is subject to the stream's exception mask. If the stream is in an EOF or fail state, restore may throw; in that case grammars should use Cursor::safeRestore() manually on the active cursor after this call.

Notes

Together with storeCursor(), this is the low-level backtracking primitive. For most grammars, extractToken() already handles the save-try-restore cycle and neither storeCursor nor restoreCursor need to be called directly.

Grammars that implement recovery beyond what extractToken provides — for example, speculatively parsing a longer alternative and rolling back several tokens — use the copy-and-assign form:

Cursor snapshot = getCursor();
size_t const errCountBefore = errors().size();

if (!parseLongAlternative())
{
    restoreCursor(snapshot);
    while (errors().size() > errCountBefore)
        /* trim speculative errors — no built-in helper for this */;
    parseShortAlternative();
}

See also