vcall.same_errors.diff

Implementation with additional grammar rules to match existing error messages - Michael Edgar, 07/10/2011 04:55 AM

Download (4.24 KB)

View differences:

parse.y (working copy)
426 426
#define get_value(val) ripper_get_value(val)
427 427
static VALUE assignable_gen(struct parser_params*,VALUE);
428 428
#define assignable(lhs,node) assignable_gen(parser, (lhs))
429
static int id_is_var_gen(struct parser_params *parser, ID id);
430
#define id_is_var(id) id_is_var_gen(parser, (id))
429 431
#endif /* !RIPPER */
430 432

  
431 433
static ID formal_argument_gen(struct parser_params*, ID);
......
699 701
%type <node> lambda f_larglist lambda_body
700 702
%type <node> brace_block cmd_brace_block do_block lhs none fitem
701 703
%type <node> mlhs mlhs_head mlhs_basic mlhs_item mlhs_node mlhs_post mlhs_inner
702
%type <id>   fsym variable sym symbol operation operation2 operation3
704
%type <id>   fsym keyword_variable user_variable sym symbol operation operation2 operation3
703 705
%type <id>   cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
704 706
/*%%%*/
705 707
/*%
......
1601 1603
		    }
1602 1604
		;
1603 1605

  
1604
mlhs_node	: variable
1606
mlhs_node	: user_variable
1605 1607
		    {
1606 1608
			$$ = assignable($1, 0);
1607 1609
		    }
1610
		| keyword_variable
1611
		    {
1612
		        $$ = assignable($1, 0);
1613
		    }
1608 1614
		| primary_value '[' opt_call_args rbracket
1609 1615
		    {
1610 1616
		    /*%%%*/
......
1671 1677
		    }
1672 1678
		;
1673 1679

  
1674
lhs		: variable
1680
lhs		: user_variable
1675 1681
		    {
1676 1682
			$$ = assignable($1, 0);
1677 1683
		    /*%%%*/
......
1680 1686
			$$ = dispatch1(var_field, $$);
1681 1687
		    %*/
1682 1688
		    }
1689
		| keyword_variable
1690
		    {
1691
		        $$ = assignable($1, 0);
1692
		    /*%%%*/
1693
		        if (!$$) $$ = NEW_BEGIN(0);
1694
		    /*%
1695
		        $$ = dispatch1(var_field, $$);
1696
		    %*/
1697
		    }
1683 1698
		| primary_value '[' opt_call_args rbracket
1684 1699
		    {
1685 1700
		    /*%%%*/
......
4257 4272
		    }
4258 4273
		;
4259 4274

  
4260
variable	: tIDENTIFIER
4261
		| tIVAR
4262
		| tGVAR
4263
		| tCONSTANT
4264
		| tCVAR
4265
		| keyword_nil {ifndef_ripper($$ = keyword_nil);}
4266
		| keyword_self {ifndef_ripper($$ = keyword_self);}
4267
		| keyword_true {ifndef_ripper($$ = keyword_true);}
4268
		| keyword_false {ifndef_ripper($$ = keyword_false);}
4269
		| keyword__FILE__ {ifndef_ripper($$ = keyword__FILE__);}
4270
		| keyword__LINE__ {ifndef_ripper($$ = keyword__LINE__);}
4271
		| keyword__ENCODING__ {ifndef_ripper($$ = keyword__ENCODING__);}
4272
		;
4275
keyword_variable : keyword_nil {ifndef_ripper($$ = keyword_nil);}
4276
		 | keyword_self {ifndef_ripper($$ = keyword_self);}
4277
		 | keyword_true {ifndef_ripper($$ = keyword_true);}
4278
		 | keyword_false {ifndef_ripper($$ = keyword_false);}
4279
		 | keyword__FILE__ {ifndef_ripper($$ = keyword__FILE__);}
4280
		 | keyword__LINE__ {ifndef_ripper($$ = keyword__LINE__);}
4281
		 | keyword__ENCODING__ {ifndef_ripper($$ = keyword__ENCODING__);}
4282
		 ;
4273 4283

  
4274
var_ref		: variable
4284
user_variable :	tIDENTIFIER
4285
	      | tIVAR
4286
	      | tGVAR
4287
	      | tCONSTANT
4288
	      | tCVAR
4289
	      ;
4290

  
4291
var_ref		: user_variable
4275 4292
		    {
4276 4293
		    /*%%%*/
4277 4294
			if (!($$ = gettable($1))) $$ = NEW_BEGIN(0);
4278 4295
		    /*%
4279
			$$ = dispatch1(var_ref, $1);
4296
		        if (id_is_var(get_id($1))) {
4297
		          $$ = dispatch1(var_ref, $1);
4298
		        } else {
4299
		          $$ = dispatch1(vcall, $1);
4300
		        }
4280 4301
		    %*/
4281 4302
		    }
4303
		| keyword_variable
4304
		    {
4305
		    /*%%%*/
4306
			if (!($$ = gettable($1))) $$ = NEW_BEGIN(0);
4307
		    /*%
4308
		        $$ = dispatch1(var_ref, $1);
4309
		    %*/
4310
		    }
4282 4311
		;
4283 4312

  
4284
var_lhs		: variable
4313
var_lhs		: user_variable
4285 4314
		    {
4286 4315
			$$ = assignable($1, 0);
4287 4316
		    /*%%%*/
......
4289 4318
			$$ = dispatch1(var_field, $$);
4290 4319
		    %*/
4291 4320
		    }
4321
		| keyword_variable
4322
		    {
4323
		        $$ = assignable($1, 0);
4324
		    /*%%%*/
4325
		    /*%
4326
		        $$ = dispatch1(var_field, $$);
4327
		    %*/
4328
		    }
4292 4329
		;
4293 4330

  
4294 4331
backref		: tNTH_REF
......
7894 7931
    return t;
7895 7932
}
7896 7933

  
7897
#ifndef RIPPER
7934
#ifdef RIPPER
7935

  
7936
static int
7937
id_is_var_gen(struct parser_params *parser, ID id)
7938
{
7939
    if (is_global_id(id) || is_instance_id(id) || is_const_id(id) || is_class_id(id)) {
7940
	return 1;
7941
    }
7942
    else if (is_local_id(id)) {
7943
	if (dyna_in_block() && dvar_defined(id)) return 1;
7944
	if (local_id(id)) return 1;
7945
	/* method call without arguments */
7946
	return 0;
7947
    }
7948
    compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2name(id));
7949
    return 0;
7950
}
7951

  
7952
#else  /* !RIPPER */
7898 7953
static NODE*
7899 7954
node_newnode(struct parser_params *parser, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
7900 7955
{