Permalink
Browse files

replace last ruby_parser dependency with coderay

  • Loading branch information...
1 parent 6512d82 commit 8913ee3f30cd998f8889eca7867f9ff3db1ad2d3 @rf- rf- committed Nov 27, 2011
Showing with 4 additions and 31 deletions.
  1. +0 −1 Rakefile
  2. +4 −30 lib/pry/method.rb
View
@@ -20,7 +20,6 @@ def apply_spec_defaults(s)
s.executables = ["pry"]
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n")
- s.add_dependency("ruby_parser",">= 2.3.1")
s.add_dependency("coderay","~>0.9.8")
s.add_dependency("slop","~>2.2.0")
s.add_dependency("method_source","~>0.6.7")
View
@@ -282,43 +282,17 @@ def super(times=1)
Pry::Method.new(sup) if sup
end
- # @return [Symbol, nil] The original name the method was defined under,
+ # @return [String, nil] The original name the method was defined under,
# before any aliasing, or `nil` if it can't be determined.
def original_name
return nil if source_type != :ruby
first_line = source.lines.first
return nil if first_line.strip !~ /^def /
- if RUBY_VERSION =~ /^1\.9/ && RUBY_ENGINE == "ruby"
- require 'ripper'
-
- # Ripper is ok with an extraneous end, so we don't need to worry about
- # whether it's a one-liner.
- tree = Ripper::SexpBuilder.new(first_line + ";end").parse
-
- name = tree.flatten(2).each do |lst|
- break lst[1] if lst[0] == :@ident
- end
-
- name.is_a?(String) ? name : nil
- else
- require 'ruby_parser'
-
- # RubyParser breaks if there's an extra end, so we'll just rescue
- # and try again.
- tree = begin
- RubyParser.new.parse(first_line + ";end")
- rescue Racc::ParseError
- RubyParser.new.parse(first_line)
- end
-
- name = tree.each_cons(2) do |a, b|
- break a if b.is_a?(Array) && b.first == :args
- end
-
- name.is_a?(Symbol) ? name.to_s : nil
- end
+ CodeRay.scan(first_line, :ruby).
+ detect { |token| [:method, :ident].include?(token.last) }.
+ first rescue nil
end
# @return [Boolean] Was the method defined outside a source file?

0 comments on commit 8913ee3

Please sign in to comment.