提交 fa9da064 编写于 作者: J Justin Collins

Treat `super` like a method call

上级 ea7c0d1f
...@@ -147,8 +147,14 @@ class Sexp ...@@ -147,8 +147,14 @@ class Sexp
#s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1))) #s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
# ^- method # ^- method
def method def method
expect :call, :attrasgn expect :call, :attrasgn, :super, :zsuper
self[2]
case self.node_type
when :call, :attrasgn
self[2]
when :super, :zsuper
:super
end
end end
#Sets the arglist in a method call. #Sets the arglist in a method call.
...@@ -165,8 +171,18 @@ class Sexp ...@@ -165,8 +171,18 @@ class Sexp
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2))) # s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
# ^------------ arglist ------------^ # ^------------ arglist ------------^
def arglist def arglist
expect :call, :attrasgn expect :call, :attrasgn, :super, :zsuper
self[3]
case self.node_type
when :call, :attrasgn
self[3]
when :super, :zsuper
if self[1]
Sexp.new(:arglist).concat self[1..-1]
else
Sexp.new(:arglist)
end
end
#For new ruby_parser #For new ruby_parser
#Sexp.new(:arglist, *self[3..-1]) #Sexp.new(:arglist, *self[3..-1])
...@@ -177,7 +193,7 @@ class Sexp ...@@ -177,7 +193,7 @@ class Sexp
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2))) # s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
# ^--------args--------^ # ^--------args--------^
def args def args
expect :call, :attrasgn expect :call, :attrasgn, :super, :zsuper
#For new ruby_parser #For new ruby_parser
#if self[3] #if self[3]
# self[3..-1] # self[3..-1]
...@@ -185,11 +201,20 @@ class Sexp ...@@ -185,11 +201,20 @@ class Sexp
# [] # []
#end #end
#For old ruby_parser case self.node_type
if self[3] when :call, :attrasgn
self[3][1..-1] #For old ruby_parser
else if self[3]
[] self[3][1..-1]
else
[]
end
when :super, :zsuper
if self[1]
self[1..-1]
else
[]
end
end end
end end
...@@ -345,7 +370,7 @@ class Sexp ...@@ -345,7 +370,7 @@ class Sexp
#Sets body #Sets body
def body= exp def body= exp
expect :defn, :defs, :methdef, :selfdef, :class, :module expect :defn, :defs, :methdef, :selfdef, :class, :module
case self.node_type case self.node_type
when :defn, :methdef, :class when :defn, :methdef, :class
self[3] = exp self[3] = exp
...@@ -392,7 +417,7 @@ end ...@@ -392,7 +417,7 @@ end
[:[]=, :clear, :collect!, :compact!, :concat, :delete, :delete_at, [:[]=, :clear, :collect!, :compact!, :concat, :delete, :delete_at,
:delete_if, :drop, :drop_while, :fill, :flatten!, :replace, :insert, :delete_if, :drop, :drop_while, :fill, :flatten!, :replace, :insert,
:keep_if, :map!, :pop, :push, :reject!, :replace, :reverse!, :rotate!, :keep_if, :map!, :pop, :push, :reject!, :replace, :reverse!, :rotate!,
:select!, :shift, :shuffle!, :slice!, :sort!, :sort_by!, :transpose, :select!, :shift, :shuffle!, :slice!, :sort!, :sort_by!, :transpose,
:uniq!, :unshift].each do |method| :uniq!, :unshift].each do |method|
Sexp.class_eval <<-RUBY Sexp.class_eval <<-RUBY
......
...@@ -233,7 +233,7 @@ class SexpTests < Test::Unit::TestCase ...@@ -233,7 +233,7 @@ class SexpTests < Test::Unit::TestCase
assert_equal :super, exp.method assert_equal :super, exp.method
assert_equal s(:arglist), exp.arglist assert_equal s(:arglist), exp.arglist
assert_equal s(), exp.args assert_equal [], exp.args
end end
def test_super_call def test_super_call
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册