Class: Ibex::Frontend::Diagnostic
- Inherits:
-
Object
- Object
- Ibex::Frontend::Diagnostic
- Defined in:
- lib/ibex/frontend/diagnostic.rb,
sig/ibex/frontend/diagnostic.rbs
Overview
An immutable machine-readable frontend error.
Instance Attribute Summary collapse
- #code ⇒ String readonly
- #expected ⇒ Array[String] readonly
- #location ⇒ Location readonly
- #message ⇒ String readonly
- #phase ⇒ Symbol readonly
- #received ⇒ String? readonly
- #span ⇒ SourceSpan? readonly
Instance Method Summary collapse
-
#initialize(code:, phase:, message:, location:, span: nil, expected: [], received: nil, rendered: nil) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #severity ⇒ String
- #to_h ⇒ Hash[Symbol, untyped]
- #to_s ⇒ String
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 = .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}: #{}").dup.freeze freeze end |
Instance Attribute Details
#code ⇒ String (readonly)
7 8 9 |
# File 'lib/ibex/frontend/diagnostic.rb', line 7 def code @code end |
#expected ⇒ Array[String] (readonly)
12 13 14 |
# File 'lib/ibex/frontend/diagnostic.rb', line 12 def expected @expected end |
#location ⇒ Location (readonly)
10 11 12 |
# File 'lib/ibex/frontend/diagnostic.rb', line 10 def location @location end |
#message ⇒ String (readonly)
9 10 11 |
# File 'lib/ibex/frontend/diagnostic.rb', line 9 def @message end |
#phase ⇒ Symbol (readonly)
8 9 10 |
# File 'lib/ibex/frontend/diagnostic.rb', line 8 def phase @phase end |
#received ⇒ String? (readonly)
13 14 15 |
# File 'lib/ibex/frontend/diagnostic.rb', line 13 def received @received end |
#span ⇒ SourceSpan? (readonly)
11 12 13 |
# File 'lib/ibex/frontend/diagnostic.rb', line 11 def span @span end |
Instance Method Details
#severity ⇒ String
32 33 34 |
# File 'lib/ibex/frontend/diagnostic.rb', line 32 def severity "error" end |
#to_h ⇒ Hash[Symbol, untyped]
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: , location: location.to_h, span: span&.to_h, expected: expected, received: received } end |
#to_s ⇒ String
37 38 39 |
# File 'lib/ibex/frontend/diagnostic.rb', line 37 def to_s @rendered end |