Exception: NestedText::Errors::ParseInvalidIndentationError

Inherits:
ParseError show all
Defined in:
lib/nestedtext/errors_internal.rb

Instance Attribute Summary

Attributes inherited from ParseError

#colno, #lineno, #message_raw

Instance Method Summary collapse

Constructor Details

#initialize(line, ind_exp) ⇒ ParseInvalidIndentationError

Returns a new instance of ParseInvalidIndentationError.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/nestedtext/errors_internal.rb', line 114

def initialize(line, ind_exp)
  prev_line = line.prev
  if prev_line.nil? && ind_exp == 0
    message = "top-level content must start in column 1."
  elsif !prev_line.nil? &&
        prev_line.attribs.key?("value") &&
        prev_line.indentation < line.indentation &&
        i[dict_item list_item].member?(prev_line.tag)
    message = "invalid indentation."
  elsif !prev_line.nil? && line.indentation < prev_line.indentation
    # Can't use ind_exp here, because it's a difference if the previous line was further indented. See test_load_error_dict_10
    message = "invalid indentation, partial dedent."
  else
    message = "invalid indentation."
  end
  # Need to wrap like official tests. #wrap always add an extra \n we need to chop off.
  message_wrapped = message.wrap(70).chop
  super(line, ind_exp, message_wrapped)
end