Sha256: f4472d0cd6adaec018a549a99170f3913375c7464d87f382f696eadd100a2442

Contents?: true

Size: 534 Bytes

Versions: 2

Compression:

Stored size: 534 Bytes

Contents

module FilterLexer
	class ParseException < Exception
		def initialize(parser)
			@index = parser.failure_index
			@input = parser.input
		end

		def message
			return "Parse error at index #{@index}"
		end

		def context
			size = @input.size
			i1 = [0, @index - 40].max
			i2 = [size, @index + 40].min

			context = @input.slice(i1..i2)
			context = "...#{context}" if i1 > 0
			context = "#{context}..." if i2 < size

			relpos = @index - i1
			relpos += 1 if i1 > 0

			return context + "\r\n" + ' ' * relpos + '^'
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
filter_lexer-0.2.0 lib/filter_lexer/exceptions.rb
filter_lexer-0.1.1 lib/filter_lexer/exceptions.rb