Rename `AST` module to `AbstractSyntaxTree`

Follow the same naming convention of `InstructionSequence` class.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
yui-knk 2018-11-09 01:37:41 +00:00
Родитель f67c0e5671
Коммит 1d7d08262e
3 изменённых файлов: 37 добавлений и 37 удалений

8
NEWS
Просмотреть файл

@ -226,17 +226,17 @@ sufficient information, see the ChangeLog file or Redmine
* 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]

24
ast.c
Просмотреть файл

@ -54,15 +54,15 @@ ast_new_internal(rb_ast_t *ast, NODE *node)
/*
* 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)
/*
* 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)
* 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)
*
* 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
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);

Просмотреть файл

@ -3,7 +3,7 @@ require 'test/unit'
require 'tempfile'
class RubyVM
module AST
module AbstractSyntaxTree
class Node
class CodePosition
include Comparable
@ -64,14 +64,14 @@ class TestAst < Test::Unit::TestCase
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
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
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
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
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
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
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
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
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
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