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

ruby-changes:42612

From: usa <ko1@a...>
Date: Fri, 22 Apr 2016 15:14:28 +0900 (JST)
Subject: [ruby-changes:42612] usa:r54686 (ruby_2_2): merge revision(s) 54131: [Backport #8851]

usa	2016-04-22 16:11:04 +0900 (Fri, 22 Apr 2016)

  New Revision: 54686

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

  Log:
    merge revision(s) 54131: [Backport #8851]
    
    * defs/keywords (alias, undef): symbol literals are allowed.
    
    * parse.y (parse_percent): should parse symbol literals for alias
      and undef.  [ruby-dev:47681] [Bug #8851]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/defs/keywords
    branches/ruby_2_2/defs/lex.c.src
    branches/ruby_2_2/lex.c.blt
    branches/ruby_2_2/parse.y
    branches/ruby_2_2/test/lib/test/unit/assertions.rb
    branches/ruby_2_2/test/ruby/test_syntax.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/defs/keywords
===================================================================
--- ruby_2_2/defs/keywords	(revision 54685)
+++ ruby_2_2/defs/keywords	(revision 54686)
@@ -13,7 +13,7 @@ __LINE__, {keyword__LINE__, keyword__LIN https://github.com/ruby/ruby/blob/trunk/ruby_2_2/defs/keywords#L13
 __FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END
 BEGIN, {keyword_BEGIN, keyword_BEGIN}, EXPR_END
 END, {keyword_END, keyword_END}, EXPR_END
-alias, {keyword_alias, keyword_alias}, EXPR_FNAME
+alias, {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM
 and, {keyword_and, keyword_and}, EXPR_VALUE
 begin, {keyword_begin, keyword_begin}, EXPR_BEG
 break, {keyword_break, keyword_break}, EXPR_MID
@@ -43,7 +43,7 @@ self, {keyword_self, keyword_self}, EXPR https://github.com/ruby/ruby/blob/trunk/ruby_2_2/defs/keywords#L43
 super, {keyword_super, keyword_super}, EXPR_ARG
 then, {keyword_then, keyword_then}, EXPR_BEG
 true, {keyword_true, keyword_true}, EXPR_END
-undef, {keyword_undef, keyword_undef}, EXPR_FNAME
+undef, {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM
 unless, {keyword_unless, modifier_unless}, EXPR_VALUE
 until, {keyword_until, modifier_until}, EXPR_VALUE
 when, {keyword_when, keyword_when}, EXPR_VALUE
Index: ruby_2_2/defs/lex.c.src
===================================================================
--- ruby_2_2/defs/lex.c.src	(revision 54685)
+++ ruby_2_2/defs/lex.c.src	(revision 54686)
@@ -13,7 +13,7 @@ __LINE__, {keyword__LINE__, keyword__LIN https://github.com/ruby/ruby/blob/trunk/ruby_2_2/defs/lex.c.src#L13
 __FILE__, {keyword__FILE__, keyword__FILE__}, EXPR_END
 BEGIN, {keyword_BEGIN, keyword_BEGIN}, EXPR_END
 END, {keyword_END, keyword_END}, EXPR_END
-alias, {keyword_alias, keyword_alias}, EXPR_FNAME
+alias, {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM
 and, {keyword_and, keyword_and}, EXPR_VALUE
 begin, {keyword_begin, keyword_begin}, EXPR_BEG
 break, {keyword_break, keyword_break}, EXPR_MID
@@ -43,7 +43,7 @@ self, {keyword_self, keyword_self}, EXPR https://github.com/ruby/ruby/blob/trunk/ruby_2_2/defs/lex.c.src#L43
 super, {keyword_super, keyword_super}, EXPR_ARG
 then, {keyword_then, keyword_then}, EXPR_BEG
 true, {keyword_true, keyword_true}, EXPR_END
-undef, {keyword_undef, keyword_undef}, EXPR_FNAME
+undef, {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM
 unless, {keyword_unless, modifier_unless}, EXPR_VALUE
 until, {keyword_until, modifier_until}, EXPR_VALUE
 when, {keyword_when, keyword_when}, EXPR_VALUE
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 54685)
+++ ruby_2_2/version.h	(revision 54686)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.5"
 #define RUBY_RELEASE_DATE "2016-04-22"
-#define RUBY_PATCHLEVEL 303
+#define RUBY_PATCHLEVEL 304
 
 #define RUBY_RELEASE_YEAR 2016
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_2/parse.y
===================================================================
--- ruby_2_2/parse.y	(revision 54685)
+++ ruby_2_2/parse.y	(revision 54686)
@@ -61,6 +61,7 @@ enum lex_state_bits { https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L61
     EXPR_CLASS_bit,		/* immediate after `class', no here document. */
     EXPR_LABEL_bit,		/* flag bit, label is allowed. */
     EXPR_LABELED_bit,		/* flag bit, just after a label. */
+    EXPR_FITEM_bit,		/* symbol literal as FNAME. */
     EXPR_MAX_STATE
 };
 /* examine combinations */
@@ -78,6 +79,7 @@ enum lex_state_e { https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L79
     DEF_EXPR(CLASS),
     DEF_EXPR(LABEL),
     DEF_EXPR(LABELED),
+    DEF_EXPR(FITEM),
     EXPR_VALUE = EXPR_BEG,
     EXPR_BEG_ANY  =  (EXPR_BEG | EXPR_MID | EXPR_CLASS),
     EXPR_ARG_ANY  =  (EXPR_ARG | EXPR_CMDARG),
@@ -1098,7 +1100,7 @@ stmt_or_begin	: stmt https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L1100
 		    %*/
 		    }
 
-stmt		: keyword_alias fitem {lex_state = EXPR_FNAME;} fitem
+stmt		: keyword_alias fitem {lex_state = EXPR_FNAME|EXPR_FITEM;} fitem
 		    {
 		    /*%%%*/
 			$$ = NEW_ALIAS($2, $4);
@@ -1934,7 +1936,7 @@ undef_list	: fitem https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L1936
 			$$ = rb_ary_new3(1, $1);
 		    %*/
 		    }
-		| undef_list ',' {lex_state = EXPR_FNAME;} fitem
+		| undef_list ',' {lex_state = EXPR_FNAME|EXPR_FITEM;} fitem
 		    {
 		    /*%%%*/
 			$$ = block_append($1, NEW_UNDEF($4));
@@ -7556,7 +7558,7 @@ parse_percent(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L7558
 
 	  case 's':
 	    lex_strterm = NEW_STRTERM(str_ssym, term, paren);
-	    lex_state = EXPR_FNAME;
+	    lex_state = EXPR_FNAME|EXPR_FITEM;
 	    return tSYMBEG;
 
 	  default:
@@ -7569,7 +7571,7 @@ parse_percent(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/ruby_2_2/parse.y#L7571
 	lex_state = EXPR_BEG;
 	return tOP_ASGN;
     }
-    if (IS_SPCARG(c)) {
+    if (IS_SPCARG(c) || (IS_lex_state(EXPR_FITEM) && c == 's')) {
 	goto quotation;
     }
     lex_state = IS_AFTER_OPERATOR() ? EXPR_ARG : EXPR_BEG;
Index: ruby_2_2/test/ruby/test_syntax.rb
===================================================================
--- ruby_2_2/test/ruby/test_syntax.rb	(revision 54685)
+++ ruby_2_2/test/ruby/test_syntax.rb	(revision 54686)
@@ -634,6 +634,30 @@ eom https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_syntax.rb#L634
     end
   end
 
+  def test_alias_symbol
+    bug8851 = '[ruby-dev:47681] [Bug #8851]'
+    formats = ['%s', ":'%s'", ':"%s"', '%%s(%s)']
+    all_assertions(bug8851) do |all|
+      formats.product(formats) do |form1, form2|
+        all.for(code = "alias #{form1 % 'a'} #{form2 % 'p'}") do
+          assert_valid_syntax(code)
+        end
+      end
+    end
+  end
+
+  def test_undef_symbol
+    bug8851 = '[ruby-dev:47681] [Bug #8851]'
+    formats = ['%s', ":'%s'", ':"%s"', '%%s(%s)']
+    all_assertions(bug8851) do |all|
+      formats.product(formats) do |form1, form2|
+        all.for(code = "undef #{form1 % 'a'}, #{form2 % 'p'}") do
+          assert_valid_syntax(code)
+        end
+      end
+    end
+  end
+
   private
 
   def not_label(x) @result = x; @not_label ||= nil end
Index: ruby_2_2/test/lib/test/unit/assertions.rb
===================================================================
--- ruby_2_2/test/lib/test/unit/assertions.rb	(revision 54685)
+++ ruby_2_2/test/lib/test/unit/assertions.rb	(revision 54686)
@@ -442,6 +442,42 @@ EOT https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/lib/test/unit/assertions.rb#L442
         assert(failed.empty?, message(m) {failed.pretty_inspect})
       end
 
+      class AllFailures
+        attr_reader :failures
+
+        def initialize
+          @count = 0
+          @failures = {}
+        end
+
+        def for(key)
+          @count += 1
+          yield
+        rescue Exception => e
+          @failures[key] = [@count, e]
+        end
+
+        def message
+          i = 0
+          total = @count.to_s
+          fmt = "%#{total.size}d"
+          @failures.map {|k, (n, v)|
+            "\n#{i+=1}. [#{fmt%n}/#{total}] Assertion for #{k.inspect}\n#{v.message.b.gsub(/^/, '   | ')}"
+          }.join("\n")
+        end
+
+        def pass?
+          @failures.empty?
+        end
+      end
+
+      def all_assertions(msg = nil)
+        all = AllFailures.new
+        yield all
+      ensure
+        assert(all.pass?, message(msg) {all.message.chomp(".")})
+      end
+
       def build_message(head, template=nil, *arguments) #:nodoc:
         template &&= template.chomp
         template.gsub(/\G((?:[^\\]|\\.)*?)(\\)?\?/) { $1 + ($2 ? "?" : mu_pp(arguments.shift)) }
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 54685)
+++ ruby_2_2/ChangeLog	(revision 54686)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Fri Apr 22 16:00:50 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* defs/keywords (alias, undef): symbol literals are allowed.
+
+	* parse.y (parse_percent): should parse symbol literals for alias
+	  and undef.  [ruby-dev:47681] [Bug #8851]
+
 Fri Apr 22 15:47:58 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* struct.c (struct_make_members_list): extract making member name
Index: ruby_2_2/lex.c.blt
===================================================================
--- ruby_2_2/lex.c.blt	(revision 54685)
+++ ruby_2_2/lex.c.blt	(revision 54686)
@@ -156,7 +156,7 @@ rb_reserved_word (str, len) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lex.c.blt#L156
 #line 30 "defs/keywords"
       {"for", {keyword_for, keyword_for}, EXPR_VALUE},
 #line 46 "defs/keywords"
-      {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
+      {"undef", {keyword_undef, keyword_undef}, EXPR_FNAME|EXPR_FITEM},
 #line 37 "defs/keywords"
       {"or", {keyword_or, keyword_or}, EXPR_VALUE},
 #line 32 "defs/keywords"
@@ -188,7 +188,7 @@ rb_reserved_word (str, len) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lex.c.blt#L188
 #line 15 "defs/keywords"
       {"END", {keyword_END, keyword_END}, EXPR_END},
 #line 16 "defs/keywords"
-      {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
+      {"alias", {keyword_alias, keyword_alias}, EXPR_FNAME|EXPR_FITEM},
 #line 14 "defs/keywords"
       {"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
 #line 23 "defs/keywords"

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r54131


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

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