ruby-changes:66288
From: Nobuyoshi <ko1@a...>
Date: Fri, 21 May 2021 18:28:37 +0900 (JST)
Subject: [ruby-changes:66288] 50a534a152 (master): ripper: wrap endless method in bodystmt [Bug #17869]
https://git.ruby-lang.org/ruby.git/commit/?id=50a534a152 From 50a534a1526e2b9f4ea41e44b802bd73f9cebbeb Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 21 May 2021 15:35:30 +0900 Subject: ripper: wrap endless method in bodystmt [Bug #17869] --- parse.y | 16 ++++++++++++---- test/ripper/test_parser_events.rb | 28 ++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/parse.y b/parse.y index 3a03a3e..e669adb 100644 --- a/parse.y +++ b/parse.y @@ -1636,6 +1636,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1636 /*%%%*/ $$ = set_defun_body(p, $1, $2, $4, &@$); /*% %*/ + /*% ripper[$4]: bodystmt!($4, Qnil, Qnil, Qnil) %*/ /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } @@ -1647,7 +1648,8 @@ command_asgn : lhs '=' lex_ctxt command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1648 $4 = rescued_expr(p, $4, $6, &@4, &@5, &@6); $$ = set_defun_body(p, $1, $2, $4, &@$); /*% %*/ - /*% ripper: def!(get_value($1), $2, rescue_mod!($4, $6)) %*/ + /*% ripper[$4]: bodystmt!(rescue_mod!($4, $6), Qnil, Qnil, Qnil) %*/ + /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } | defs_head f_opt_paren_args '=' command @@ -1659,6 +1661,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1661 /*% $1 = get_value($1); %*/ + /*% ripper[$4]: bodystmt!($4, Qnil, Qnil, Qnil) %*/ /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, $4) %*/ local_pop(p); } @@ -1672,7 +1675,8 @@ command_asgn : lhs '=' lex_ctxt command_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L1675 /*% $1 = get_value($1); %*/ - /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, rescue_mod!($4, $6)) %*/ + /*% ripper[$4]: bodystmt!(rescue_mod!($4, $6), Qnil, Qnil, Qnil) %*/ + /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, $4) %*/ local_pop(p); } | backref tOP_ASGN lex_ctxt command_rhs @@ -2557,6 +2561,7 @@ arg : lhs '=' lex_ctxt arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2561 /*%%%*/ $$ = set_defun_body(p, $1, $2, $4, &@$); /*% %*/ + /*% ripper[$4]: bodystmt!($4, Qnil, Qnil, Qnil) %*/ /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } @@ -2568,7 +2573,8 @@ arg : lhs '=' lex_ctxt arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2573 $4 = rescued_expr(p, $4, $6, &@4, &@5, &@6); $$ = set_defun_body(p, $1, $2, $4, &@$); /*% %*/ - /*% ripper: def!(get_value($1), $2, rescue_mod!($4, $6)) %*/ + /*% ripper[$4]: bodystmt!(rescue_mod!($4, $6), Qnil, Qnil, Qnil) %*/ + /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } | defs_head f_opt_paren_args '=' arg @@ -2580,6 +2586,7 @@ arg : lhs '=' lex_ctxt arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2586 /*% $1 = get_value($1); %*/ + /*% ripper[$4]: bodystmt!($4, Qnil, Qnil, Qnil) %*/ /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, $4) %*/ local_pop(p); } @@ -2593,7 +2600,8 @@ arg : lhs '=' lex_ctxt arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2600 /*% $1 = get_value($1); %*/ - /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, rescue_mod!($4, $6)) %*/ + /*% ripper[$4]: bodystmt!(rescue_mod!($4, $6), Qnil, Qnil, Qnil) %*/ + /*% ripper: defs!(AREF($1, 0), AREF($1, 1), AREF($1, 2), $2, $4) %*/ local_pop(p); } | primary diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index 413381e..5bb8f12 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -672,12 +672,12 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L672 thru = {} tree = parse('def foo() = 42', events, &hook) assert_equal({on_def: true}, thru) - assert_equal '[def(foo,[],42)]', tree + assert_equal '[def(foo,[],bodystmt(42))]', tree thru = {} tree = parse('def foo() = 42 rescue 0', events, &hook) assert_equal({on_def: true}, thru) - assert_equal '[def(foo,[],rescue_mod(42,0))]', tree + assert_equal '[def(foo,[],bodystmt(rescue_mod(42,0)))]', tree thru = {} tree = parse('def foo=() = 42', events, &hook) @@ -686,6 +686,16 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L686 thru = {} tree = parse('def foo=() = 42 rescue 0', events, &hook) assert_equal({on_def: true, on_parse_error: true}, thru) + + thru = {} + tree = parse('def foo() = p 42', events, &hook) + assert_equal({on_def: true}, thru) + assert_equal '[def(foo,[],bodystmt(command(p,[42])))]', tree + + thru = {} + tree = parse('def foo() = p 42 rescue 0', events, &hook) + assert_equal({on_def: true}, thru) + assert_equal '[def(foo,[],bodystmt(rescue_mod(command(p,[42]),0)))]', tree end def test_defined @@ -713,12 +723,12 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L723 thru = {} tree = parse('def foo.bar() = 42', events, &hook) assert_equal({on_defs: true}, thru) - assert_equal '[defs(vcall(foo),.,bar,[],42)]', tree + assert_equal '[defs(vcall(foo),.,bar,[],bodystmt(42))]', tree thru = {} tree = parse('def foo.bar() = 42 rescue 0', events, &hook) assert_equal({on_defs: true}, thru) - assert_equal '[defs(vcall(foo),.,bar,[],rescue_mod(42,0))]', tree + assert_equal '[defs(vcall(foo),.,bar,[],bodystmt(rescue_mod(42,0)))]', tree thru = {} tree = parse('def foo.bar=() = 42', events, &hook) @@ -727,6 +737,16 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L737 thru = {} tree = parse('def foo.bar=() = 42 rescue 0', events, &hook) assert_equal({on_defs: true, on_parse_error: true}, thru) + + thru = {} + tree = parse('def foo.bar() = p 42', events, &hook) + assert_equal({on_defs: true}, thru) + assert_equal '[defs(vcall(foo),.,bar,[],bodystmt(command(p,[42])))]', tree + + thru = {} + tree = parse('def foo.bar() = p 42 rescue 0', events, &hook) + assert_equal({on_defs: true}, thru) + assert_equal '[defs(vcall(foo),.,bar,[],bodystmt(rescue_mod(command(p,[42]),0)))]', tree end def test_do_block -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/