diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-06-15 15:46:03 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-06-15 15:46:03 +0900 |
| commit | d7e09ffa5f890f7508da7d3cf82f3d0285d033ca (patch) | |
| tree | e036de0d45b8b778c352d9522fe43023fe7be07e /mrbgems/mruby-eval/src/eval.c | |
| parent | 47bd44fce1a441919595de9000ced6f871973b70 (diff) | |
| download | mruby-d7e09ffa5f890f7508da7d3cf82f3d0285d033ca.tar.gz mruby-d7e09ffa5f890f7508da7d3cf82f3d0285d033ca.zip | |
Print the file name along with line number on syntax errors; fix #3698
Diffstat (limited to 'mrbgems/mruby-eval/src/eval.c')
| -rw-r--r-- | mrbgems/mruby-eval/src/eval.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/mrbgems/mruby-eval/src/eval.c b/mrbgems/mruby-eval/src/eval.c index 54a6aab2e..537e8541e 100644 --- a/mrbgems/mruby-eval/src/eval.c +++ b/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)); |
