mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Define AST module under RubyVM [experimental]
* ext/-test-/ast/ast.c: Rename to ast.c and define AST module under RubyVM. * common.mk: compile ast.c. * ext/-test-/ast/extconf.rb: Don't need this file anymore. * inits.c (rb_call_inits): Call Init_ast to setup AST module. * test/-ext-/ast/test_ast.rb: Follow up the namespace change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63534 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c7c9635360
commit
46463af983
5 changed files with 38 additions and 32 deletions
|
|
@ -479,7 +479,7 @@ rb_ast_node_inspect(VALUE self)
|
||||||
void
|
void
|
||||||
Init_ast(void)
|
Init_ast(void)
|
||||||
{
|
{
|
||||||
rb_mAST = rb_define_module("AST");
|
rb_mAST = rb_define_module_under(rb_cRubyVM, "AST");
|
||||||
rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject);
|
rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject);
|
||||||
|
|
||||||
rb_define_alloc_func(rb_cNode, rb_ast_node_alloc);
|
rb_define_alloc_func(rb_cNode, rb_ast_node_alloc);
|
||||||
|
|
@ -75,6 +75,7 @@ MAKE_ENC = -f $(ENC_MK) V="$(V)" UNICODE_HDR_DIR="$(UNICODE_HDR_DIR)" \
|
||||||
RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(mflags)
|
RUBY="$(MINIRUBY)" MINIRUBY="$(MINIRUBY)" $(mflags)
|
||||||
|
|
||||||
COMMONOBJS = array.$(OBJEXT) \
|
COMMONOBJS = array.$(OBJEXT) \
|
||||||
|
ast.$(OBJEXT) \
|
||||||
bignum.$(OBJEXT) \
|
bignum.$(OBJEXT) \
|
||||||
class.$(OBJEXT) \
|
class.$(OBJEXT) \
|
||||||
compar.$(OBJEXT) \
|
compar.$(OBJEXT) \
|
||||||
|
|
@ -1445,6 +1446,12 @@ array.$(OBJEXT): {$(VPATH)}ruby_assert.h
|
||||||
array.$(OBJEXT): {$(VPATH)}st.h
|
array.$(OBJEXT): {$(VPATH)}st.h
|
||||||
array.$(OBJEXT): {$(VPATH)}subst.h
|
array.$(OBJEXT): {$(VPATH)}subst.h
|
||||||
array.$(OBJEXT): {$(VPATH)}util.h
|
array.$(OBJEXT): {$(VPATH)}util.h
|
||||||
|
ast.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||||
|
ast.$(OBJEXT): $(top_srcdir)/include/ruby.h
|
||||||
|
ast.$(OBJEXT): {$(VPATH)}encoding.h
|
||||||
|
ast.$(OBJEXT): {$(VPATH)}internal.h
|
||||||
|
ast.$(OBJEXT): {$(VPATH)}node.h
|
||||||
|
ast.$(OBJEXT): {$(VPATH)}vm_core.h
|
||||||
bignum.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
bignum.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||||
bignum.$(OBJEXT): $(top_srcdir)/include/ruby.h
|
bignum.$(OBJEXT): $(top_srcdir)/include/ruby.h
|
||||||
bignum.$(OBJEXT): {$(VPATH)}bignum.c
|
bignum.$(OBJEXT): {$(VPATH)}bignum.c
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
# frozen_string_literal: false
|
|
||||||
require_relative "../auto_ext.rb"
|
|
||||||
auto_ext(inc: true)
|
|
||||||
1
inits.c
1
inits.c
|
|
@ -61,5 +61,6 @@ rb_call_inits(void)
|
||||||
CALL(Complex);
|
CALL(Complex);
|
||||||
CALL(version);
|
CALL(version);
|
||||||
CALL(vm_trace);
|
CALL(vm_trace);
|
||||||
|
CALL(ast);
|
||||||
}
|
}
|
||||||
#undef CALL
|
#undef CALL
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require "-test-/ast"
|
|
||||||
|
|
||||||
module AST
|
class RubyVM
|
||||||
|
module AST
|
||||||
class Node
|
class Node
|
||||||
class CodePosition
|
class CodePosition
|
||||||
include Comparable
|
include Comparable
|
||||||
|
|
@ -34,6 +34,7 @@ module AST
|
||||||
|
|
||||||
alias to_s inspect
|
alias to_s inspect
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestAst < Test::Unit::TestCase
|
class TestAst < Test::Unit::TestCase
|
||||||
|
|
@ -62,7 +63,7 @@ class TestAst < Test::Unit::TestCase
|
||||||
|
|
||||||
def ast
|
def ast
|
||||||
return @ast if defined?(@ast)
|
return @ast if defined?(@ast)
|
||||||
ast = AST.parse_file(@path)
|
ast = RubyVM::AST.parse_file(@path)
|
||||||
raise "Syntax error: #{@path}" if ast.nil?
|
raise "Syntax error: #{@path}" if ast.nil?
|
||||||
@ast = ast
|
@ast = ast
|
||||||
end
|
end
|
||||||
|
|
@ -132,7 +133,7 @@ class TestAst < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_column_with_long_heredoc_identifier
|
def test_column_with_long_heredoc_identifier
|
||||||
term = "A"*257
|
term = "A"*257
|
||||||
ast = AST.parse("<<-#{term}\n""ddddddd\n#{term}\n")
|
ast = RubyVM::AST.parse("<<-#{term}\n""ddddddd\n#{term}\n")
|
||||||
node = ast.children[1]
|
node = ast.children[1]
|
||||||
assert_equal("NODE_STR", node.type)
|
assert_equal("NODE_STR", node.type)
|
||||||
assert_equal(0, node.first_column)
|
assert_equal(0, node.first_column)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue