diff --git a/NEWS b/NEWS index 3c692fcd89..a4b07925b3 100644 --- a/NEWS +++ b/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] diff --git a/ast.c b/ast.c index babfc1fbf6..a64278f8c7 100644 --- a/ast.c +++ b/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::AbstractSyntaxTree.parse("x = 1 + 2") + * # => # */ 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 pathname, 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 pathname's contents are not * valid Ruby syntax. * - * RubyVM::AST.parse_file("my-app/app.rb") - * # => # + * RubyVM::AbstractSyntaxTree.parse_file("my-app/app.rb") + * # => # */ 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); diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 70f0b4af1f..e8b25fd7d6 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -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("<