Print the file name along with line number on syntax errors; fix
@@ -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;
+ 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));
