Exception: MilkTea::LexError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/milk_tea/core/lexer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, line:, column:, path: nil) ⇒ LexError

Returns a new instance of LexError.



17
18
19
20
21
22
23
24
# File 'lib/milk_tea/core/lexer.rb', line 17

def initialize(message, line:, column:, path: nil)
  @line = line
  @column = column
  @path = path

  location = [path, "#{line}:#{column}"].compact.join(":")
  super(location.empty? ? message : "#{message} at #{location}")
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



15
16
17
# File 'lib/milk_tea/core/lexer.rb', line 15

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



15
16
17
# File 'lib/milk_tea/core/lexer.rb', line 15

def line
  @line
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/milk_tea/core/lexer.rb', line 15

def path
  @path
end

Instance Method Details

#codeObject



26
27
28
# File 'lib/milk_tea/core/lexer.rb', line 26

def code
  "lex/error"
end

#to_diagnostic(path: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/milk_tea/core/lexer.rb', line 30

def to_diagnostic(path: nil)
  Diagnostic.new(
    path: @path || path,
    line: @line,
    column: @column,
    length: nil,
    code: code,
    message: message,
    severity: :error,
  )
end