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

ruby-changes:43786

From: nobu <ko1@a...>
Date: Thu, 11 Aug 2016 11:13:03 +0900 (JST)
Subject: [ruby-changes:43786] nobu:r55859 (trunk): parse.y: const declaration macro

nobu	2016-08-11 11:12:57 +0900 (Thu, 11 Aug 2016)

  New Revision: 55859

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

  Log:
    parse.y: const declaration macro
    
    * parse.y (const_decl): unify parser and ripper code.

  Modified files:
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 55858)
+++ parse.y	(revision 55859)
@@ -488,6 +488,9 @@ static NODE *new_const_op_assign_gen(str https://github.com/ruby/ruby/blob/trunk/parse.y#L488
 
 #define const_path_field(w, n) NEW_COLON2(w, n)
 #define top_const_field(n) NEW_COLON3(n)
+#define const_decl(path) ( \
+	((in_def || in_single) ? yyerror("dynamic constant assignment") : (void)0), \
+	NEW_CDECL(0, 0, (path)))
 
 static NODE *kwd_append(NODE*, NODE*);
 
@@ -554,6 +557,8 @@ static VALUE new_attr_op_assign_gen(stru https://github.com/ruby/ruby/blob/trunk/parse.y#L557
 #define new_const_op_assign(lhs, op, rhs) new_op_assign(lhs, op, rhs)
 #define const_path_field(w, n) dispatch2(const_path_field, (w), (n))
 #define top_const_field(n) dispatch1(top_const_field, (n))
+static VALUE const_decl_gen(struct parser_params *parser, VALUE path);
+#define const_decl(path) const_decl_gen(parser, path)
 
 static VALUE parser_reg_compile(struct parser_params*, VALUE, int, VALUE *);
 
@@ -1782,31 +1787,11 @@ mlhs_node	: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1787
 		    }
 		| primary_value tCOLON2 tCONSTANT
 		    {
-		    /*%%%*/
-			if (in_def || in_single)
-			    yyerror("dynamic constant assignment");
-			$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
-		    /*%
-			$$ = dispatch2(const_path_field, $1, $3);
-			if (in_def || in_single) {
-			    $$ = dispatch1(assign_error, $$);
-			    ripper_error();
-			}
-		    %*/
+			$$ = const_decl(const_path_field($1, $3));
 		    }
 		| tCOLON3 tCONSTANT
 		    {
-		    /*%%%*/
-			if (in_def || in_single)
-			    yyerror("dynamic constant assignment");
-			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
-		    /*%
-			$$ = dispatch1(top_const_field, $2);
-			if (in_def || in_single) {
-			    $$ = dispatch1(assign_error, $$);
-			    ripper_error();
-			}
-		    %*/
+			$$ = const_decl(top_const_field($2));
 		    }
 		| backref
 		    {
@@ -1873,31 +1858,11 @@ lhs		: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1858
 		    }
 		| primary_value tCOLON2 tCONSTANT
 		    {
-		    /*%%%*/
-			if (in_def || in_single)
-			    yyerror("dynamic constant assignment");
-			$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
-		    /*%
-			$$ = dispatch2(const_path_field, $1, $3);
-			if (in_def || in_single) {
-			    $$ = dispatch1(assign_error, $$);
-			    ripper_error();
-			}
-		    %*/
+			$$ = const_decl(const_path_field($1, $3));
 		    }
 		| tCOLON3 tCONSTANT
 		    {
-		    /*%%%*/
-			if (in_def || in_single)
-			    yyerror("dynamic constant assignment");
-			$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
-		    /*%
-			$$ = dispatch1(top_const_field, $2);
-			if (in_def || in_single) {
-			    $$ = dispatch1(assign_error, $$);
-			    ripper_error();
-			}
-		    %*/
+			$$ = const_decl(top_const_field($2));
 		    }
 		| backref
 		    {
@@ -10304,6 +10269,16 @@ new_attr_op_assign_gen(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L10269
     VALUE recv = dispatch3(field, lhs, type, attr);
     return dispatch3(opassign, recv, op, rhs);
 }
+
+static VALUE
+const_decl_gen(struct parser_params *parser, VALUE path)
+{
+    if (in_def || in_single) {
+	dispatch1(assign_error, path);
+	ripper_error();
+    }
+    return path;
+}
 #endif
 
 static void

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

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