2003-06-09 21:31:01 -04:00
|
|
|
module REXML
|
2003-10-10 08:54:46 -04:00
|
|
|
class ParseException < RuntimeError
|
2003-06-09 21:31:01 -04:00
|
|
|
attr_accessor :source, :parser, :continued_exception
|
|
|
|
|
|
|
|
def initialize( message, source=nil, parser=nil, exception=nil )
|
|
|
|
super(message)
|
|
|
|
@source = source
|
|
|
|
@parser = parser
|
|
|
|
@continued_exception = exception
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
# Quote the original exception, if there was one
|
|
|
|
if @continued_exception
|
2003-10-10 08:54:46 -04:00
|
|
|
err = @continued_exception.inspect
|
2003-06-09 21:31:01 -04:00
|
|
|
err << "\n"
|
2003-10-10 08:54:46 -04:00
|
|
|
err << @continued_exception.backtrace.join("\n")
|
2003-06-09 21:31:01 -04:00
|
|
|
err << "\n...\n"
|
|
|
|
else
|
|
|
|
err = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get the stack trace and error message
|
|
|
|
err << super
|
|
|
|
|
|
|
|
# Add contextual information
|
2003-10-10 08:54:46 -04:00
|
|
|
if @source
|
|
|
|
err << "\nLine: #{line}\n"
|
|
|
|
err << "Position: #{position}\n"
|
|
|
|
err << "Last 80 unconsumed characters:\n"
|
|
|
|
err << @source.buffer[0..80].gsub(/\n/, ' ')
|
|
|
|
end
|
|
|
|
|
2003-06-09 21:31:01 -04:00
|
|
|
err
|
|
|
|
end
|
|
|
|
|
|
|
|
def position
|
2003-10-10 08:54:46 -04:00
|
|
|
@source.current_line[0] if @source and @source.current_line
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def line
|
2003-10-10 08:54:46 -04:00
|
|
|
@source.current_line[2] if @source and @source.current_line
|
2003-06-09 21:31:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def context
|
|
|
|
@source.current_line
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|