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

ruby-changes:55047

From: nobu <ko1@a...>
Date: Thu, 14 Mar 2019 17:13:50 +0900 (JST)
Subject: [ruby-changes:55047] nobu:r67254 (trunk): parse.y: no punctuation instance/class variables

nobu	2019-03-14 17:13:46 +0900 (Thu, 14 Mar 2019)

  New Revision: 67254

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

  Log:
    parse.y: no punctuation instance/class variables
    
    * parse.y (parse_atmark): exclude punctuation follows @ marks,
      whereas it is inclusive after $ mark as some punctuation global
      variables exist.

  Modified files:
    trunk/parse.y
    trunk/test/ripper/test_parser_events.rb
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 67253)
+++ parse.y	(revision 67254)
@@ -7596,7 +7596,8 @@ parse_atmark(struct parser_params *p, co https://github.com/ruby/ruby/blob/trunk/parse.y#L7596
 	tokadd(p, '@');
 	c = nextc(p);
     }
-    if (c == -1 || ISSPACE(c)) {
+    if (c == -1 || !parser_is_identchar(p)) {
+	pushback(p, c);
 	if (result == tIVAR) {
 	    compile_error(p, "`@' without identifiers is not allowed as an instance variable name");
 	}
@@ -7605,7 +7606,7 @@ parse_atmark(struct parser_params *p, co https://github.com/ruby/ruby/blob/trunk/parse.y#L7606
 	}
 	return 0;
     }
-    else if (ISDIGIT(c) || !parser_is_identchar(p)) {
+    else if (ISDIGIT(c)) {
 	pushback(p, c);
 	if (result == tIVAR) {
 	    compile_error(p, "`@%c' is not allowed as an instance variable name", c);
Index: test/ripper/test_parser_events.rb
===================================================================
--- test/ripper/test_parser_events.rb	(revision 67253)
+++ test/ripper/test_parser_events.rb	(revision 67254)
@@ -1479,13 +1479,13 @@ class TestRipper::ParserEvents < Test::U https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L1479
 
   def test_invalid_instance_variable_name
     assert_equal("`@1' is not allowed as an instance variable name", compile_error('@1'))
-    assert_equal("`@%' is not allowed as an instance variable name", compile_error('@%'))
+    assert_equal("`@' without identifiers is not allowed as an instance variable name", compile_error('@%'))
     assert_equal("`@' without identifiers is not allowed as an instance variable name", compile_error('@'))
   end
 
   def test_invalid_class_variable_name
     assert_equal("`@@1' is not allowed as a class variable name", compile_error('@@1'))
-    assert_equal("`@@%' is not allowed as a class variable name", compile_error('@@%'))
+    assert_equal("`@@' without identifiers is not allowed as a class variable name", compile_error('@@%'))
     assert_equal("`@@' without identifiers is not allowed as a class variable name", compile_error('@@'))
   end
 
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 67253)
+++ test/ruby/test_parse.rb	(revision 67254)
@@ -376,23 +376,25 @@ class TestParse < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L376
     assert_nothing_raised { eval(':""') }
   end
 
-  def assert_disallowed_variable(type, noname, *invalid)
-    assert_syntax_error("a = #{noname}", "`#{noname}' without identifiers is not allowed as #{type} variable name")
+  def assert_disallowed_variable(type, noname, invalid)
+    noname.each do |name|
+      assert_syntax_error("a = #{name}", "`#{noname[0]}' without identifiers is not allowed as #{type} variable name")
+    end
     invalid.each do |name|
       assert_syntax_error("a = #{name}", "`#{name}' is not allowed as #{type} variable name")
     end
   end
 
   def test_disallowed_instance_variable
-    assert_disallowed_variable("an instance", *%w[@ @1 @.])
+    assert_disallowed_variable("an instance", %w[@ @.], %w[@1])
   end
 
   def test_disallowed_class_variable
-    assert_disallowed_variable("a class", *%w[@@ @@1 @@.])
+    assert_disallowed_variable("a class", %w[@@ @@.], %w[@@1])
   end
 
   def test_disallowed_gloal_variable
-    assert_disallowed_variable("a global", *%w[$ $%])
+    assert_disallowed_variable("a global", %w[$], %w[$%])
   end
 
   def test_arg2

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

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