aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-20 01:25:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-20 01:25:55 +0000
commit97177a2d99f7c38d6085ccba343a980031aec7cf (patch)
tree006f7d88aff9629cb1fae9cc244afec1fb0b1ec8
parent51c195948f32e86226d2a45f810e2d830b573435 (diff)
downloadruby-97177a2d99f7c38d6085ccba343a980031aec7cf.tar.gz
refactor syntax error
* compile.c (append_compile_error): use rb_syntax_error_append. * error.c (rb_syntax_error_append): append messages into a SyntaxError exception instance. * parse.y (yycompile0): make new SyntaxError instance in main mode, otherwize error_buffer should be a SyntaxError if error has occurred. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--compile.c9
-rw-r--r--error.c16
-rw-r--r--internal.h1
-rw-r--r--parse.y9
5 files changed, 29 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 344962a89a..3155dfe855 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed Apr 20 10:25:53 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * compile.c (append_compile_error): use rb_syntax_error_append.
+
+ * error.c (rb_syntax_error_append): append messages into a
+ SyntaxError exception instance.
+
+ * parse.y (yycompile0): make new SyntaxError instance in main
+ mode, otherwize error_buffer should be a SyntaxError if error
+ has occurred.
+
Tue Apr 19 17:42:47 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (err_vcatf): rename, and separate appending message from
diff --git a/compile.c b/compile.c
index 0f319b7ce8..63be63c13d 100644
--- a/compile.c
+++ b/compile.c
@@ -318,18 +318,11 @@ static void
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...)
{
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
- VALUE str = rb_attr_get(err_info, idMesg);
VALUE file = iseq->body->location.path;
va_list args;
- if (RSTRING_LEN(str)) rb_str_cat2(str, "\n");
- if (file) {
- rb_str_concat(str, file);
- if (line) rb_str_catf(str, ":%d", line);
- rb_str_cat2(str, ": ");
- }
va_start(args, fmt);
- rb_str_vcatf(str, fmt, args);
+ rb_syntax_error_append(err_info, file, line, -1, NULL, fmt, args);
va_end(args);
}
diff --git a/error.c b/error.c
index 6a8111085a..89858719c1 100644
--- a/error.c
+++ b/error.c
@@ -104,12 +104,18 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
rb_str_cat2(mesg, "\n");
rb_write_error_str(mesg);
}
- else if (NIL_P(exc)) {
- VALUE mesg = rb_enc_str_new(0, 0, enc);
- exc = err_vcatf(mesg, NULL, fn, line, fmt, args);
- }
else {
- err_vcatf(exc, "\n", fn, line, fmt, args);
+ VALUE mesg;
+ const char *pre = NULL;
+ if (NIL_P(exc)) {
+ mesg = rb_enc_str_new(0, 0, enc);
+ exc = rb_class_new_instance(1, &mesg, rb_eSyntaxError);
+ }
+ else {
+ mesg = rb_attr_get(exc, idMesg);
+ pre = "\n";
+ }
+ err_vcatf(mesg, pre, fn, line, fmt, args);
}
return exc;
diff --git a/internal.h b/internal.h
index 126410796e..f3767110cc 100644
--- a/internal.h
+++ b/internal.h
@@ -852,6 +852,7 @@ extern VALUE rb_eEWOULDBLOCK;
extern VALUE rb_eEINPROGRESS;
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
PRINTF_ARGS(void rb_compile_error_str(VALUE file, int line, void *enc, const char *fmt, ...), 4, 5);
+VALUE rb_syntax_error_append(VALUE, VALUE, int, int, rb_encoding*, const char*, va_list);
VALUE rb_check_backtrace(VALUE);
NORETURN(void rb_async_bug_errno(const char *,int));
const char *rb_builtin_type_name(int t);
diff --git a/parse.y b/parse.y
index 2243f69765..56f4d837c5 100644
--- a/parse.y
+++ b/parse.y
@@ -5550,8 +5550,11 @@ yycompile0(VALUE arg)
lex_lastline = lex_nextline = 0;
if (parser->error_p) {
VALUE mesg = parser->error_buffer;
- if (!mesg) mesg = rb_fstring_cstr("compile error");
- rb_set_errinfo(rb_exc_new_str(rb_eSyntaxError, mesg));
+ if (!mesg) {
+ mesg = rb_fstring_cstr("compile error");
+ mesg = rb_exc_new_str(rb_eSyntaxError, mesg);
+ }
+ rb_set_errinfo(mesg);
return 0;
}
tree = ruby_eval_tree;
@@ -11074,8 +11077,6 @@ rb_parser_printf(struct parser_params *parser, const char *fmt, ...)
}
}
-extern VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args);
-
static void
parser_compile_error(struct parser_params *parser, const char *fmt, ...)
{