ruby-changes:46520
From: nobu <ko1@a...>
Date: Wed, 10 May 2017 02:20:10 +0900 (JST)
Subject: [ruby-changes:46520] nobu:r58641 (trunk): parse.y: brace after literal arg
nobu 2017-05-10 02:20:00 +0900 (Wed, 10 May 2017) New Revision: 58641 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58641 Log: parse.y: brace after literal arg * parse.y (symbol, dsym, parser_set_number_literal, parser_yylex): set state to END too not only ENDARG and after a literal, so that a left brace after it should be a primary block bound to the literal, which causes syntax error. [ruby-core:81037] [Bug #13547] Modified files: trunk/parse.y trunk/test/ruby/test_syntax.rb Index: parse.y =================================================================== --- parse.y (revision 58640) +++ parse.y (revision 58641) @@ -4049,7 +4049,7 @@ string_dvar : tGVAR https://github.com/ruby/ruby/blob/trunk/parse.y#L4049 symbol : tSYMBEG sym { - SET_LEX_STATE(EXPR_ENDARG); + SET_LEX_STATE(EXPR_END|EXPR_ENDARG); /*%%%*/ $$ = $2; /*% @@ -4066,7 +4066,7 @@ sym : fname https://github.com/ruby/ruby/blob/trunk/parse.y#L4066 dsym : tSYMBEG xstring_contents tSTRING_END { - SET_LEX_STATE(EXPR_ENDARG); + SET_LEX_STATE(EXPR_END|EXPR_ENDARG); /*%%%*/ $$ = dsym_node($2); /*% @@ -6526,7 +6526,7 @@ parser_set_number_literal(struct parser_ https://github.com/ruby/ruby/blob/trunk/parse.y#L6526 type = tIMAGINARY; } set_yylval_literal(v); - SET_LEX_STATE(EXPR_ENDARG); + SET_LEX_STATE(EXPR_END|EXPR_ENDARG); return type; } @@ -7884,9 +7884,11 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7884 } } if (token == tSTRING_END || token == tREGEXP_END || token == tLABEL_END) { + const enum lex_state_e next_state = + token == tLABEL_END ? EXPR_BEG|EXPR_LABEL : EXPR_END|EXPR_ENDARG; rb_gc_force_recycle((VALUE)lex_strterm); lex_strterm = 0; - SET_LEX_STATE(token == tLABEL_END ? EXPR_BEG|EXPR_LABEL : EXPR_ENDARG); + SET_LEX_STATE(next_state); } } return token; Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 58640) +++ test/ruby/test_syntax.rb (revision 58641) @@ -952,6 +952,16 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L952 assert_equal(:ok, result) end + def test_brace_after_literal_argument + bug = '[ruby-core:81037] [Bug #13547]' + error = /unexpected '{'/ + assert_syntax_error('m "x" {}', error) + assert_syntax_error('m 1 {}', error, bug) + assert_syntax_error('m 1.0 {}', error, bug) + assert_syntax_error('m :m {}', error, bug) + assert_syntax_error('m :"#{m}" {}', error, bug) + end + def test_return_toplevel feature4840 = '[ruby-core:36785] [Feature #4840]' code = "#{<<~"begin;"}\n#{<<~"end;"}" -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/