Output position when JSON parser fails
Chlumsky opened this issue · 1 comments
Chlumsky commented
The generated parser should report the postition within the input string if parsing fails. This is simply cur - jsonString. To achieve this, Error must be a structure containing both the error code and position. The current enumeration can be renamed to ErrorType. Proposed error structure:
struct Error {
ErrorType type;
int position;
inline Error(ErrorType type = OK, int position = -1) : type(type), position(position) { }
operator ErrorType() const;
operator bool() const;
};For serializers, reporting the source of error would be tricky because it is an element within a structure. Providing a pointer to the faulty element would be possible but probably not too helpful, because it isn't enough to easily find it within the structure tree. Still, serializers' error enumeration should also be renamed to ErrorType for consistency (with a possibility of typedef ErrorType Error;.