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 getLineNumber() / getColumnNumber().

Does not terminate the parse — call exit() separately if the error is fatal.

Parameters

ParameterDescription
kindOne of the ParseError::Kind enumerators.
messageThe diagnostic text. No format prescribed.
lineOptional. 0 (default) means "use the active cursor's line number".
colOptional. 0 (default) means "use the active cursor's column number".

Return value

(none)

Exceptions

May propagate std::bad_alloc from the internal std::vector::push_back. Does not throw otherwise.

Notes

Passing explicit line and col is useful when the diagnostic refers to a construct that started earlier in the file. 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