Exception: XRB::ParseError

Inherits:
Error
  • Object
show all
Defined in:
lib/xrb/error.rb

Overview

Raised when an XRB parser encounters invalid input.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, buffer, offset) ⇒ ParseError

Initialize a parse error at a specific byte offset within a buffer.



19
20
21
22
23
24
# File 'lib/xrb/error.rb', line 19

def initialize(message, buffer, offset)
	super(message)
	
	@buffer = buffer
	@offset = offset
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



32
33
34
# File 'lib/xrb/error.rb', line 32

def buffer
  @buffer
end

#pathObject (readonly)

Returns the value of attribute path.



33
34
35
# File 'lib/xrb/error.rb', line 33

def path
  @path
end

Instance Method Details

#locationObject

Compute the location of the parse error within the input buffer.



28
29
30
# File 'lib/xrb/error.rb', line 28

def location
	@location ||= Location.new(@buffer.read, @offset)
end

#to_sObject

Format the error with its path, location, message, and source line.



37
38
39
# File 'lib/xrb/error.rb', line 37

def to_s
	"#{buffer.path}#{location}: #{super}\n#{location.line_text}"
end