Exception: Curlybars::Error::Lex

Inherits:
Base
  • Object
show all
Defined in:
lib/curlybars/error/lex.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #metadata, #position

Instance Method Summary collapse

Constructor Details

#initialize(source, file_name, exception) ⇒ Lex

Returns a new instance of Lex.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/curlybars/error/lex.rb', line 6

def initialize(source, file_name, exception)
  line_number = exception.line_number
  line_offset = exception.line_offset

  error_line = source.split("\n")[line_number - 1]
  before_error = error_line.first(line_offset).last(10)
  after_error = error_line[line_offset + 1..-1].first(10)
  error = error_line[line_offset]

  details = [before_error, error, after_error]
  message = ".. %s `%s` %s .. is not permitted symbol in this context" % details
  position = Curlybars::Position.new(file_name, line_number, line_offset)
  super('lex', message, position)
end