Class: Ibex::Frontend::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/frontend/diagnostic.rb

Overview

An immutable machine-readable frontend error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code:, phase:, message:, location:, span: nil, expected: [], received: nil, rendered: nil) ⇒ Diagnostic

Returns a new instance of Diagnostic.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ibex/frontend/diagnostic.rb', line 17

def initialize(code:, phase:, message:, location:, span: nil, expected: [], received: nil, rendered: nil)
  @code = code.dup.freeze
  @phase = phase
  @message = message.dup.freeze
  @location = Location.new(
    file: location.file.dup.freeze, line: location.line, column: location.column
  ).freeze
  @span = span
  @expected = expected.map { |value| value.dup.freeze }.freeze
  @received = received&.dup&.freeze
  @rendered = (rendered || "#{location}: #{message}").dup.freeze
  freeze
end

Instance Attribute Details

#codeObject (readonly)

: String



7
8
9
# File 'lib/ibex/frontend/diagnostic.rb', line 7

def code
  @code
end

#expectedObject (readonly)

: Array



12
13
14
# File 'lib/ibex/frontend/diagnostic.rb', line 12

def expected
  @expected
end

#locationObject (readonly)

: Location



10
11
12
# File 'lib/ibex/frontend/diagnostic.rb', line 10

def location
  @location
end

#messageObject (readonly)

: String



9
10
11
# File 'lib/ibex/frontend/diagnostic.rb', line 9

def message
  @message
end

#phaseObject (readonly)

: Symbol



8
9
10
# File 'lib/ibex/frontend/diagnostic.rb', line 8

def phase
  @phase
end

#receivedObject (readonly)

: String?



13
14
15
# File 'lib/ibex/frontend/diagnostic.rb', line 13

def received
  @received
end

#spanObject (readonly)

: SourceSpan?



11
12
13
# File 'lib/ibex/frontend/diagnostic.rb', line 11

def span
  @span
end

Instance Method Details

#severityObject



32
33
34
# File 'lib/ibex/frontend/diagnostic.rb', line 32

def severity
  "error"
end

#to_hObject



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ibex/frontend/diagnostic.rb', line 42

def to_h
  {
    code: code,
    severity: severity,
    phase: phase.to_s,
    message: message,
    location: location.to_h,
    span: span&.to_h,
    expected: expected,
    received: received
  }
end

#to_sObject



37
38
39
# File 'lib/ibex/frontend/diagnostic.rb', line 37

def to_s
  @rendered
end