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

Treat `super` like a method call

上级 ea7c0d1f
......@@ -147,8 +147,14 @@ class Sexp
#s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1)))
# ^- method
def method
expect :call, :attrasgn
expect :call, :attrasgn, :super, :zsuper
case self.node_type
when :call, :attrasgn
self[2]
when :super, :zsuper
:super
end
end
#Sets the arglist in a method call.
......@@ -165,8 +171,18 @@ class Sexp
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
# ^------------ arglist ------------^
def arglist
expect :call, :attrasgn
expect :call, :attrasgn, :super, :zsuper
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
#Sexp.new(:arglist, *self[3..-1])
......@@ -177,7 +193,7 @@ class Sexp
# s(:call, s(:call, nil, :x, s(:arglist)), :y, s(:arglist, s(:lit, 1), s(:lit, 2)))
# ^--------args--------^
def args
expect :call, :attrasgn
expect :call, :attrasgn, :super, :zsuper
#For new ruby_parser
#if self[3]
# self[3..-1]
......@@ -185,12 +201,21 @@ class Sexp
# []
#end
case self.node_type
when :call, :attrasgn
#For old ruby_parser
if self[3]
self[3][1..-1]
else
[]
end
when :super, :zsuper
if self[1]
self[1..-1]
else
[]
end
end
end
#Returns first argument of a method call.
......
......@@ -233,7 +233,7 @@ class SexpTests < Test::Unit::TestCase
assert_equal :super, exp.method
assert_equal s(:arglist), exp.arglist
assert_equal s(), exp.args
assert_equal [], exp.args
end
def test_super_call
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册