Permalink
Browse files

Print the file name along with line number on syntax errors; fix #3698

  • Loading branch information...
matz committed Jun 15, 2017
1 parent 47bd44f commit d7e09ffa5f890f7508da7d3cf82f3d0285d033ca
Showing with 12 additions and 7 deletions.
  1. +12 −7 mrbgems/mruby-eval/src/eval.c
@@ -160,10 +160,7 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, con
cxt = mrbc_context_new(mrb);
cxt->lineno = line;
if (!file) {
file = "(eval)";
}
mrbc_filename(mrb, cxt, file);
mrbc_filename(mrb, cxt, file ? file : "(eval)");
cxt->capture_errors = TRUE;
cxt->no_optimize = TRUE;
@@ -178,9 +175,17 @@ create_proc_from_string(mrb_state *mrb, char *s, int len, mrb_value binding, con
/* parse error */
mrb_value str;
str = mrb_format(mrb, "line %S: %S",
mrb_fixnum_value(p->error_buffer[0].lineno),
mrb_str_new_cstr(mrb, p->error_buffer[0].message));
if (file) {
str = mrb_format(mrb, " file %S line %S: %S",
mrb_str_new_cstr(mrb, file),
mrb_fixnum_value(p->error_buffer[0].lineno),
mrb_str_new_cstr(mrb, p->error_buffer[0].message));
}
else {
str = mrb_format(mrb, " line %S: %S",
mrb_fixnum_value(p->error_buffer[0].lineno),
mrb_str_new_cstr(mrb, p->error_buffer[0].message));
}
mrb_parser_free(p);
mrbc_context_free(mrb, cxt);
mrb_exc_raise(mrb, mrb_exc_new_str(mrb, E_SYNTAX_ERROR, str));

0 comments on commit d7e09ff

Please sign in to comment.