ruby-changes:49414
From: nobu <ko1@a...>
Date: Mon, 1 Jan 2018 00:05:30 +0900 (JST)
Subject: [ruby-changes:49414] nobu:r61530 (trunk): parse.y: yyerror1
nobu 2018-01-01 00:05:26 +0900 (Mon, 01 Jan 2018) New Revision: 61530 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61530 Log: parse.y: yyerror1 * parse.y (yyerror1): pass location to parser_yyerror. Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 61529) +++ parse.y (revision 61530) @@ -292,6 +292,7 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/parse.y#L292 static int parser_yyerror(struct parser_params*, const YYLTYPE *yylloc, const char*); #define yyerror0(msg) parser_yyerror(parser, NULL, (msg)) +#define yyerror1(loc, msg) parser_yyerror(parser, (loc), (msg)) #define yyerror(yylloc, parser, msg) parser_yyerror(parser, yylloc, msg) #define token_flush(p) ((p)->lex.ptok = (p)->lex.pcur) @@ -1339,7 +1340,7 @@ stmt_or_begin : stmt https://github.com/ruby/ruby/blob/trunk/parse.y#L1340 } | keyword_BEGIN { - yyerror0("BEGIN is permitted only at toplevel"); + yyerror1(&@1, "BEGIN is permitted only at toplevel"); /*%%%*/ /* local_push(0); */ /*% @@ -1392,7 +1393,7 @@ stmt : keyword_alias fitem {SET_LEX_STA https://github.com/ruby/ruby/blob/trunk/parse.y#L1393 | keyword_alias tGVAR tNTH_REF { /*%%%*/ - yyerror0("can't make alias for the number variables"); + yyerror1(&@3, "can't make alias for the number variables"); $$ = new_begin(0, &@$); /*% $$ = dispatch2(var_alias, $2, $3); @@ -2039,7 +2040,7 @@ lhs : user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L2040 cname : tIDENTIFIER { /*%%%*/ - yyerror0("class/module name must be CONSTANT"); + yyerror1(&@1, "class/module name must be CONSTANT"); /*% $$ = dispatch1(class_name_error, $1); ripper_error(); @@ -2975,8 +2976,12 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2976 } | k_class cpath superclass { - if (in_def) - yyerror0("class definition in method body"); + if (in_def) { + YYLTYPE location; + location.first_loc = @1.first_loc; + location.last_loc = @2.last_loc; + yyerror1(&location, "class definition in method body"); + } $<num>1 = in_class; in_class = 1; local_push(0); @@ -3026,8 +3031,12 @@ primary : literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3031 } | k_module cpath { - if (in_def) - yyerror0("module definition in method body"); + if (in_def) { + YYLTYPE location; + location.first_loc = @1.first_loc; + location.last_loc = @2.last_loc; + yyerror1(&location, "module definition in method body"); + } $<num>1 = in_class; in_class = 1; local_push(0); @@ -3235,7 +3244,7 @@ k_end : keyword_end https://github.com/ruby/ruby/blob/trunk/parse.y#L3244 k_return : keyword_return { if (in_class && !in_def && !dyna_in_block()) - yyerror0("Invalid return in class/module body"); + yyerror1(&@1, "Invalid return in class/module body"); } ; @@ -4591,7 +4600,7 @@ f_args : f_arg ',' f_optarg ',' f_rest_ https://github.com/ruby/ruby/blob/trunk/parse.y#L4600 f_bad_arg : tCONSTANT { /*%%%*/ - yyerror0("formal argument cannot be a constant"); + yyerror1(&@1, "formal argument cannot be a constant"); $$ = 0; /*% $$ = dispatch1(param_error, $1); @@ -4601,7 +4610,7 @@ f_bad_arg : tCONSTANT https://github.com/ruby/ruby/blob/trunk/parse.y#L4610 | tIVAR { /*%%%*/ - yyerror0("formal argument cannot be an instance variable"); + yyerror1(&@1, "formal argument cannot be an instance variable"); $$ = 0; /*% $$ = dispatch1(param_error, $1); @@ -4611,7 +4620,7 @@ f_bad_arg : tCONSTANT https://github.com/ruby/ruby/blob/trunk/parse.y#L4620 | tGVAR { /*%%%*/ - yyerror0("formal argument cannot be a global variable"); + yyerror1(&@1, "formal argument cannot be a global variable"); $$ = 0; /*% $$ = dispatch1(param_error, $1); @@ -4621,7 +4630,7 @@ f_bad_arg : tCONSTANT https://github.com/ruby/ruby/blob/trunk/parse.y#L4630 | tCVAR { /*%%%*/ - yyerror0("formal argument cannot be a class variable"); + yyerror1(&@1, "formal argument cannot be a class variable"); $$ = 0; /*% $$ = dispatch1(param_error, $1); @@ -4884,7 +4893,7 @@ f_rest_arg : restarg_mark tIDENTIFIER https://github.com/ruby/ruby/blob/trunk/parse.y#L4893 { /*%%%*/ if (!is_local_id($2)) - yyerror0("rest argument must be local variable"); + yyerror1(&@2, "rest argument must be local variable"); /*% %*/ arg_var(shadowing_lvar(get_id($2))); /*%%%*/ @@ -4912,9 +4921,9 @@ f_block_arg : blkarg_mark tIDENTIFIER https://github.com/ruby/ruby/blob/trunk/parse.y#L4921 { /*%%%*/ if (!is_local_id($2)) - yyerror0("block argument must be local variable"); + yyerror1(&@2, "block argument must be local variable"); else if (!dyna_in_block() && local_id($2)) - yyerror0("duplicated block argument name"); + yyerror1(&@2, "duplicated block argument name"); /*% %*/ arg_var(shadowing_lvar(get_id($2))); /*%%%*/ @@ -4953,7 +4962,7 @@ singleton : var_ref https://github.com/ruby/ruby/blob/trunk/parse.y#L4962 { /*%%%*/ if ($3 == 0) { - yyerror0("can't define singleton method for ()."); + yyerror1(&@2, "can't define singleton method for ()."); } else { switch (nd_type($3)) { @@ -4965,7 +4974,7 @@ singleton : var_ref https://github.com/ruby/ruby/blob/trunk/parse.y#L4974 case NODE_LIT: case NODE_ARRAY: case NODE_ZARRAY: - yyerror0("can't define singleton method for literals"); + yyerror1(&@2, "can't define singleton method for literals"); break; default: value_expr($3); @@ -9985,25 +9994,25 @@ assignable_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9994 if (!id) return assignable_error(); switch (id) { case keyword_self: - yyerror0("Can't change the value of self"); + yyerror1(location, "Can't change the value of self"); goto error; case keyword_nil: - yyerror0("Can't assign to nil"); + yyerror1(location, "Can't assign to nil"); goto error; case keyword_true: - yyerror0("Can't assign to true"); + yyerror1(location, "Can't assign to true"); goto error; case keyword_false: - yyerror0("Can't assign to false"); + yyerror1(location, "Can't assign to false"); goto error; case keyword__FILE__: - yyerror0("Can't assign to __FILE__"); + yyerror1(location, "Can't assign to __FILE__"); goto error; case keyword__LINE__: - yyerror0("Can't assign to __LINE__"); + yyerror1(location, "Can't assign to __LINE__"); goto error; case keyword__ENCODING__: - yyerror0("Can't assign to __ENCODING__"); + yyerror1(location, "Can't assign to __ENCODING__"); goto error; } switch (id_type(id)) { @@ -10037,7 +10046,7 @@ assignable_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L10046 case ID_CONST: if (!in_def) return assignable_result(new_cdecl(id, val, 0, location)); - yyerror0("dynamic constant assignment"); + yyerror1(location, "dynamic constant assignment"); break; case ID_CLASS: return assignable_result(NEW_CVASGN(id, val)); @@ -10280,7 +10289,7 @@ value_expr_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L10289 case NODE_NEXT: case NODE_REDO: case NODE_RETRY: - if (!cond) yyerror0("void value expression"); + if (!cond) yyerror1(&node->nd_loc, "void value expression"); /* or "control never reach"? */ return FALSE; @@ -11093,7 +11102,7 @@ static NODE * https://github.com/ruby/ruby/blob/trunk/parse.y#L11102 const_decl_gen(struct parser_params *parser, NODE *path, const YYLTYPE *location) { if (in_def) { - yyerror0("dynamic constant assignment"); + yyerror1(location, "dynamic constant assignment"); } return new_cdecl(0, 0, (path), location); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/