[前][次][番号順一覧][スレッド一覧]

ruby-changes:43787

From: nobu <ko1@a...>
Date: Thu, 11 Aug 2016 11:20:38 +0900 (JST)
Subject: [ruby-changes:43787] nobu:r55860 (trunk): parse.y: backref_assign_error

nobu	2016-08-11 11:20:34 +0900 (Thu, 11 Aug 2016)

  New Revision: 55860

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55860

  Log:
    parse.y: backref_assign_error
    
    * parse.y (backref_assign_error): unify parser and ripper code.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 55859)
+++ parse.y	(revision 55860)
@@ -492,6 +492,9 @@ static NODE *new_const_op_assign_gen(str https://github.com/ruby/ruby/blob/trunk/parse.y#L492
 	((in_def || in_single) ? yyerror("dynamic constant assignment") : (void)0), \
 	NEW_CDECL(0, 0, (path)))
 
+#define var_field(n) (n)
+#define backref_assign_error(n, a) (rb_backref_error(n), NEW_BEGIN(0))
+
 static NODE *kwd_append(NODE*, NODE*);
 
 static NODE *new_hash_gen(struct parser_params *parser, NODE *hash);
@@ -560,6 +563,10 @@ static VALUE new_attr_op_assign_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L563
 static VALUE const_decl_gen(struct parser_params *parser, VALUE path);
 #define const_decl(path) const_decl_gen(parser, path)
 
+#define var_field(n) dispatch1(var_field, (n))
+static VALUE backref_assign_error_gen(struct parser_params *parser, VALUE a);
+#define backref_assign_error(n, a) backref_assign_error_gen(parser, (a))
+
 static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
 
 #endif /* !RIPPER */
@@ -1325,14 +1332,8 @@ stmt		: keyword_alias fitem {SET_LEX_STA https://github.com/ruby/ruby/blob/trunk/parse.y#L1332
 		    }
 		| backref tOP_ASGN command_call
 		    {
-		    /*%%%*/
-			rb_backref_error($1);
-			$$ = NEW_BEGIN(0);
-		    /*%
-			$$ = dispatch2(assign, dispatch1(var_field, $1), $3);
-			$$ = dispatch1(assign_error, $$);
-			ripper_error();
-		    %*/
+			$1 = var_field($1);
+			$$ = backref_assign_error($1, node_assign($1, $3));
 		    }
 		| lhs '=' mrhs
 		    {
@@ -1795,14 +1796,8 @@ mlhs_node	: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1796
 		    }
 		| backref
 		    {
-		    /*%%%*/
-			rb_backref_error($1);
-			$$ = NEW_BEGIN(0);
-		    /*%
-			$$ = dispatch1(var_field, $1);
-			$$ = dispatch1(assign_error, $$);
-			ripper_error();
-		    %*/
+			$1 = var_field($1);
+			$$ = backref_assign_error($1, $1);
 		    }
 		;
 
@@ -1866,13 +1861,8 @@ lhs		: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1861
 		    }
 		| backref
 		    {
-		    /*%%%*/
-			rb_backref_error($1);
-			$$ = NEW_BEGIN(0);
-		    /*%
-			$$ = dispatch1(assign_error, $1);
-			ripper_error();
-		    %*/
+			$1 = var_field($1);
+			$$ = backref_assign_error($1, $1);
 		    }
 		;
 
@@ -2073,15 +2063,8 @@ arg		: lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2063
 		    }
 		| backref tOP_ASGN arg
 		    {
-		    /*%%%*/
-			rb_backref_error($1);
-			$$ = NEW_BEGIN(0);
-		    /*%
-			$$ = dispatch1(var_field, $1);
-			$$ = dispatch3(opassign, $$, $2, $3);
-			$$ = dispatch1(assign_error, $$);
-			ripper_error();
-		    %*/
+			$1 = var_field($1);
+			$$ = backref_assign_error($1, new_op_assign($1, $2, $3));
 		    }
 		| arg tDOT2 arg
 		    {
@@ -10279,6 +10262,14 @@ const_decl_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L10262
     }
     return path;
 }
+
+static VALUE
+backref_assign_error_gen(struct parser_params *parser, VALUE a)
+{
+    a = dispatch1(assign_error, a);
+    ripper_error();
+    return a;
+}
 #endif
 
 static void

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]