Module: Enolib::Errors::Parsing
- Defined in:
- lib/enolib/errors/parsing.rb
Constant Summary collapse
- UNTERMINATED_ESCAPED_KEY =
/^\s*#*\s*(`+)(?!`)((?:(?!\1).)+)$/.freeze
Class Method Summary collapse
- .cyclic_dependency(context, instruction, instruction_chain) ⇒ Object
- .invalid_line(context, instruction) ⇒ Object
- .missing_element_for_continuation(context, continuation) ⇒ Object
- .missing_fieldset_for_fieldset_entry(context, entry) ⇒ Object
- .missing_list_for_list_item(context, item) ⇒ Object
- .non_section_element_not_found(context, copy) ⇒ Object
- .section_hierarchy_layer_skip(context, section, super_section) ⇒ Object
- .section_not_found(context, copy) ⇒ Object
- .two_or_more_templates_found(context, copy, first_template, second_template) ⇒ Object
- .unterminated_escaped_key(context, instruction, selection_column) ⇒ Object
- .unterminated_multiline_field(context, field) ⇒ Object
Class Method Details
.cyclic_dependency(context, instruction, instruction_chain) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/enolib/errors/parsing.rb', line 8 def self.cyclic_dependency(context, instruction, instruction_chain) first_occurrence = instruction_chain.find_index(instruction) feedback_chain = instruction_chain[first_occurrence..-1] if feedback_chain.last.has_key?(:template) copy_instruction = feedback_chain.last elsif feedback_chain.first.has_key?(:template) # TODO: Here and elsewhere, do we even need to check this? One has to be it, right? copy_instruction = feedback_chain.first end reporter = context.reporter.new(context) reporter.report_line(copy_instruction) feedback_chain.each do |element| reporter.indicate_line(element) if element != copy_instruction end ParseError.new( context..cyclic_dependency(copy_instruction[:line] + Enolib::HUMAN_INDEXING, copy_instruction[:template]), reporter.snippet, Selections.select_template(copy_instruction) ) end |
.invalid_line(context, instruction) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/enolib/errors/parsing.rb', line 33 def self.invalid_line(context, instruction) line = context.input[instruction[:ranges][:line][RANGE_BEGIN]..instruction[:ranges][:line][RANGE_END]] match = UNTERMINATED_ESCAPED_KEY.match(line) return unterminated_escaped_key(context, instruction, match.end(1)) if match ParseError.new( context..invalid_line(instruction[:line] + Enolib::HUMAN_INDEXING), context.reporter.new(context).report_line(instruction).snippet, Selections.select_line(instruction) ) end |
.missing_element_for_continuation(context, continuation) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/enolib/errors/parsing.rb', line 46 def self.missing_element_for_continuation(context, continuation) ParseError.new( context..missing_element_for_continuation(continuation[:line] + Enolib::HUMAN_INDEXING), context.reporter.new(context).report_line(continuation).snippet, Selections.select_line(continuation) ) end |
.missing_fieldset_for_fieldset_entry(context, entry) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/enolib/errors/parsing.rb', line 54 def self.missing_fieldset_for_fieldset_entry(context, entry) ParseError.new( context..missing_fieldset_for_fieldset_entry(entry[:line] + Enolib::HUMAN_INDEXING), context.reporter.new(context).report_line(entry).snippet, Selections.select_line(entry) ) end |
.missing_list_for_list_item(context, item) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/enolib/errors/parsing.rb', line 62 def self.missing_list_for_list_item(context, item) ParseError.new( context..missing_list_for_list_item(item[:line] + Enolib::HUMAN_INDEXING), context.reporter.new(context).report_line(item).snippet, Selections.select_line(item) ) end |
.non_section_element_not_found(context, copy) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/enolib/errors/parsing.rb', line 70 def self.non_section_element_not_found(context, copy) ParseError.new( context..non_section_element_not_found(copy[:line] + Enolib::HUMAN_INDEXING, copy[:template]), context.reporter.new(context).report_line(copy).snippet, Selections.select_line(copy) ) end |
.section_hierarchy_layer_skip(context, section, super_section) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/enolib/errors/parsing.rb', line 78 def self.section_hierarchy_layer_skip(context, section, super_section) reporter = context.reporter.new(context).report_line(section) reporter.indicate_line(super_section) if super_section[:type] != :document ParseError.new( context..section_hierarchy_layer_skip(section[:line] + Enolib::HUMAN_INDEXING), reporter.snippet, Selections.select_line(section) ) end |
.section_not_found(context, copy) ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/enolib/errors/parsing.rb', line 90 def self.section_not_found(context, copy) ParseError.new( context..section_not_found(copy[:line] + Enolib::HUMAN_INDEXING, copy[:template]), context.reporter.new(context).report_line(copy).snippet, Selections.select_line(copy) ) end |
.two_or_more_templates_found(context, copy, first_template, second_template) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/enolib/errors/parsing.rb', line 113 def self.two_or_more_templates_found(context, copy, first_template, second_template) ParseError.new( context..two_or_more_templates_found(copy[:template]), context.reporter.new(context).report_line(copy).question_line(first_template).question_line(second_template).snippet, Selections.select_line(copy) ) end |
.unterminated_escaped_key(context, instruction, selection_column) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/enolib/errors/parsing.rb', line 98 def self.unterminated_escaped_key(context, instruction, selection_column) ParseError.new( context..unterminated_escaped_key(instruction[:line] + Enolib::HUMAN_INDEXING), context.reporter.new(context).report_line(instruction).snippet, { from: { column: selection_column, index: instruction[:ranges][:line][RANGE_BEGIN] + selection_column, line: instruction[:line] }, to: Selections.cursor(instruction, :line, RANGE_END) } ) end |
.unterminated_multiline_field(context, field) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/enolib/errors/parsing.rb', line 121 def self.unterminated_multiline_field(context, field) reporter = context.reporter.new(context).report_element(field) context..each do |instruction| reporter.indicate_line(instruction) if instruction[:line] > field[:line] end ParseError.new( context..unterminated_multiline_field(field[:key], field[:line] + Enolib::HUMAN_INDEXING), reporter.snippet, Selections.select_line(field) ) end |