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

ruby-changes:38328

From: nobu <ko1@a...>
Date: Thu, 30 Apr 2015 23:36:34 +0900 (JST)
Subject: [ruby-changes:38328] nobu:r50409 (trunk): parse.y: %-string cannot be a label

nobu	2015-04-30 23:36:19 +0900 (Thu, 30 Apr 2015)

  New Revision: 50409

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

  Log:
    parse.y: %-string cannot be a label
    
    * parse.y (parser_yylex): %-string cannot be a label even if
      terminated by single/double quotes.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_syntax.rb
Index: parse.y
===================================================================
--- parse.y	(revision 50408)
+++ parse.y	(revision 50409)
@@ -5686,6 +5686,7 @@ rb_parser_compile_file_path(volatile VAL https://github.com/ruby/ruby/blob/trunk/parse.y#L5686
 #define STR_FUNC_QWORDS 0x08
 #define STR_FUNC_SYMBOL 0x10
 #define STR_FUNC_INDENT 0x20
+#define STR_FUNC_LABEL  0x40
 
 enum string_type {
     str_squote = (0),
@@ -7858,7 +7859,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7859
 	}
 	else {
 	    token = parse_string(lex_strterm);
-	    if (token == tSTRING_END && (peek_n('\'', -1) || peek_n('"', -1))) {
+	    if ((token == tSTRING_END) && (lex_strterm->nd_func & STR_FUNC_LABEL)) {
 		if (((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !COND_P()) || IS_ARG()) &&
 		    IS_LABEL_SUFFIX(0)) {
 		    nextc();
@@ -8139,7 +8140,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8140
 	return '>';
 
       case '"':
-	lex_strterm = NEW_STRTERM(str_dquote, '"', 0);
+	lex_strterm = NEW_STRTERM(str_dquote|STR_FUNC_LABEL, '"', 0);
 	return tSTRING_BEG;
 
       case '`':
@@ -8158,7 +8159,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8159
 	return tXSTRING_BEG;
 
       case '\'':
-	lex_strterm = NEW_STRTERM(str_squote, '\'', 0);
+	lex_strterm = NEW_STRTERM(str_squote|STR_FUNC_LABEL, '\'', 0);
 	return tSTRING_BEG;
 
       case '?':
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 50408)
+++ test/ruby/test_syntax.rb	(revision 50409)
@@ -295,6 +295,15 @@ WARN https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L295
     assert_not_label(:foo, 'class Foo < not_label:foo; end', bug6347)
   end
 
+  def test_no_label_with_percent
+    assert_syntax_error('{%"a": 1}', /unexpected ':'/)
+    assert_syntax_error("{%'a': 1}", /unexpected ':'/)
+    assert_syntax_error('{%Q"a": 1}', /unexpected ':'/)
+    assert_syntax_error("{%Q'a': 1}", /unexpected ':'/)
+    assert_syntax_error('{%q"a": 1}', /unexpected ':'/)
+    assert_syntax_error("{%q'a': 1}", /unexpected ':'/)
+  end
+
   def test_duplicated_arg
     assert_syntax_error("def foo(a, a) end", /duplicated argument name/)
     assert_nothing_raised { def foo(_, _) end }

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

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