aboutsummaryrefslogtreecommitdiffstats
path: root/error.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-19 08:42:50 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-19 08:42:50 +0000
commit0818b7d4ad638b5d30d7d4b6ddb86ab7c942744d (patch)
treea4df94058a4eb2ffee9c16426b4921b3870c26bd /error.c
parentde64e17f662930452708c4ab104491cf097f6b09 (diff)
downloadruby-0818b7d4ad638b5d30d7d4b6ddb86ab7c942744d.tar.gz
refactor parser error
* error.c (err_vcatf): rename, and separate appending message from creating a string buffer. * error.c (rb_syntax_error_append): merge rb_error_vsprintf and rb_compile_err_append. * parse.y (parser_compile_error): use rb_syntax_error_append. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/error.c b/error.c
index 36a1bf5da7..6a8111085a 100644
--- a/error.c
+++ b/error.c
@@ -80,10 +80,9 @@ err_position_0(char *buf, long len, const char *file, int line)
}
static VALUE
-compile_vsprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
+err_vcatf(VALUE str, const char *pre, const char *file, int line,
+ const char *fmt, va_list args)
{
- VALUE str = rb_enc_str_new(0, 0, enc);
-
if (file) {
rb_str_cat2(str, file);
if (line) rb_str_catf(str, ":%d", line);
@@ -95,21 +94,25 @@ compile_vsprintf(rb_encoding *enc, const char *pre, const char *file, int line,
}
VALUE
-rb_compile_err_append(VALUE buffer, VALUE mesg)
+rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
+ rb_encoding *enc, const char *fmt, va_list args)
{
- if (!buffer) {
+ const char *fn = NIL_P(file) ? NULL : RSTRING_PTR(file);
+ if (!exc) {
+ VALUE mesg = rb_enc_str_new(0, 0, enc);
+ err_vcatf(mesg, NULL, fn, line, fmt, args);
rb_str_cat2(mesg, "\n");
rb_write_error_str(mesg);
}
- else if (NIL_P(buffer)) {
- buffer = 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 {
- rb_str_cat2(buffer, "\n");
- rb_str_append(buffer, mesg);
+ err_vcatf(exc, "\n", fn, line, fmt, args);
}
- return buffer;
+ return exc;
}
void
@@ -122,14 +125,6 @@ rb_compile_error(const char *file, int line, const char *fmt, ...)
{
}
-VALUE
-rb_error_vsprintf(VALUE file, int line, void *enc, const char *fmt, va_list args)
-{
- return compile_vsprintf(enc, NULL,
- NIL_P(file) ? NULL : RSTRING_PTR(file), line,
- fmt, args);
-}
-
void
rb_compile_error_append(const char *fmt, ...)
{
@@ -138,9 +133,9 @@ rb_compile_error_append(const char *fmt, ...)
static VALUE
warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
{
- VALUE str;
+ VALUE str = rb_enc_str_new(0, 0, enc);
- str = compile_vsprintf(enc, "warning: ", file, line, fmt, args);
+ err_vcatf(str, "warning: ", file, line, fmt, args);
return rb_str_cat2(str, "\n");
}