Exception: Puffy::PuffyError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/puffy.rb

Direct Known Subclasses

ParseError, SyntaxError

Instance Method Summary collapse

Constructor Details

#initialize(message, token) ⇒ PuffyError

Returns a new instance of PuffyError.



19
20
21
22
# File 'lib/puffy.rb', line 19

def initialize(message, token)
  super(message)
  @token = token
end

Instance Method Details

#extraObject



44
45
46
# File 'lib/puffy.rb', line 44

def extra
  '~' * (length - 1)
end

#filenameObject



24
25
26
# File 'lib/puffy.rb', line 24

def filename
  @token[:filename]
end

#lengthObject



40
41
42
# File 'lib/puffy.rb', line 40

def length
  @token.fetch(:length, 1)
end

#lineObject



32
33
34
# File 'lib/puffy.rb', line 32

def line
  @token[:line]
end

#linenoObject



28
29
30
# File 'lib/puffy.rb', line 28

def lineno
  @token[:lineno]
end

#positionObject



36
37
38
# File 'lib/puffy.rb', line 36

def position
  @token[:position]
end

#to_sObject



48
49
50
51
52
53
54
# File 'lib/puffy.rb', line 48

def to_s
  <<~MESSAGE
    #{filename}:#{lineno}:#{position + 1}: #{super}
    #{line}
    #{' ' * position}^#{extra}
  MESSAGE
end