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

ruby-changes:33924

From: nagachika <ko1@a...>
Date: Mon, 19 May 2014 00:37:05 +0900 (JST)
Subject: [ruby-changes:33924] nagachika:r46005 (ruby_2_1): merge revision(s) r45405, r45408: [Backport #9669] [Backport #9740]

nagachika	2014-05-19 00:36:58 +0900 (Mon, 19 May 2014)

  New Revision: 46005

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

  Log:
    merge revision(s) r45405,r45408: [Backport #9669] [Backport #9740]
    
    * parse.y (lex_state_e, parser_params, f_arglist, parser_yylex):
      separate EXPR_LABELARG from EXPR_BEG and let newline significant,
      so that required keyword argument can place at the end of
      argument list without parentheses.  [ruby-core:61658] [Bug #9669]
    
    * parse.y (parser_yylex): only a newline after label should be
      significant.  [ruby-core:61658] [Bug #9669]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/parse.y
    branches/ruby_2_1/test/ruby/test_keyword.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46004)
+++ ruby_2_1/ChangeLog	(revision 46005)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon May 19 00:26:53 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_yylex): only a newline after label should be
+	  significant.  [ruby-core:61658] [Bug #9669]
+
+Mon May 19 00:26:53 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (lex_state_e, parser_params, f_arglist, parser_yylex):
+	  separate EXPR_LABELARG from EXPR_BEG and let newline significant,
+	  so that required keyword argument can place at the end of
+	  argument list without parentheses.  [ruby-core:61658] [Bug #9669]
+
 Fri May 16 00:27:02 2014  James Edward Gray II  <james@g...>
 
 	* lib/csv.rb: Fixed a broken regular expression that was causing
Index: ruby_2_1/parse.y
===================================================================
--- ruby_2_1/parse.y	(revision 46004)
+++ ruby_2_1/parse.y	(revision 46005)
@@ -74,6 +74,7 @@ enum lex_state_bits { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L74
     EXPR_DOT_bit,		/* right after `.' or `::', no reserved words. */
     EXPR_CLASS_bit,		/* immediate after `class', no here document. */
     EXPR_VALUE_bit,		/* alike EXPR_BEG but label is disallowed. */
+    EXPR_LABELARG_bit,		/* ignore significant, +/- is a sign. */
     EXPR_MAX_STATE
 };
 /* examine combinations */
@@ -90,7 +91,8 @@ enum lex_state_e { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L91
     DEF_EXPR(DOT),
     DEF_EXPR(CLASS),
     DEF_EXPR(VALUE),
-    EXPR_BEG_ANY  =  (EXPR_BEG | EXPR_VALUE | EXPR_MID | EXPR_CLASS),
+    DEF_EXPR(LABELARG),
+    EXPR_BEG_ANY  =  (EXPR_BEG | EXPR_VALUE | EXPR_MID | EXPR_CLASS | EXPR_LABELARG),
     EXPR_ARG_ANY  =  (EXPR_ARG | EXPR_CMDARG),
     EXPR_END_ANY  =  (EXPR_END | EXPR_ENDARG | EXPR_ENDFN)
 };
@@ -244,6 +246,7 @@ struct parser_params { https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L246
     int parser_brace_nest;
     int parser_compile_for_eval;
     VALUE parser_cur_mid;
+    int parser_in_kwarg;
     int parser_in_defined;
     char *parser_tokenbuf;
     int parser_tokidx;
@@ -4409,9 +4412,14 @@ f_arglist	: '(' f_args rparen https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L4412
 			lex_state = EXPR_BEG;
 			command_start = TRUE;
 		    }
-		| f_args term
+		|   {
+			$<num>$ = parser->parser_in_kwarg;
+			parser->parser_in_kwarg = 1;
+		    }
+		    f_args term
 		    {
-			$$ = $1;
+			parser->parser_in_kwarg = $<num>1;
+			$$ = $2;
 			lex_state = EXPR_BEG;
 			command_start = TRUE;
 		    }
@@ -7012,13 +7020,16 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L7020
 #endif
 	/* fall through */
       case '\n':
-	if (IS_lex_state(EXPR_BEG | EXPR_VALUE | EXPR_CLASS | EXPR_FNAME | EXPR_DOT)) {
+	if (IS_lex_state(EXPR_BEG | EXPR_VALUE | EXPR_CLASS | EXPR_FNAME | EXPR_DOT | EXPR_LABELARG)) {
 #ifdef RIPPER
             if (!fallthru) {
                 ripper_dispatch_scan_event(parser, tIGNORED_NL);
             }
             fallthru = FALSE;
 #endif
+	    if (IS_lex_state(EXPR_LABELARG) && parser->parser_in_kwarg) {
+		goto normal_newline;
+	    }
 	    goto retry;
 	}
 	while ((c = nextc())) {
@@ -8150,7 +8161,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L8161
 
 	    if (IS_LABEL_POSSIBLE()) {
 		if (IS_LABEL_SUFFIX(0)) {
-		    lex_state = EXPR_BEG;
+		    lex_state = EXPR_LABELARG;
 		    nextc();
 		    set_yylval_name(TOK_INTERN(!ENC_SINGLE(mb)));
 		    return tLABEL;
@@ -10846,6 +10857,7 @@ parser_initialize(struct parser_params * https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L10857
     parser->parser_in_single = 0;
     parser->parser_in_def = 0;
     parser->parser_in_defined = 0;
+    parser->parser_in_kwarg = 0;
     parser->parser_compile_for_eval = 0;
     parser->parser_cur_mid = 0;
     parser->parser_tokenbuf = NULL;
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46004)
+++ ruby_2_1/version.h	(revision 46005)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-05-16"
-#define RUBY_PATCHLEVEL 102
+#define RUBY_RELEASE_DATE "2014-05-19"
+#define RUBY_PATCHLEVEL 103
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 5
-#define RUBY_RELEASE_DAY 16
+#define RUBY_RELEASE_DAY 19
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_keyword.rb
===================================================================
--- ruby_2_1/test/ruby/test_keyword.rb	(revision 46004)
+++ ruby_2_1/test/ruby/test_keyword.rb	(revision 46005)
@@ -325,6 +325,25 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_keyword.rb#L325
     assert_equal([[:keyreq, :a], [:keyrest, :b]], o.method(:bar).parameters, feature7701)
     assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {o.bar(c: bug8139)}
     assert_raise_with_message(ArgumentError, /missing keyword/, bug8139) {o.bar}
+
+    bug9669 = '[ruby-core:61658] [Bug #9669]'
+    assert_nothing_raised(SyntaxError, bug9669) do
+      eval(<<-'end;', nil, __FILE__, __LINE__)
+        def bug9669.foo a:
+          return a
+        end
+      end;
+    end
+    assert_equal(42, bug9669.foo(a: 42))
+    assert_nothing_raised(SyntaxError, bug9669) do
+      eval(<<-'end;', nil, __FILE__, __LINE__)
+        o = {
+          a:
+          1
+        }
+      end;
+    end
+    assert_equal({a: 1}, o, bug9669)
   end
 
   def test_block_required_keyword

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45405,45408


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

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