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