From fa9da064d7e5e639e51e97c550e41b4353cff4b0 Mon Sep 17 00:00:00 2001 From: Justin Collins Date: Mon, 10 Sep 2012 18:03:27 -0700 Subject: [PATCH] Treat `super` like a method call --- lib/ruby_parser/bm_sexp.rb | 49 ++++++++++++++++++++++++++++---------- test/tests/test_sexp.rb | 2 +- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/lib/ruby_parser/bm_sexp.rb b/lib/ruby_parser/bm_sexp.rb index 8694d77d..bba287f6 100644 --- a/lib/ruby_parser/bm_sexp.rb +++ b/lib/ruby_parser/bm_sexp.rb @@ -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 - self[2] + 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 - self[3] + 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,11 +201,20 @@ class Sexp # [] #end - #For old ruby_parser - if self[3] - self[3][1..-1] - else - [] + 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 @@ -345,7 +370,7 @@ class Sexp #Sets body def body= exp expect :defn, :defs, :methdef, :selfdef, :class, :module - + case self.node_type when :defn, :methdef, :class self[3] = exp @@ -392,7 +417,7 @@ end [:[]=, :clear, :collect!, :compact!, :concat, :delete, :delete_at, :delete_if, :drop, :drop_while, :fill, :flatten!, :replace, :insert, :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| Sexp.class_eval <<-RUBY diff --git a/test/tests/test_sexp.rb b/test/tests/test_sexp.rb index bea90d5e..2de7b9a5 100644 --- a/test/tests/test_sexp.rb +++ b/test/tests/test_sexp.rb @@ -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 -- GitLab