mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
51c195948f
commit
97177a2d99
5 changed files with 29 additions and 17 deletions
11
ChangeLog
11
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>
|
Tue Apr 19 17:42:47 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* error.c (err_vcatf): rename, and separate appending message from
|
* error.c (err_vcatf): rename, and separate appending message from
|
||||||
|
|
|
@ -318,18 +318,11 @@ static void
|
||||||
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...)
|
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
|
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
|
||||||
VALUE str = rb_attr_get(err_info, idMesg);
|
|
||||||
VALUE file = iseq->body->location.path;
|
VALUE file = iseq->body->location.path;
|
||||||
va_list args;
|
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);
|
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);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
error.c
16
error.c
|
@ -104,12 +104,18 @@ rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
|
||||||
rb_str_cat2(mesg, "\n");
|
rb_str_cat2(mesg, "\n");
|
||||||
rb_write_error_str(mesg);
|
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 {
|
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;
|
return exc;
|
||||||
|
|
|
@ -852,6 +852,7 @@ extern VALUE rb_eEWOULDBLOCK;
|
||||||
extern VALUE rb_eEINPROGRESS;
|
extern VALUE rb_eEINPROGRESS;
|
||||||
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args);
|
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);
|
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);
|
VALUE rb_check_backtrace(VALUE);
|
||||||
NORETURN(void rb_async_bug_errno(const char *,int));
|
NORETURN(void rb_async_bug_errno(const char *,int));
|
||||||
const char *rb_builtin_type_name(int t);
|
const char *rb_builtin_type_name(int t);
|
||||||
|
|
9
parse.y
9
parse.y
|
@ -5550,8 +5550,11 @@ yycompile0(VALUE arg)
|
||||||
lex_lastline = lex_nextline = 0;
|
lex_lastline = lex_nextline = 0;
|
||||||
if (parser->error_p) {
|
if (parser->error_p) {
|
||||||
VALUE mesg = parser->error_buffer;
|
VALUE mesg = parser->error_buffer;
|
||||||
if (!mesg) mesg = rb_fstring_cstr("compile error");
|
if (!mesg) {
|
||||||
rb_set_errinfo(rb_exc_new_str(rb_eSyntaxError, mesg));
|
mesg = rb_fstring_cstr("compile error");
|
||||||
|
mesg = rb_exc_new_str(rb_eSyntaxError, mesg);
|
||||||
|
}
|
||||||
|
rb_set_errinfo(mesg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
tree = ruby_eval_tree;
|
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
|
static void
|
||||||
parser_compile_error(struct parser_params *parser, const char *fmt, ...)
|
parser_compile_error(struct parser_params *parser, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue