Exception: NOSJ::ParserError

Inherits:
Error
  • Object
show all
Defined in:
lib/nosj.rb,
sig/nosj.rbs

Overview

Parse failures. Position accessors are nil for failures without one (encoding refusals); positions are byte-absolute within the document, lines and (character) columns 1-based.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#byte_offsetInteger? (readonly)

Returns byte offset of the failure in the source.

Returns:

  • (Integer, nil)

    byte offset of the failure in the source



46
47
48
# File 'lib/nosj.rb', line 46

def byte_offset
  @byte_offset
end

#columnInteger? (readonly)

Returns 1-based character (not byte) column within #line.

Returns:

  • (Integer, nil)

    1-based character (not byte) column within #line



51
52
53
# File 'lib/nosj.rb', line 51

def column
  @column
end

#lineInteger? (readonly)

Returns 1-based line of the failure.

Returns:

  • (Integer, nil)

    1-based line of the failure



48
49
50
# File 'lib/nosj.rb', line 48

def line
  @line
end

#snippetString? (readonly)

Returns the offending line (windowed when long) with a caret line underneath.

Returns:

  • (String, nil)

    the offending line (windowed when long) with a caret line underneath



54
55
56
# File 'lib/nosj.rb', line 54

def snippet
  @snippet
end

Instance Method Details

#detailed_message(highlight: false, **opts) ⇒ String

The default message plus #snippet: Ruby prints detailed_message when an exception reaches the top level, so an unrescued parse error shows where the document broke.

Parameters:

  • highlight: (Boolean) (defaults to: false)
  • (Object)

Returns:

  • (String)


59
60
61
62
# File 'lib/nosj.rb', line 59

def detailed_message(highlight: false, **opts)
  base = super
  snippet ? "#{base}\n#{snippet}" : base
end