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 | aedece589291dc8be6350935f432376a9b4a212b (patch) | |
tree | 34701ea26f297294c1ab55561610227fcd761eba /parse.y | |
parent | e91339cd217f7353d71498c04fb824a7f4c93c2f (diff) | |
download | ruby-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 'parse.y')
-rw-r--r-- | parse.y | 41 |
1 files changed, 37 insertions, 4 deletions
@@ -312,6 +312,7 @@ struct parser_params { NODE *eval_tree_begin; NODE *eval_tree; + VALUE error_buffer; VALUE debug_lines; VALUE coverage; #else @@ -740,7 +741,6 @@ static ID id_warn, id_warning; # define WARNING_ARGS_L(l, fmt,n) WARNING_ARGS(fmt,n) # define WARNING_CALL rb_funcall static void ripper_compile_error(struct parser_params*, const char *fmt, ...); -# define rb_compile_error ripper_compile_error # define compile_error ripper_compile_error # define PARSER_ARG parser, #else @@ -753,9 +753,9 @@ static void ripper_compile_error(struct parser_params*, const char *fmt, ...); # define WARNING_ARGS(fmt,n) WARN_ARGS(fmt,n) # define WARNING_ARGS_L(l,fmt,n) WARN_ARGS_L(l,fmt,n) # define WARNING_CALL rb_compile_warning -# define rb_compile_error rb_compile_error_str -# define compile_error (parser->error_p = 1),rb_compile_error_str -# define PARSER_ARG ruby_sourcefile_string, ruby_sourceline, (void *)current_enc, +static void parser_compile_error(struct parser_params*, const char *fmt, ...); +# define compile_error parser_compile_error +# define PARSER_ARG parser, #endif /* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150, @@ -5559,6 +5559,9 @@ yycompile0(VALUE arg) lex_p = lex_pbeg = lex_pend = 0; 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)); return 0; } tree = ruby_eval_tree; @@ -10792,6 +10795,8 @@ parser_initialize(struct parser_params *parser) parser->delayed = Qnil; parser->result = Qnil; parser->parsing_thread = Qnil; +#else + parser->error_buffer = Qfalse; #endif parser->debug_buffer = Qnil; parser->enc = rb_utf8_encoding(); @@ -10818,6 +10823,7 @@ parser_mark(void *ptr) rb_gc_mark((VALUE)ruby_eval_tree); rb_gc_mark(ruby_debug_lines); rb_gc_mark(parser->compile_option); + rb_gc_mark(parser->error_buffer); #else rb_gc_mark(parser->delayed); rb_gc_mark(parser->value); @@ -10901,6 +10907,16 @@ rb_parser_new(void) parser_initialize(p); return parser; } + +VALUE +rb_parser_mild_error(VALUE vparser) +{ + struct parser_params *parser; + + TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser); + parser->error_buffer = Qnil; + return vparser; +} #endif #ifdef RIPPER @@ -11069,6 +11085,23 @@ rb_parser_printf(struct parser_params *parser, const char *fmt, ...) parser->debug_buffer = Qnil; } } + +extern VALUE rb_error_vsprintf(VALUE, int, void *, const char *, va_list); +extern VALUE rb_compile_err_append(VALUE buffer, VALUE mesg); + +static void +parser_compile_error(struct parser_params *parser, const char *fmt, ...) +{ + VALUE str; + va_list ap; + + parser->error_p = 1; + va_start(ap, fmt); + str = rb_error_vsprintf(ruby_sourcefile_string, ruby_sourceline, + (void *)current_enc, fmt, ap); + va_end(ap); + parser->error_buffer = rb_compile_err_append(parser->error_buffer, str); +} #endif #ifdef RIPPER |