mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
replace last ruby_parser dependency with coderay
This commit is contained in:
parent
6512d82b7f
commit
8913ee3f30
2 changed files with 4 additions and 31 deletions
1
Rakefile
1
Rakefile
|
@ -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")
|
||||
|
|
|
@ -282,7 +282,7 @@ class Pry
|
|||
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
|
||||
|
@ -290,35 +290,9 @@ class Pry
|
|||
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?
|
||||
|
|
Loading…
Add table
Reference in a new issue