sciurius / perl-JSON-Relaxed

An extension of JSON that allows for better human-readability.
0 stars 0 forks source link

Add line or character number offset within JSON::Relaxed::Parser::Token #1

Closed sciurius closed 5 months ago

sciurius commented 7 months ago

Imported from CPAN RT

Hello,

I really like JSON::Relaxed for our config file because it simplifies the end-user's experience while being a familiar format.

I noticed that it is difficult to tell where there is an error (like a missing comma). Would it be possible to include the line number and/or character offset in the JSON::Relaxed::Parser::Token object when being tokenized? This would allow the error functions to report the line number or offset into the string that the error occurred.

It looks like you could retrieve the line number information in the invalid_token sub when returning the error information since most if not all error reports use this function.

For example, if I update invalid_token like so:

Then I can get a little bit more output for an error like the following:

{ foo bar, baz }

unknown-token-after-key: expected comma or closing brace after a hash key, but got string: bar instead

This helps because we know that the problem is near bar, but if we can add line numbers and make it even better that would be great!

Do you have any ideas here that might provide a trivial update for a 0.06 release that would annotate the error messages as such?

-- Eric Wheeler

sciurius commented 5 months ago

Added in 0.090.