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

ruby-changes:49839

From: mame <ko1@a...>
Date: Fri, 19 Jan 2018 22:11:16 +0900 (JST)
Subject: [ruby-changes:49839] mame:r61957 (trunk): parse.y: Allows Ripper DSL to embed C function calls as `foo!`

mame	2018-01-19 22:11:11 +0900 (Fri, 19 Jan 2018)

  New Revision: 61957

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

  Log:
    parse.y: Allows Ripper DSL to embed C function calls as `foo!`
    
    Instead of `_foo`.  This makes it useful to do word boundary search of
    the editor.

  Modified files:
    trunk/ext/ripper/tools/dsl.rb
    trunk/parse.y
Index: parse.y
===================================================================
--- parse.y	(revision 61956)
+++ parse.y	(revision 61957)
@@ -1047,7 +1047,7 @@ bodystmt	: compstmt https://github.com/ruby/ruby/blob/trunk/parse.y#L1047
 			}
 			fixpos($$, $1);
 		    /*% %*/
-		    /*% ripper: bodystmt(_escape_Qundef($1), _escape_Qundef($2), _escape_Qundef($3), _escape_Qundef($4)) %*/
+		    /*% ripper: bodystmt(escape_Qundef!($1), escape_Qundef!($2), escape_Qundef!($3), escape_Qundef!($4)) %*/
 		    }
 		;
 
@@ -1570,7 +1570,7 @@ mlhs_node	: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1570
 		    /*%%%*/
 			$$ = aryset(p, $1, $3, &@$);
 		    /*% %*/
-		    /*% ripper: aref_field($1, _escape_Qundef($3)) %*/
+		    /*% ripper: aref_field($1, escape_Qundef!($3)) %*/
 		    }
 		| primary_value call_op tIDENTIFIER
 		    {
@@ -1621,7 +1621,7 @@ lhs		: user_variable https://github.com/ruby/ruby/blob/trunk/parse.y#L1621
 		    /*%%%*/
 			$$ = aryset(p, $1, $3, &@$);
 		    /*% %*/
-		    /*% ripper: aref_field($1, _escape_Qundef($3)) %*/
+		    /*% ripper: aref_field($1, escape_Qundef!($3)) %*/
 		    }
 		| primary_value call_op tIDENTIFIER
 		    {
@@ -1726,7 +1726,7 @@ undef_list	: fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1726
 		    /*%%%*/
 			$$ = NEW_UNDEF($1, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, _get_value($1)) %*/
 		    }
 		| undef_list ',' {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
 		    {
@@ -1734,7 +1734,7 @@ undef_list	: fitem https://github.com/ruby/ruby/blob/trunk/parse.y#L1734
 			NODE *undef = NEW_UNDEF($4, &@$);
 			$$ = block_append(p, $1, undef);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($4)) %*/
+		    /*% ripper: rb_ary_push!($1, _get_value($4)) %*/
 		    }
 		;
 
@@ -2031,7 +2031,7 @@ paren_args	: '(' opt_call_args rparen https://github.com/ruby/ruby/blob/trunk/parse.y#L2031
 		    /*%%%*/
 			$$ = $2;
 		    /*% %*/
-		    /*% ripper: arg_paren(_escape_Qundef($2)) %*/
+		    /*% ripper: arg_paren(escape_Qundef!($2)) %*/
 		    }
 		;
 
@@ -2277,7 +2277,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2277
 		    /*%%%*/
 			$$ = make_array($2, &@$);
 		    /*% %*/
-		    /*% ripper: array(_escape_Qundef($2)) %*/
+		    /*% ripper: array(escape_Qundef!($2)) %*/
 		    }
 		| tLBRACE assoc_list '}'
 		    {
@@ -2285,7 +2285,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2285
 			$$ = new_hash(p, $2, &@$);
 			$$->nd_alen = TRUE;
 		    /*% %*/
-		    /*% ripper: hash(_escape_Qundef($2)) %*/
+		    /*% ripper: hash(escape_Qundef!($2)) %*/
 		    }
 		| k_return
 		    {
@@ -2361,7 +2361,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2361
 			$$ = new_if(p, $2, $4, $5, &@$);
 			fixpos($$, $2);
 		    /*% %*/
-		    /*% ripper: send(:if, $2, $4, _escape_Qundef($5)) %*/
+		    /*% ripper: send(:if, $2, $4, escape_Qundef!($5)) %*/
 		    }
 		| k_unless expr_value then
 		  compstmt
@@ -2372,7 +2372,7 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L2372
 			$$ = new_unless(p, $2, $4, $5, &@$);
 			fixpos($$, $2);
 		    /*% %*/
-		    /*% ripper: send(:unless, $2, $4, _escape_Qundef($5)) %*/
+		    /*% ripper: send(:unless, $2, $4, escape_Qundef!($5)) %*/
 		    }
 		| k_while expr_value_do
 		  compstmt
