Class: RubyModKit::CorrectorManager
- Inherits:
-
Object
- Object
- RubyModKit::CorrectorManager
- Defined in:
- lib/ruby_mod_kit/corrector_manager.rb
Overview
the class to manege parse error correctors
Instance Method Summary collapse
- #check_prev_errors(generation) ⇒ void
- #initialize(features) ⇒ void constructor
- #perform(generation) ⇒ Boolean
Constructor Details
#initialize(features) ⇒ void
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ruby_mod_kit/corrector_manager.rb', line 15 def initialize(features) @previous_source = +"" @correctors_error_map = {} features.each do |feature| feature.create_correctors.each do |corrector| corrector.correctable_error_types.each do |error_type| (@correctors_error_map[error_type] ||= []) << corrector end end end end |
Instance Method Details
#check_prev_errors(generation) ⇒ void
This method returns an undefined value.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby_mod_kit/corrector_manager.rb', line 55 def check_prev_errors(generation) return if @previous_source.empty? return if generation.errors.empty? return if @previous_source != generation.script = +"" generation.errors.each do |parse_error| << "\n" unless .empty? << "#{generation.name}:#{parse_error.location.start_line}:#{parse_error.message} " << "(#{parse_error.type})" line = generation.line(parse_error) if line << "\n#{line.chomp}\n" << "#{" " * parse_error.location.start_column}^#{"~" * [parse_error.location.length - 1, 0].max}" end end raise RubyModKit::SyntaxError, end |
#perform(generation) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_mod_kit/corrector_manager.rb', line 31 def perform(generation) return true if generation.errors.empty? check_prev_errors(generation) @previous_source = generation.script.dup @correctors_error_map.each_value do |correctors| correctors.each(&:setup) end generation.errors.each do |parse_error| correctors = @correctors_error_map[parse_error.type] || next correctors.each do |corrector| corrector.correct(parse_error, generation) end end false end |