From bc343b851d04f68ef7554a2cca0bad63a32c2b7d Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 19 Mar 2016 05:46:20 +0000 Subject: SyntaxError message at iseq compile * iseq.c (rb_iseq_compile_with_option): make the parser in mild error. * load.c (rb_load_internal0): ditto. * parse.y (yycompile0): return the error message within the error to be raised. [Feature #11951] * parse.y (parser_compile_error): accumulate error messages in the error_buffer. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- error.c | 67 ++++++++++++++++------------------------------------------------- 1 file changed, 16 insertions(+), 51 deletions(-) (limited to 'error.c') diff --git a/error.c b/error.c index 93cb6f03d6..6bd45bd021 100644 --- a/error.c +++ b/error.c @@ -94,88 +94,53 @@ compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, return str; } -static void -compile_err_append(VALUE mesg) +VALUE +rb_compile_err_append(VALUE buffer, VALUE mesg) { rb_thread_t *th = GET_THREAD(); - VALUE err = th->errinfo; rb_block_t *prev_base_block = th->base_block; th->base_block = 0; /* base_block should be zero while normal Ruby execution */ /* after this line, any Ruby code *can* run */ - if (th->mild_compile_error) { - if (RTEST(err)) { - VALUE str = rb_obj_as_string(err); - - rb_str_cat2(str, "\n"); - rb_str_append(str, mesg); - mesg = str; - } - err = rb_exc_new3(rb_eSyntaxError, mesg); - th->errinfo = err; - } - else { - if (!RTEST(err)) { - err = rb_exc_new2(rb_eSyntaxError, "compile error"); - th->errinfo = err; - } + if (!buffer) { rb_str_cat2(mesg, "\n"); rb_write_error_str(mesg); } + else if (NIL_P(buffer)) { + buffer = mesg; + } + else { + rb_str_cat2(buffer, "\n"); + rb_str_append(buffer, mesg); + } /* returned to the parser world */ th->base_block = prev_base_block; + return buffer; } void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...) { - va_list args; - VALUE str; - - va_start(args, fmt); - str = compile_snprintf(enc, NULL, file, line, fmt, args); - va_end(args); - compile_err_append(str); } void rb_compile_error(const char *file, int line, const char *fmt, ...) { - va_list args; - VALUE str; - - va_start(args, fmt); - str = compile_snprintf(NULL, NULL, file, line, fmt, args); - va_end(args); - compile_err_append(str); } -void -rb_compile_error_str(VALUE file, int line, void *enc, const char *fmt, ...) +VALUE +rb_error_vsprintf(VALUE file, int line, void *enc, const char *fmt, va_list args) { - va_list args; - VALUE str; - - va_start(args, fmt); - str = compile_snprintf(enc, NULL, - NIL_P(file) ? NULL : RSTRING_PTR(file), line, - fmt, args); - va_end(args); - compile_err_append(str); + return compile_snprintf(enc, NULL, + NIL_P(file) ? NULL : RSTRING_PTR(file), line, + fmt, args); } void rb_compile_error_append(const char *fmt, ...) { - va_list args; - VALUE str; - - va_start(args, fmt); - str = rb_vsprintf(fmt, args); - va_end(args); - compile_err_append(str); } static void -- cgit v1.2.3