diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-19 05:46:20 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-03-19 05:46:20 +0000 |
commit | bc343b851d04f68ef7554a2cca0bad63a32c2b7d (patch) | |
tree | 34701ea26f297294c1ab55561610227fcd761eba /error.c | |
parent | 22198f9d3c384dbc3e95b953d71a07de12da652b (diff) | |
download | ruby-bc343b851d04f68ef7554a2cca0bad63a32c2b7d.tar.gz |
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
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 67 |
1 files changed, 16 insertions, 51 deletions
@@ -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 |