summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.y16
-rw-r--r--test/ripper/test_parser_events.rb28
2 files changed, 36 insertions, 8 deletions
diff --git a/parse.y b/parse.y
index 3a03a3e030d..e669adbcd5d 100644
--- a/parse.y
+++ b/parse.y
@@ -1636,6 +1636,7 @@ command_asgn : lhs '=' lex_ctxt command_rhs
/*%%%*/
$$ = 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
$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
/*%
$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
/*%
$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
/*%%%*/
$$ = 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
$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
/*%
$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
/*%
$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 413381ed1fb..5bb8f120f2f 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
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
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
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
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