Skip to content

Commit

Permalink
Switched to ruby_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrutherford committed May 18, 2009
1 parent 4f33719 commit 46e5b18
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
6 changes: 6 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
== 1.2.0 (In progress)

=== Major Enhancements
* Switched from ParseTree to ruby_parser for source code parsing
* 'MyClass.should_not reek' now only possible if ParseTree gem installed

== 1.1.1 2009-05-08

=== Minor enhancements
Expand Down
1 change: 0 additions & 1 deletion lib/reek/code_parser.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'rubygems'
require 'parse_tree'
require 'sexp_processor'
require 'reek/block_context'
require 'reek/class_context'
Expand Down
2 changes: 1 addition & 1 deletion lib/reek/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.resolve(exp, context)

def self.resolve_string(str, context)
return [context, new(str)] unless str =~ /::/
resolve(ParseTree.new.parse_tree_for_string(str)[0], context)
resolve(RubyParser.new.parse(str), context)
end

def initialize(sym)
Expand Down
66 changes: 30 additions & 36 deletions lib/reek/object_source.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
module Reek
def can_parse_objects?
begin
require 'parse_tree'
true
rescue LoadError
false
class Source
#
# Factory method: creates a +Source+ from obj.
# The code is not parsed until +report+ is called.
# (This feature is only enabled if you have the ParseTree gem installed.)
#
def self.from_object(obj)
return ObjectSource.new(obj, obj.to_s)
end
end
module_function :can_parse_objects?
end

if Reek.can_parse_objects?
module Reek
class Source
#
# Factory method: creates a +Source+ from obj.
# The code is not parsed until +report+ is called.
# (This feature is only enabled if you have the ParseTree gem installed.)
#
def self.from_object(obj)
return ObjectSource.new(obj, obj.to_s)
class ObjectSource < Source # :nodoc:
def can_parse_objects?
return true if Object.const_defined?(:ParseTree)
begin
require 'parse_tree'
true
rescue LoadError
false
end
end

class ObjectSource < Source # :nodoc:
def check(parser) # :nodoc:
def check(parser) # :nodoc:
if can_parse_objects?
sexp = CodeParser.unify(ParseTree.new.parse_tree(@source))
parser.process(sexp)
else
throw ArgumentError.new('You must install the ParseTree gem to use this feature')
end
end
end
end

class Object
#
# Constructs a Source representing this object; the source can then be used
# to generate an abstract syntax tree for the object, which can in turn then
# be examined for code smells.
# (This feature is only enabled if you have the ParseTree gem installed.)
#
def to_source
Reek::Source.from_object(self)
end
end
else
class Object
def to_source
throw ArgumentError.new('You must install the ParseTree gem to use this feature')
end
class Object
#
# Constructs a Source representing this object; the source can then be used
# to generate an abstract syntax tree for the object, which can in turn then
# be examined for code smells.
# (This feature is only enabled if you have the ParseTree gem installed.)
#
def to_source
Reek::Source.from_object(self)
end
end
3 changes: 2 additions & 1 deletion lib/reek/source.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'reek/code_parser'
require 'reek/report'
require 'reek/smells/smells'
require 'ruby_parser'

module Reek

Expand Down Expand Up @@ -65,7 +66,7 @@ def initialize(code, desc, dir = nil) # :nodoc:
end

def check(parser) # :nodoc:
sexp = CodeParser.unify(ParseTree.new.parse_tree_for_string(@source))
sexp = RubyParser.new.parse(@source, @desc)
parser.process(sexp)
end

Expand Down
2 changes: 1 addition & 1 deletion tasks/deployment.rake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $gemspec = Gem::Specification.new do |s|
s.email = ['kevin@rutherford-software.com']
s.homepage = 'http://wiki.github.com/kevinrutherford/reek'
s.rubyforge_project = PROJECT_NAME
s.add_dependency('ParseTree', '~> 3.0')
s.add_dependency('ruby_parser', '~> 2.0')
s.add_dependency('ruby2ruby', '~> 1.2')
s.add_dependency('sexp_processor', '~> 3.0')
s.files = File.read(GEM_MANIFEST).delete("\r").split(/\n/)
Expand Down

0 comments on commit 46e5b18

Please sign in to comment.