@@ -2705,7 +2705,7 @@ if_tail		: opt_else https://github.com/ruby/ruby/blob/trunk/parse.y#L2705
 			$$ = new_if(p, $2, $4, $5, &@$);
 			fixpos($$, $2);
 		    /*% %*/
-		    /*% ripper: send(:elsif, $2, $4, _escape_Qundef($5)) %*/
+		    /*% ripper: send(:elsif, $2, $4, escape_Qundef!($5)) %*/
 		    }
 		;
 
@@ -2928,7 +2928,7 @@ block_param_def	: '|' opt_bv_decl '|' https://github.com/ruby/ruby/blob/trunk/parse.y#L2928
 		    /*%%%*/
 			$$ = 0;
 		    /*% %*/
-		    /*% ripper: block_var("params_new(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil)", _escape_Qundef($2)) %*/
+		    /*% ripper: block_var("params_new(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil)", escape_Qundef!($2)) %*/
 		    }
 		| tOROP
 		    {
@@ -2943,7 +2943,7 @@ block_param_def	: '|' opt_bv_decl '|' https://github.com/ruby/ruby/blob/trunk/parse.y#L2943
 		    /*%%%*/
 			$$ = $2;
 		    /*% %*/
-		    /*% ripper: block_var(_escape_Qundef($2), _escape_Qundef($3)) %*/
+		    /*% ripper: block_var(escape_Qundef!($2), escape_Qundef!($3)) %*/
 		    }
 		;
 
@@ -2962,9 +2962,9 @@ opt_bv_decl	: opt_nl https://github.com/ruby/ruby/blob/trunk/parse.y#L2962
 		;
 
 bv_decls	: bvar
-		    /*% ripper[brace]: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper[brace]: rb_ary_new3!(1, _get_value($1)) %*/
 		| bv_decls ',' bvar
-		    /*% ripper[brace]: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper[brace]: rb_ary_push!($1, _get_value($3)) %*/
 		;
 
 bvar		: tIDENTIFIER
@@ -3123,7 +3123,7 @@ method_call	: fcall paren_args https://github.com/ruby/ruby/blob/trunk/parse.y#L3123
 			    $$ = NEW_CALL($1, tAREF, $3, &@$);
 			fixpos($$, $1);
 		    /*% %*/
-		    /*% ripper: aref($1, _escape_Qundef($3)) %*/
+		    /*% ripper: aref($1, escape_Qundef!($3)) %*/
 		    }
 		;
 
@@ -3173,7 +3173,7 @@ case_body	: keyword_when args then https://github.com/ruby/ruby/blob/trunk/parse.y#L3173
 			$$ = NEW_WHEN($2, $4, $5, &@$);
 			fixpos($$, $2);
 		    /*% %*/
-		    /*% ripper: send(:when, $2, $4, _escape_Qundef($5)) %*/
+		    /*% ripper: send(:when, $2, $4, escape_Qundef!($5)) %*/
 		    }
 		;
 
@@ -3193,7 +3193,7 @@ opt_rescue	: keyword_rescue exc_list exc https://github.com/ruby/ruby/blob/trunk/parse.y#L3193
 			$$ = NEW_RESBODY($2, $5, $6, &@$);
 			fixpos($$, $2?$2:$5);
 		    /*% %*/
-		    /*% ripper: send(:rescue, _escape_Qundef($2), _escape_Qundef($3), _escape_Qundef($5), _escape_Qundef($6)) %*/
+		    /*% ripper: send(:rescue, escape_Qundef!($2), escape_Qundef!($3), escape_Qundef!($5), escape_Qundef!($6)) %*/
 		    }
 		| none
 		;
@@ -3203,7 +3203,7 @@ exc_list	: arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3203
 		    /*%%%*/
 			$$ = NEW_LIST($1, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, get_value!($1)) %*/
 		    }
 		| mrhs
 		    {
@@ -3852,7 +3852,7 @@ f_arg_item	: f_arg_asgn https://github.com/ruby/ruby/blob/trunk/parse.y#L3852
 		    /*%%%*/
 			$$ = NEW_ARGS_AUX($1, 1, &NULL_LOC);
 		    /*% %*/
-		    /*% ripper: _get_value($1) %*/
+		    /*% ripper: get_value!($1) %*/
 		    }
 		| tLPAREN f_margs rparen
 		    {
@@ -3878,7 +3878,7 @@ f_arg_item	: f_arg_asgn https://github.com/ruby/ruby/blob/trunk/parse.y#L3878
 		;
 
 f_arg		: f_arg_item
-		    /*% ripper[brace]: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper[brace]: rb_ary_new3!(1, get_value!($1)) %*/
 		| f_arg ',' f_arg_item
 		    {
 		    /*%%%*/
@@ -3887,7 +3887,7 @@ f_arg		: f_arg_item https://github.com/ruby/ruby/blob/trunk/parse.y#L3887
 			$$->nd_next = block_append(p, $$->nd_next, $3->nd_next);
 			rb_discard_node(p, $3);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
@@ -3908,7 +3908,7 @@ f_kw		: f_label arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3908
 		    /*%%%*/
 			$$ = new_kw_arg(p, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), _get_value($2)) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), get_value!($2)) %*/
 		    }
 		| f_label
 		    {
@@ -3917,7 +3917,7 @@ f_kw		: f_label arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3917
 		    /*%%%*/
 			$$ = new_kw_arg(p, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), 0) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), 0) %*/
 		    }
 		;
 
