class Trenni::Location

def initialize(input, offset)

def initialize(input, offset)
	raise ArgumentError.new("Offset #{index} is past end of input #{input.bytesize}") if offset > input.bytesize
	
	@offset = offset
	@line_index = 0
	line_offset = next_line_offset = 0
	
	input.each_line do |line|
		line_offset = next_line_offset
		next_line_offset += line.bytesize
		
		# Is our input offset within this line?
		if next_line_offset >= offset
			@line_text = line.chomp
			@line_range = line_offset...next_line_offset
			break
		else
			@line_index += 1
		end
	end
end

def line_number

The line index, but base-1.
def line_number
	@line_index + 1
end

def line_offset

The number of bytes from the start of the line to the given offset in the input.
def line_offset
	@offset - @line_range.min
end

def to_i

def to_i
	@offset
end

def to_s

def to_s
	"[#{self.line_number}:#{self.line_offset}]"
end