Exception: NOSJ::ParserError
- 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
-
#byte_offset ⇒ Integer?
readonly
Byte offset of the failure in the source.
-
#column ⇒ Integer?
readonly
1-based character (not byte) column within #line.
-
#line ⇒ Integer?
readonly
1-based line of the failure.
-
#snippet ⇒ String?
readonly
The offending line (windowed when long) with a caret line underneath.
Instance Method Summary collapse
-
#detailed_message(highlight: false, **opts) ⇒ String
The default message plus #snippet: Ruby prints
detailed_messagewhen an exception reaches the top level, so an unrescued parse error shows where the document broke.
Instance Attribute Details
#byte_offset ⇒ Integer? (readonly)
Returns byte offset of the failure in the source.
46 47 48 |
# File 'lib/nosj.rb', line 46 def byte_offset @byte_offset end |
#column ⇒ Integer? (readonly)
Returns 1-based character (not byte) column within #line.
51 52 53 |
# File 'lib/nosj.rb', line 51 def column @column end |
#line ⇒ Integer? (readonly)
Returns 1-based line of the failure.
48 49 50 |
# File 'lib/nosj.rb', line 48 def line @line end |
#snippet ⇒ String? (readonly)
Returns 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.
59 60 61 62 |
# File 'lib/nosj.rb', line 59 def (highlight: false, **opts) base = super snippet ? "#{base}\n#{snippet}" : base end |