aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-19 05:46:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-19 05:46:20 +0000
commitaedece589291dc8be6350935f432376a9b4a212b (patch)
tree34701ea26f297294c1ab55561610227fcd761eba /error.c
parente91339cd217f7353d71498c04fb824a7f4c93c2f (diff)
downloadruby-aedece589291dc8be6350935f432376a9b4a212b.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.c67
1 files changed, 16 insertions, 51 deletions
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