Skip to content

Commit

Permalink
Merge d38510d into 6f35b6f
Browse files Browse the repository at this point in the history
  • Loading branch information
flyerhzm committed Jan 9, 2021
2 parents 6f35b6f + d38510d commit 119e9c6
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions lib/synvert/core/rewriter/instance.rb
Expand Up @@ -88,39 +88,38 @@ def initialize(rewriter, file_pattern, options={}, &block)
def process
file_pattern = File.join(Configuration.instance.get(:path), @file_pattern)
Dir.glob(file_pattern).each do |file_path|
unless Configuration.instance.get(:skip_files).include? file_path
begin
conflict_actions = []
source = self.class.file_source(file_path)
ast = self.class.file_ast(file_path)

@current_file = file_path

self.process_with_node ast do
begin
instance_eval &@block
rescue NoMethodError
puts @current_node.debug_info
raise
end
next if Configuration.instance.get(:skip_files).include? file_path
begin
conflict_actions = []
source = self.class.file_source(file_path)
ast = self.class.file_ast(file_path)

@current_file = file_path

self.process_with_node ast do
begin
instance_eval &@block
rescue NoMethodError
puts @current_node.debug_info
raise
end
end

if @actions.length > 0
@actions.sort_by! { |action| action.send(@options[:sort_by]) }
conflict_actions = get_conflict_actions
@actions.reverse.each do |action|
source[action.begin_pos...action.end_pos] = action.rewritten_code
source = remove_code_or_whole_line(source, action.line)
end
@actions = []

self.class.write_file(file_path, source)
if @actions.length > 0
@actions.sort_by! { |action| action.send(@options[:sort_by]) }
conflict_actions = get_conflict_actions
@actions.reverse.each do |action|
source[action.begin_pos...action.end_pos] = action.rewritten_code
source = remove_code_or_whole_line(source, action.line)
end
rescue Parser::SyntaxError
puts "[Warn] file #{file_path} was not parsed correctly."
# do nothing, iterate next file
end while !conflict_actions.empty?
end
@actions = []

self.class.write_file(file_path, source)
end
rescue Parser::SyntaxError
puts "[Warn] file #{file_path} was not parsed correctly."
# do nothing, iterate next file
end while !conflict_actions.empty?
end
end

Expand Down

0 comments on commit 119e9c6

Please sign in to comment.