class NestedText::Errors::ParseError

Attributes

colno[R]
lineno[R]
message_raw[R]

Public Class Methods

new(line, colno, message) click to toggle source
Calls superclass method
# File lib/nestedtext/errors_internal.rb, line 19
def initialize(line, colno, message)
  # Note, both line and column number are 0-indexed.
  # But for human display we make them 1-indexed.
  @lineno = line.lineno
  @colno = colno
  @message_raw = message
  super(pretty_message(line))
end

Private Instance Methods

colno_disp() click to toggle source
# File lib/nestedtext/errors_internal.rb, line 34
def colno_disp
  @colno + 1
end
lineno_digits() click to toggle source

Number of digits in the line number.

# File lib/nestedtext/errors_internal.rb, line 39
def lineno_digits
  lineno_disp.to_s.length
end
lineno_disp() click to toggle source
# File lib/nestedtext/errors_internal.rb, line 30
def lineno_disp
  @lineno + 1
end
pretty_last_lines(line) click to toggle source
# File lib/nestedtext/errors_internal.rb, line 57
def pretty_last_lines(line)
  pretty_line(line.prev) + pretty_line(line)
end
pretty_line(line) click to toggle source
# File lib/nestedtext/errors_internal.rb, line 47
def pretty_line(line)
  return '' if line.nil?

  lline_indent = ' ' * line.indentation
  prev_lineno_disp = line.lineno + 1

  # From one line to another, we can at most have 1 digits length difference.
  "\n\t#{prev_lineno_disp.to_s.rjust(lineno_digits)}│#{lline_indent}#{line.content}"
end
pretty_marker() click to toggle source
# File lib/nestedtext/errors_internal.rb, line 61
def pretty_marker
  marker_indent = colno_disp + lineno_digits # +1 for the "|"
  "\n\t#{' ' * marker_indent}^"
end
pretty_message(line) click to toggle source
# File lib/nestedtext/errors_internal.rb, line 66
def pretty_message(line)
  pretty_prefix + @message_raw + pretty_last_lines(line) + pretty_marker
end
pretty_prefix() click to toggle source
# File lib/nestedtext/errors_internal.rb, line 43
def pretty_prefix
  "\nParse ParseError (line #{lineno_disp}, column #{colno_disp}): "
end