@@ -3927,7 +3927,7 @@ f_block_kw	: f_label primary_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3927
 		    /*%%%*/
 			$$ = new_kw_arg(p, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), _get_value($2)) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), get_value!($2)) %*/
 		    }
 		| f_label
 		    {
@@ -3935,7 +3935,7 @@ f_block_kw	: f_label primary_value https://github.com/ruby/ruby/blob/trunk/parse.y#L3935
 		    /*%%%*/
 			$$ = new_kw_arg(p, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), 0) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), 0) %*/
 		    }
 		;
 
@@ -3944,14 +3944,14 @@ f_block_kwarg	: f_block_kw https://github.com/ruby/ruby/blob/trunk/parse.y#L3944
 		    /*%%%*/
 			$$ = $1;
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, get_value!($1)) %*/
 		    }
 		| f_block_kwarg ',' f_block_kw
 		    {
 		    /*%%%*/
 			$$ = kwd_append($1, $3);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
@@ -3961,14 +3961,14 @@ f_kwarg		: f_kw https://github.com/ruby/ruby/blob/trunk/parse.y#L3961
 		    /*%%%*/
 			$$ = $1;
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, get_value!($1)) %*/
 		    }
 		| f_kwarg ',' f_kw
 		    {
 		    /*%%%*/
 			$$ = kwd_append($1, $3);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
@@ -4001,7 +4001,7 @@ f_opt		: f_arg_asgn '=' arg_value https://github.com/ruby/ruby/blob/trunk/parse.y#L4001
 		    /*%%%*/
 			$$ = NEW_OPT_ARG(0, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), _get_value($3)) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), get_value!($3)) %*/
 		    }
 		;
 
@@ -4012,7 +4012,7 @@ f_block_opt	: f_arg_asgn '=' primary_val https://github.com/ruby/ruby/blob/trunk/parse.y#L4012
 		    /*%%%*/
 			$$ = NEW_OPT_ARG(0, $$, &@$);
 		    /*% %*/
-		    /*% ripper: _rb_assoc_new(_get_value("$$"), _get_value($3)) %*/
+		    /*% ripper: _rb_assoc_new(get_value!("$$"), get_value!($3)) %*/
 		    }
 		;
 
@@ -4021,14 +4021,14 @@ f_block_optarg	: f_block_opt https://github.com/ruby/ruby/blob/trunk/parse.y#L4021
 		    /*%%%*/
 			$$ = $1;
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, get_value!($1)) %*/
 		    }
 		| f_block_optarg ',' f_block_opt
 		    {
 		    /*%%%*/
 			$$ = opt_arg_append($1, $3);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
@@ -4037,14 +4037,14 @@ f_optarg	: f_opt https://github.com/ruby/ruby/blob/trunk/parse.y#L4037
 		    /*%%%*/
 			$$ = $1;
 		    /*% %*/
-		    /*% ripper: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper: rb_ary_new3!(1, get_value!($1)) %*/
 		    }
 		| f_optarg ',' f_opt
 		    {
 		    /*%%%*/
 			$$ = opt_arg_append($1, $3);
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
@@ -4137,7 +4137,7 @@ assoc_list	: none https://github.com/ruby/ruby/blob/trunk/parse.y#L4137
 		;
 
 assocs		: assoc
-		    /*% ripper[brace]: _rb_ary_new3(1, _get_value($1)) %*/
+		    /*% ripper[brace]: rb_ary_new3!(1, get_value!($1)) %*/
 		| assocs ',' assoc
 		    {
 		    /*%%%*/
@@ -4157,7 +4157,7 @@ assocs		: assoc https://github.com/ruby/ruby/blob/trunk/parse.y#L4157
 			}
 			$$ = assocs;
 		    /*% %*/
-		    /*% ripper: _rb_ary_push($1, _get_value($3)) %*/
+		    /*% ripper: rb_ary_push!($1, get_value!($3)) %*/
 		    }
 		;
 
Index: ext/ripper/tools/dsl.rb
===================================================================
--- ext/ripper/tools/dsl.rb	(revision 61956)
+++ ext/ripper/tools/dsl.rb	(revision 61957)
@@ -35,8 +35,8 @@ class DSL https://github.com/ruby/ruby/blob/trunk/ext/ripper/tools/dsl.rb#L35
   end
 
   def method_missing(*args)
-    if args.first =~ /\A_/
-      "#{ $' }(#{ args.drop(1).join(", ") })"
+    if args.first =~ /!\z/
+      "#{ $` }(#{ args.drop(1).join(", ") })"
     else
       @events[args.first.to_s] = args.size - 1
       "dispatch#{ args.size - 1 }(#{ args.join(", ") })"

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

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