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

ruby-changes:23406

From: nobu <ko1@a...>
Date: Tue, 24 Apr 2012 16:04:52 +0900 (JST)
Subject: [ruby-changes:23406] nobu:r35457 (trunk): * parse.y (parser_yylex): EXPR_BEG by keywords is a start point of

nobu	2012-04-24 16:04:41 +0900 (Tue, 24 Apr 2012)

  New Revision: 35457

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35457

  Log:
    * parse.y (parser_yylex): EXPR_BEG by keywords is a start point of
      commands.  [ruby-dev:45563][Bug #6347]
    * parse.y (superclass): ditto for superclass.
    * parse.y (parser_parse_string, parser_here_document): ditto for
      string interpolation.
    * parse.y (parser_yylex): ditto for singleton class.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35456)
+++ ChangeLog	(revision 35457)
@@ -1,3 +1,15 @@
+Tue Apr 24 16:04:39 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_yylex): EXPR_BEG by keywords is a start point of
+	  commands.  [ruby-dev:45563][Bug #6347]
+
+	* parse.y (superclass): ditto for superclass.
+
+	* parse.y (parser_parse_string, parser_here_document): ditto for
+	  string interpolation.
+
+	* parse.y (parser_yylex): ditto for singleton class.
+
 Tue Apr 24 15:51:41 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/optparse.rb (OptionParser#to_a): should split by end-of-line
Index: parse.y
===================================================================
--- parse.y	(revision 35456)
+++ parse.y	(revision 35457)
@@ -4407,6 +4407,7 @@
 		| '<'
 		    {
 			lex_state = EXPR_BEG;
+			command_start = TRUE;
 		    }
 		  expr_value term
 		    {
@@ -6144,6 +6145,7 @@
 	    pushback(c);
 	    return tSTRING_DVAR;
 	  case '{':
+	    command_start = TRUE;
 	    return tSTRING_DBEG;
 	}
 	tokadd('#');
@@ -6369,6 +6371,7 @@
 		pushback(c);
 		return tSTRING_DVAR;
 	      case '{':
+		command_start = TRUE;
 		return tSTRING_DBEG;
 	    }
 	    tokadd('#');
@@ -7009,6 +7012,8 @@
 	switch (lex_state) {
 	  case EXPR_FNAME: case EXPR_DOT:
 	    lex_state = EXPR_ARG; break;
+	  case EXPR_CLASS:
+	    command_start = TRUE;
 	  default:
 	    lex_state = EXPR_BEG; break;
 	}
@@ -7997,8 +8002,10 @@
 			set_yylval_name(rb_intern(kw->name));
 			return kw->id[0];
 		    }
+		    if (lex_state == EXPR_BEG) {
+			command_start = TRUE;
+		    }
 		    if (kw->id[0] == keyword_do) {
-			command_start = TRUE;
 			if (lpar_beg && lpar_beg == paren_nest) {
 			    lpar_beg = 0;
 			    --paren_nest;
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 35456)
+++ test/ruby/test_syntax.rb	(revision 35457)
@@ -103,8 +103,40 @@
     end
   end
 
+  def test_cmd_symbol_after_keyword
+    bug6347 = '[ruby-dev:45563]'
+    assert_not_label(:foo, 'if true then not_label:foo end', bug6347)
+    assert_not_label(:foo, 'if false; else not_label:foo end', bug6347)
+    assert_not_label(:foo, 'begin not_label:foo end', bug6347)
+    assert_not_label(:foo, 'begin ensure not_label:foo end', bug6347)
+  end
+
+  def test_cmd_symbol_in_string
+    bug6347 = '[ruby-dev:45563]'
+    assert_not_label(:foo, '"#{not_label:foo}"', bug6347)
+  end
+
+  def test_cmd_symbol_singleton_class
+    bug6347 = '[ruby-dev:45563]'
+    @not_label = self
+    assert_not_label(:foo, 'class << not_label:foo; end', bug6347)
+  end
+
+  def test_cmd_symbol_superclass
+    bug6347 = '[ruby-dev:45563]'
+    @not_label = Object
+    assert_not_label(:foo, 'class Foo < not_label:foo; end', bug6347)
+  end
+
   private
 
+  def not_label(x) @result = x; @not_label ||= nil end
+  def assert_not_label(expected, src, message = nil)
+    @result = nil
+    assert_nothing_raised(SyntaxError, message) {eval(src)}
+    assert_equal(expected, @result, message)
+  end
+
   def make_tmpsrc(f, src)
     f.open
     f.truncate(0)

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

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