-
Notifications
You must be signed in to change notification settings - Fork 679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Print source code with a given context when a parse error happens #1403
Print source code with a given context when a parse error happens #1403
Conversation
bf5a5af
to
4114289
Compare
} | ||
|
||
jerry_size_t err_str_size = jerry_get_string_size (error_name); | ||
jerry_char_t err_str_buf[32]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get the size, but the buf is only 32 bytes long.
|
||
if (strncmp ((char *) (err_str_buf + i), ", column: ", 10)) | ||
{ | ||
break; /* wrong position info format */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can simply return here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, break is better here, because on a return there is no error message printing, so if you don't check the exit value, then you don't even notice the program failure. Check the end of the function.
|
||
if (err_line != 0 && err_col != 0) | ||
{ | ||
uint32_t curr_line = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably go to the position with a loop, then break, print 2*context_size lines and that is all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it will be much simpler, because we still have to check a few special case when we cannot print 2*context_size.
4114289
to
84649e8
Compare
Hm ok. This is a utility function anyway, might be not worth to overdo this. LGTM |
Example source: var s = "hello"; if (s) a[,] = s; Output: var s = "hello"; if (s) a[,] = s; ~~~~^ Script Error: SyntaxError: Primary expression expected. [line: 3, column: 5] JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
84649e8
to
fc89f96
Compare
LGTM |
Example source:
Output:
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com