Skip to content

Commit

Permalink
fix 'NestingError: nesting of 100 is too deep' error
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 12, 2016
1 parent 30dd55c commit 6f8380a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/yinwang/rubysonar/AstCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


/**
* Provides a factory for python source ASTs. Maintains configurable on-disk and
* Provides a factory for ruby source ASTs. Maintains configurable on-disk and
* in-memory caches to avoid re-parsing files during analysis.
*/
public class AstCache {
Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/org/yinwang/rubysonar/ruby/dump_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -882,13 +882,21 @@ def negate(exp)

end

def hash_nest_max hash
if hash.is_a?(Array)
hash.map{ |e| (hash_nest_max e).to_i }.max.to_i + 1
elsif hash.is_a?(Hash)
hash.values.map{ |s| (hash_nest_max s).to_i }.max.to_i + 1
else
0
end
end

def parse_dump(input, output, endmark)
begin
simplifier = AstSimplifier.new(input)
hash = simplifier.simplify

json_string = JSON.pretty_generate(hash)
json_string = JSON.pretty_generate(hash, max_nesting: (hash_nest_max hash))
out = File.open(output, 'wb')
out.write(json_string)
out.close
Expand Down

0 comments on commit 6f8380a

Please sign in to comment.