Exception: FilterLexer::ParseException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/filter_lexer/exceptions.rb

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ ParseException

Returns a new instance of ParseException.



3
4
5
6
# File 'lib/filter_lexer/exceptions.rb', line 3

def initialize(parser)
	@index = parser.failure_index
	@input = parser.input
end

Instance Method Details

#contextObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/filter_lexer/exceptions.rb', line 12

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

#messageObject



8
9
10
# File 'lib/filter_lexer/exceptions.rb', line 8

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