Skip to content

Commit

Permalink
+ Added --18 and --19 flags to specify parser. Defaults to hybrid.
Browse files Browse the repository at this point in the history
- Cleaned up some 1.9 warnings.
+ Modified processor to deal with cleaner sexps from RP 3.x.

[git-p4: depot-paths = "//src/flog/dev/": change = 7666]
  • Loading branch information
zenspider committed Jul 21, 2012
1 parent 9671669 commit b1ce791
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/flog.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def self.parse_options args = ARGV
option = { option = {
:quiet => true, :quiet => true,
:continue => false, :continue => false,
:parser => RubyParser,
} }


OptionParser.new do |opts| OptionParser.new do |opts|
Expand Down Expand Up @@ -185,6 +186,14 @@ def self.parse_options args = ARGV
option[:verbose] = true option[:verbose] = true
end end


opts.on("--18", "Use a ruby 1.8 parser.") do
option[:parser] = Ruby18Parser
end

opts.on("--19", "Use a ruby 1.9 parser.") do
option[:parser] = Ruby19Parser
end

next if self.plugins.empty? next if self.plugins.empty?
opts.separator "Plugin options:" opts.separator "Plugin options:"


Expand Down Expand Up @@ -251,7 +260,7 @@ def flog(*files_or_dirs)
mass[file] = ast.mass mass[file] = ast.mass
process ast process ast
rescue RegexpError, SyntaxError, Racc::ParseError => e rescue RegexpError, SyntaxError, Racc::ParseError => e
if e.inspect =~ /<%|%>/ or ruby =~ /<%|%>/ then if e.inspect =~ /<\%|%\>/ or ruby =~ /<\%|%\>/ then
warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}" warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}"
warn "\n...stupid lemmings and their bad erb templates... skipping" warn "\n...stupid lemmings and their bad erb templates... skipping"
else else
Expand Down Expand Up @@ -308,7 +317,7 @@ def initialize option = {}
@method_stack = [] @method_stack = []
@method_locations = {} @method_locations = {}
@mass = {} @mass = {}
@parser = Ruby18Parser.new @parser = option[:parser].new
self.auto_shift_type = true self.auto_shift_type = true
self.reset self.reset
end end
Expand Down Expand Up @@ -514,7 +523,7 @@ def process_attrasgn(exp)
add_to_score :assignment add_to_score :assignment
process exp.shift # lhs process exp.shift # lhs
exp.shift # name exp.shift # name
process exp.shift # rhs process_until_empty exp # rhs
s() s()
end end


Expand Down Expand Up @@ -552,9 +561,11 @@ def process_call(exp)
penalize_by 0.2 do penalize_by 0.2 do
process exp.shift # recv process exp.shift # recv
end end

name = exp.shift name = exp.shift

penalize_by 0.2 do penalize_by 0.2 do
process exp.shift # args process_until_empty exp
end end


add_to_score name, SCORES[name] add_to_score name, SCORES[name]
Expand Down

0 comments on commit b1ce791

Please sign in to comment.