ruby-changes:33326
From: nobu <ko1@a...>
Date: Tue, 25 Mar 2014 16:47:43 +0900 (JST)
Subject: [ruby-changes:33326] nobu:r45405 (trunk): parse.y: required kwarg without parentheses
nobu 2014-03-25 16:47:37 +0900 (Tue, 25 Mar 2014) New Revision: 45405 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45405 Log: parse.y: required kwarg without parentheses * 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] Modified files: trunk/ChangeLog trunk/parse.y trunk/test/ruby/test_keyword.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45404) +++ ChangeLog (revision 45405) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Mar 25 16:47:36 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] + Mon Mar 24 22:19:56 2014 Nobuyoshi Nakada <nobu@r...> * parse.y (ripper_initialize): filename can not be modified. Index: parse.y =================================================================== --- parse.y (revision 45404) +++ parse.y (revision 45405) @@ -74,6 +74,7 @@ enum lex_state_bits { https://github.com/ruby/ruby/blob/trunk/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/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/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; @@ -4402,9 +4405,14 @@ f_arglist : '(' f_args rparen https://github.com/ruby/ruby/blob/trunk/parse.y#L4405 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; } @@ -8147,7 +8155,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8155 if (IS_LABEL_POSSIBLE()) { if (IS_LABEL_SUFFIX(0)) { - lex_state = EXPR_BEG; + lex_state = EXPR_LABELARG; nextc(); set_yylval_name(TOK_INTERN()); return tLABEL; @@ -10861,6 +10869,7 @@ parser_initialize(struct parser_params * https://github.com/ruby/ruby/blob/trunk/parse.y#L10869 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: test/ruby/test_keyword.rb =================================================================== --- test/ruby/test_keyword.rb (revision 45404) +++ test/ruby/test_keyword.rb (revision 45405) @@ -325,6 +325,16 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/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)) end def test_block_required_keyword -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/