Skip to content
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

Conversation

LaszloLango
Copy link
Contributor

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

@LaszloLango LaszloLango force-pushed the print-error-location-context branch from bf5a5af to 4114289 Compare October 20, 2016 10:21
@LaszloLango LaszloLango added enhancement An improvement parser Related to the JavaScript parser labels Oct 20, 2016
}

jerry_size_t err_str_size = jerry_get_string_size (error_name);
jerry_char_t err_str_buf[32];
Copy link
Member

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 */
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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

Copy link
Contributor Author

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.

@LaszloLango LaszloLango force-pushed the print-error-location-context branch from 4114289 to 84649e8 Compare October 21, 2016 07:21
@zherczeg
Copy link
Member

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
@LaszloLango LaszloLango force-pushed the print-error-location-context branch from 84649e8 to fc89f96 Compare October 21, 2016 08:37
@dbatyai
Copy link
Member

dbatyai commented Oct 25, 2016

LGTM

@LaszloLango LaszloLango merged commit dc1e269 into jerryscript-project:master Oct 25, 2016
@LaszloLango LaszloLango deleted the print-error-location-context branch January 19, 2017 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement parser Related to the JavaScript parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants