Return lineno:column alongside error messages#18
Return lineno:column alongside error messages#18
Conversation
src/parser.c
Outdated
| _fallthrough_; | ||
| case KDL_TOKEN_NEWLINE: | ||
| case KDL_TOKEN_SEMICOLON: | ||
| current_line_number++; |
There was a problem hiding this comment.
I'm guessing this will give incorrect line numbers after any semicolon
|
Hi! Thanks for giving this a go! Without having tested it, I would assume that this sometimes gives incorrect line numbers (particularly when there are semicolons involved) and usually gives incorrect column numbers (since the code appears to assume that 1 token = 1 character, which is normally not true) I think that the tokenizer would have to keep track of (and return) the line and column for each token for the numbers to be correct. |
|
OK I'll admit my last PR was a half assed effort. Here's my updated PR.
Reverting back last PR:
I feel like i still miss something, feel free to point me out |
This PR adds additioinal line number and column information on error messages.
What I've done in this PR was declaring static int variable in
parser.cnamedcurrent_line_numberandcurrent_column_number, Theese variables value initialized with 1.Every
kdl_parser_next_event()loop I increase value ofcurrent_column_number.Every time parser find
KDL_TOKEN_NEWLINE,current_line_numberis increased andcurrent_column_numberreset back to 1.Then finally inside
_set_parse_error()I allocate new string then format it using snprintf prependingcurrent_line_numbercurrent_column_numberinto final error message