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

ruby-changes:53425

From: yui-knk <ko1@a...>
Date: Fri, 9 Nov 2018 10:37:46 +0900 (JST)
Subject: [ruby-changes:53425] yui-knk:r65641 (trunk): Rename `AST` module to `AbstractSyntaxTree`

yui-knk	2018-11-09 10:37:41 +0900 (Fri, 09 Nov 2018)

  New Revision: 65641

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65641

  Log:
    Rename `AST` module to `AbstractSyntaxTree`
    
    Follow the same naming convention of `InstructionSequence` class.

  Modified files:
    trunk/NEWS
    trunk/ast.c
    trunk/test/ruby/test_ast.rb
Index: ast.c
===================================================================
--- ast.c	(revision 65640)
+++ ast.c	(revision 65641)
@@ -54,15 +54,15 @@ ast_new_internal(rb_ast_t *ast, NODE *no https://github.com/ruby/ruby/blob/trunk/ast.c#L54
 
 /*
  *  call-seq:
- *     RubyVM::AST.parse(string) -> RubyVM::AST::Node
+ *     RubyVM::AbstractSyntaxTree.parse(string) -> RubyVM::AbstractSyntaxTree::Node
  *
  *  Parses the given string into an abstract syntax tree,
  *  returning the root node of that tree.
  *
  *  SyntaxError is raised if the given string is invalid syntax.
  *
- *    RubyVM::AST.parse("x = 1 + 2")
- *    # => #<RubyVM::AST::Node(NODE_SCOPE(0) 1:0, 1:9): >
+ *    RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
+ *    # => #<RubyVM::AbstractSyntaxTree::Node(NODE_SCOPE(0) 1:0, 1:9): >
  */
 static VALUE
 rb_ast_s_parse(VALUE module, VALUE str)
@@ -88,7 +88,7 @@ rb_ast_s_parse(VALUE module, VALUE str) https://github.com/ruby/ruby/blob/trunk/ast.c#L88
 
 /*
  *  call-seq:
- *     RubyVM::AST.parse_file(pathname) -> RubyVM::AST::Node
+ *     RubyVM::AbstractSyntaxTree.parse_file(pathname) -> RubyVM::AbstractSyntaxTree::Node
  *
  *   Reads the file from <code>pathname</code>, then parses it like ::parse,
  *   returning the root node of the abstract syntax tree.
@@ -96,8 +96,8 @@ rb_ast_s_parse(VALUE module, VALUE str) https://github.com/ruby/ruby/blob/trunk/ast.c#L96
  *   SyntaxError is raised if <code>pathname</code>'s contents are not
  *   valid Ruby syntax.
  *
- *     RubyVM::AST.parse_file("my-app/app.rb")
- *     # => #<RubyVM::AST::Node(NODE_SCOPE(0) 1:0, 31:3): >
+ *     RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb")
+ *     # => #<RubyVM::AbstractSyntaxTree::Node(NODE_SCOPE(0) 1:0, 31:3): >
  */
 static VALUE
 rb_ast_s_parse_file(VALUE module, VALUE path)
@@ -200,7 +200,7 @@ node_type_to_str(NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L200
  *
  *  Returns the type of this node as a string.
  *
- *    root = RubyVM::AST.parse("x = 1 + 2")
+ *    root = RubyVM::AbstractSyntaxTree.parse("x = 1 + 2")
  *    root.type # => "NODE_SCOPE"
  *    call = root.children[2]
  *    call.type # => "NODE_OPCALL"
@@ -659,14 +659,14 @@ void https://github.com/ruby/ruby/blob/trunk/ast.c#L659
 Init_ast(void)
 {
     /*
-     * AST provides methods to parse Ruby code into
+     * AbstractSyntaxTree provides methods to parse Ruby code into
      * abstract syntax trees. The nodes in the tree
-     * are instances of RubyVM::AST::Node.
+     * are instances of RubyVM::AbstractSyntaxTree::Node.
      */
-    rb_mAST = rb_define_module_under(rb_cRubyVM, "AST");
+    rb_mAST = rb_define_module_under(rb_cRubyVM, "AbstractSyntaxTree");
     /*
-     * RubyVM::AST::Node instances are created by parse methods in
-     * RubyVM::AST.
+     * RubyVM::AbstractSyntaxTree::Node instances are created by parse methods in
+     * RubyVM::AbstractSyntaxTree.
      */
     rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject);
 
Index: NEWS
===================================================================
--- NEWS	(revision 65640)
+++ NEWS	(revision 65641)
@@ -226,17 +226,17 @@ sufficient information, see the ChangeLo https://github.com/ruby/ruby/blob/trunk/NEWS#L226
     * Range#step now returns an instance of Enumerator::ArithmeticSequence
       class rather than one of Enumerator class.
 
-[RubyVM::AST]
+[RubyVM::AbstractSyntaxTree]
 
   [New methods]
 
-    * RubyVM::AST.parse parses a given string and returns AST
+    * RubyVM::AbstractSyntaxTree.parse parses a given string and returns AST
       nodes. [experimental]
 
-    * RubyVM::AST.parse_file parses a given file and returns AST
+    * RubyVM::AbstractSyntaxTree.parse_file parses a given file and returns AST
       nodes.  [experimental]
 
-    * RubyVM::AST.of returns AST nodes of the given proc or method.
+    * RubyVM::AbstractSyntaxTree.of returns AST nodes of the given proc or method.
       [experimental]
 
 [String]
Index: test/ruby/test_ast.rb
===================================================================
--- test/ruby/test_ast.rb	(revision 65640)
+++ test/ruby/test_ast.rb	(revision 65641)
@@ -3,7 +3,7 @@ require 'test/unit' https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L3
 require 'tempfile'
 
 class RubyVM
-  module AST
+  module AbstractSyntaxTree
     class Node
       class CodePosition
         include Comparable
@@ -64,14 +64,14 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L64
 
     def ast
       return @ast if defined?(@ast)
-      @ast = RubyVM::AST.parse_file(@path)
+      @ast = RubyVM::AbstractSyntaxTree.parse_file(@path)
     end
 
     private
 
     def validate_range0(node)
       beg_pos, end_pos = node.beg_pos, node.end_pos
-      children = node.children.grep(RubyVM::AST::Node)
+      children = node.children.grep(RubyVM::AbstractSyntaxTree::Node)
 
       return true if children.empty?
       # These NODE_D* has NODE_ARRAY as nd_next->nd_next whose last locations
@@ -99,7 +99,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L99
 
     def validate_not_cared0(node)
       beg_pos, end_pos = node.beg_pos, node.end_pos
-      children = node.children.grep(RubyVM::AST::Node)
+      children = node.children.grep(RubyVM::AbstractSyntaxTree::Node)
 
       @errors << { type: :first_lineno, node: node } if beg_pos.lineno == 0
       @errors << { type: :first_column, node: node } if beg_pos.column == -1
@@ -131,24 +131,24 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L131
   end
 
   def test_allocate
-    assert_raise(TypeError) {RubyVM::AST::Node.allocate}
+    assert_raise(TypeError) {RubyVM::AbstractSyntaxTree::Node.allocate}
   end
 
   def test_column_with_long_heredoc_identifier
     term = "A"*257
-    ast = RubyVM::AST.parse("<<-#{term}\n""ddddddd\n#{term}\n")
+    ast = RubyVM::AbstractSyntaxTree.parse("<<-#{term}\n""ddddddd\n#{term}\n")
     node = ast.children[2]
     assert_equal("NODE_STR", node.type)
     assert_equal(0, node.first_column)
   end
 
   def test_column_of_heredoc
-    node = RubyVM::AST.parse("<<-SRC\nddddddd\nSRC\n").children[2]
+    node = RubyVM::AbstractSyntaxTree.parse("<<-SRC\nddddddd\nSRC\n").children[2]
     assert_equal("NODE_STR", node.type)
     assert_equal(0, node.first_column)
     assert_equal(6, node.last_column)
 
-    node = RubyVM::AST.parse("<<SRC\nddddddd\nSRC\n").children[2]
+    node = RubyVM::AbstractSyntaxTree.parse("<<SRC\nddddddd\nSRC\n").children[2]
     assert_equal("NODE_STR", node.type)
     assert_equal(0, node.first_column)
     assert_equal(5, node.last_column)
@@ -156,7 +156,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L156
 
   def test_parse_raises_syntax_error
     assert_raise_with_message(SyntaxError, /keyword_end/) do
-      RubyVM::AST.parse("end")
+      RubyVM::AbstractSyntaxTree.parse("end")
     end
   end
 
@@ -165,7 +165,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L165
       f.puts "end"
       f.close
       assert_raise_with_message(SyntaxError, /keyword_end/) do
-        RubyVM::AST.parse_file(f.path)
+        RubyVM::AbstractSyntaxTree.parse_file(f.path)
       end
     end
   end
@@ -174,23 +174,23 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L174
     proc = Proc.new { 1 + 2 }
     method = self.method(__method__)
 
-    node_proc = RubyVM::AST.of(proc)
-    node_method = RubyVM::AST.of(method)
+    node_proc = RubyVM::AbstractSyntaxTree.of(proc)
+    node_method = RubyVM::AbstractSyntaxTree.of(method)
 
-    assert_instance_of(RubyVM::AST::Node, node_proc)
-    assert_instance_of(RubyVM::AST::Node, node_method)
-    assert_raise(TypeError) { RubyVM::AST.of("1 + 2") }
+    assert_instance_of(RubyVM::AbstractSyntaxTree::Node, node_proc)
+    assert_instance_of(RubyVM::AbstractSyntaxTree::Node, node_method)
+    assert_raise(TypeError) { RubyVM::AbstractSyntaxTree.of("1 + 2") }
   end
 
   def test_scope_local_variables
-    node = RubyVM::AST.parse("x = 0")
+    node = RubyVM::AbstractSyntaxTree.parse("x = 0")
     lv, _, body = *node.children
     assert_equal([:x], lv)
     assert_equal("NODE_LASGN", body.type)
   end
 
   def test_call
-    node = RubyVM::AST.parse("nil.foo")
+    node = RubyVM::AbstractSyntaxTree.parse("nil.foo")
     _, _, body = *node.children
     assert_equal("NODE_CALL", body.type)
     recv, mid, args = body.children
@@ -200,7 +200,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L200
   end
 
   def test_fcall
-    node = RubyVM::AST.parse("foo()")
+    node = RubyVM::AbstractSyntaxTree.parse("foo()")
     _, _, body = *node.children
     assert_equal("NODE_FCALL", body.type)
     mid, args = body.children
@@ -209,7 +209,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L209
   end
 
   def test_vcall
-    node = RubyVM::AST.parse("foo")
+    node = RubyVM::AbstractSyntaxTree.parse("foo")
     _, _, body = *node.children
     assert_equal("NODE_VCALL", body.type)
     mid, args = body.children
@@ -218,7 +218,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L218
   end
 
   def test_defn
-    node = RubyVM::AST.parse("def a; end")
+    node = RubyVM::AbstractSyntaxTree.parse("def a; end")
     _, _, body = *node.children
     assert_equal("NODE_DEFN", body.type)
     mid, defn = body.children
@@ -227,7 +227,7 @@ class TestAst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_ast.rb#L227
   end
 
   def test_defs
-    node = RubyVM::AST.parse("def a.b; end")
+    node = RubyVM::AbstractSyntaxTree.parse("def a.b; end")
     _, _, body = *node.children
     assert_equal("NODE_DEFS", body.type)
     recv, mid, defn = body.children

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

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