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

ruby-changes:62153

From: manga_osyo <ko1@a...>
Date: Wed, 8 Jul 2020 17:43:23 +0900 (JST)
Subject: [ruby-changes:62153] ff5e660340 (master): Added `NODE_SPECIAL_EXCESSIVE_COMMA` info to `ARGS` of `RubyVM::AbstractSyntaxTree`.

https://git.ruby-lang.org/ruby.git/commit/?id=ff5e660340

From ff5e66034006a875125581114cce19d46843b32a Mon Sep 17 00:00:00 2001
From: manga_osyo <manga.osyo@g...>
Date: Tue, 7 Jul 2020 20:18:18 +0900
Subject: Added `NODE_SPECIAL_EXCESSIVE_COMMA` info to `ARGS` of
 `RubyVM::AbstractSyntaxTree`.


diff --git a/ast.c b/ast.c
index 27a1074..575458f 100644
--- a/ast.c
+++ b/ast.c
@@ -547,7 +547,9 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L547
                                         var_name(ainfo->first_post_arg),
                                         INT2NUM(ainfo->post_args_num),
                                         NEW_CHILD(ast, ainfo->post_init),
-                                        var_name(ainfo->rest_arg),
+                                        (ainfo->rest_arg == NODE_SPECIAL_EXCESSIVE_COMMA
+                                            ? ID2SYM(rb_intern("NODE_SPECIAL_EXCESSIVE_COMMA"))
+                                            : var_name(ainfo->rest_arg)),
                                         (ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_args)),
                                         (ainfo->no_kwarg ? Qfalse : NEW_CHILD(ast, ainfo->kw_rest_arg)),
                                         var_name(ainfo->block_arg));
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index da7dde4..0d846b7 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -330,4 +330,19 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L330
     assert_equal(:+, op)
     assert_equal(:VCALL, value.type)
   end
+
+  def test_args
+    rest = 6
+    node = RubyVM::AbstractSyntaxTree.parse("proc { |a| }")
+    _, args = *node.children.last.children[1].children
+    assert_equal(nil, args.children[rest])
+
+    node = RubyVM::AbstractSyntaxTree.parse("proc { |a,| }")
+    _, args = *node.children.last.children[1].children
+    assert_equal(:NODE_SPECIAL_EXCESSIVE_COMMA, args.children[rest])
+
+    node = RubyVM::AbstractSyntaxTree.parse("proc { |*a| }")
+    _, args = *node.children.last.children[1].children
+    assert_equal(:a, args.children[rest])
+  end
 end
-- 
cgit v0.10.2


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

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