Friendly error
This is a proof of concept for printing a helper "error indicator" discussed in #153
I made it so that you get the buffer back in this implementation, but a simple print function could be done as well. And I'm not sure if we should use malloc or not?
I added a use in the simple_parser test program for an easy way to test it with different input.
Example output:
Type some JSON > {["a","b","c",]}
Error:
{["a","b","c",]
^~~~~~ (string or '}' expected near '[')
In my opinion using malloc is OK. Another option would be to use a user-supplied buffer, but it's somewhat harder to use.
I'll add diff comments next.
Coverage decreased (-2.81%) when pulling bde5513649b2146d0af65fcf08ebf77746d7eddb on JoakimSoderberg:friendly_error into 58c188e1d5967a1d905acce9beb450204d7da56b on akheron:master.
Hmm so I guess assuming that column was bytes, not utf-8 code points was dumb :)
int column The column on which the error occurred. Note that this is the character column, not the byte column, i.e. a multibyte UTF-8 character counts as one column.
RTFM
Hmm. Even I didn't remember very well, then :)
But if the column already is characters and the console supports UTF-8, should you just print an arrow whose length is the same as column? For example U+00E4 (ä) is \xc3\xa4 when encoded as UTF-8, but (per Jansson's documentation) the column only increments by one in this case.
What's the status of this? IIRC there were some problems with characters vs. bytes which are not very easy to get right, am I correct?
Ah yes, sorry... I kind of lost the steam, my focus has been on this lately: https://github.com/JoakimSoderberg/cargo Inspired by python argparse :)
I will try to get to this eventually.
Ok, no hurry. cargo looks cool :)
I'd appreciate this too, using JSON for config files means hand editing and more error info makes that much easier. But sorry, I don't have time to actually work on the code.
@JoakimSoderberg any chance we might see this PR resolved soon? Like MozLe above, I'm also using JSON for config files, and this would be very useful.