Exception: Bade::Parser::SyntaxError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/bade/parser.rb

Overview

Error representing syntax error in specific file, line and column

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, file, line, lineno, column) ⇒ SyntaxError

Returns a new instance of SyntaxError.



19
20
21
22
23
24
25
26
27
# File 'lib/bade/parser.rb', line 19

def initialize(error, file, line, lineno, column)
  super(error)

  @error = error
  @file = file || '(__TEMPLATE__)'
  @line = line.to_s
  @lineno = lineno
  @column = column
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



17
18
19
# File 'lib/bade/parser.rb', line 17

def column
  @column
end

#errorObject (readonly)

Returns the value of attribute error.



17
18
19
# File 'lib/bade/parser.rb', line 17

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



17
18
19
# File 'lib/bade/parser.rb', line 17

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



17
18
19
# File 'lib/bade/parser.rb', line 17

def line
  @line
end

#linenoObject (readonly)

Returns the value of attribute lineno.



17
18
19
# File 'lib/bade/parser.rb', line 17

def lineno
  @lineno
end

Instance Method Details

#to_sObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/bade/parser.rb', line 29

def to_s
  line = @line.lstrip
  column = @column + line.size - @line.size
  <<~MSG
    #{error}
      #{file}, Line #{lineno}, Column #{@column}
      #{line}
      #{' ' * column}^
  MSG
end