Class: Carbon::Compiler::Metanostic
- Inherits:
-
Object
- Object
- Carbon::Compiler::Metanostic
- Includes:
- Comparable
- Defined in:
- lib/carbon/compiler/metanostic.rb,
lib/carbon/compiler/metanostic/list.rb,
lib/carbon/compiler/metanostic/mode.rb,
lib/carbon/compiler/metanostic/state.rb,
lib/carbon/compiler/metanostic/defaults.rb,
lib/carbon/compiler/metanostic/diagnostic.rb
Overview
A “Metanostic.” A “metanostic” has information about what a diagnostic could be about. For example, a ‘Diagnostic/Unknown` diagnostic has metanostic information; the name itself, the default mode, and the allowed modes are a part of that metanostic information. Diagnostics are generated from both metanostic information and environmental information.
Defined Under Namespace
Modules: Defaults, Mode Classes: Diagnostic, List, State
Instance Attribute Summary collapse
-
#allowed ⇒ ::Integer
readonly
The allowed modes of a metanostic or diagnostic.
-
#default ⇒ ::Integer
The default mode of derived diagnostics.
-
#message ⇒ ::String
readonly
The default message of derived diagnostics, if the diagnostic does not provide one.
-
#name ⇒ ::String
readonly
The name of the metanostic.
Instance Method Summary collapse
-
#<=>(other) ⇒ ::Numeric
Compares this with another metanostic.
-
#can_be?(mode) ⇒ Boolean
Checks to see if the metanostic or any derived diagnostics can have the given mode.
-
#hash ⇒ ::Numeric
Returns a numeric representation of this class for use of hashing.
-
#initialize(data) ⇒ Metanostic
constructor
Initialize the diagnostic with the given data.
-
#inspect ⇒ ::String
Pretty inspect.
-
#to_a ⇒ (::Class, ::String, ::Integer, ::Integer, ::String)
Returns an array representation of this class.
Constructor Details
#initialize(data) ⇒ Metanostic
Initialize the diagnostic with the given data.
59 60 61 62 63 64 |
# File 'lib/carbon/compiler/metanostic.rb', line 59 def initialize(data) @name = data.fetch(:name) { data.fetch("name") } @allowed = data.fetch(:allowed) { data.fetch("allowed") } self.default = data.fetch(:default) { data.fetch("default") } @message = data.fetch(:message) { data.fetch("message") } end |
Instance Attribute Details
#allowed ⇒ ::Integer (readonly)
The allowed modes of a metanostic or diagnostic. This limits how a diagnostic can be categorized. This is a bitfield of modes. If a metanostic can be any mode, this is ‘Metanostic::Mode::ALL`; otherwise, it is a union of all of the allowed modes of a diagnostic.
34 35 36 |
# File 'lib/carbon/compiler/metanostic.rb', line 34 def allowed @allowed end |
#default ⇒ ::Integer
The default mode of derived diagnostics. This is and must be an allowed diagnostic.
41 42 43 |
# File 'lib/carbon/compiler/metanostic.rb', line 41 def default @default end |
#message ⇒ ::String (readonly)
The default message of derived diagnostics, if the diagnostic does not provide one. This is used to provide a generic message.
46 47 48 |
# File 'lib/carbon/compiler/metanostic.rb', line 46 def @message end |
#name ⇒ ::String (readonly)
The name of the metanostic. This is used as a unique identifier for the metanostic. This is a string, and is normally represented as a path of CamelCase names. For example, a name might be ‘Diagnostic/Unknown`.
26 27 28 |
# File 'lib/carbon/compiler/metanostic.rb', line 26 def name @name end |
Instance Method Details
#<=>(other) ⇒ ::Numeric
Compares this with another metanostic. This should only be used for equality; it makes no sense otherwise.
71 72 73 74 |
# File 'lib/carbon/compiler/metanostic.rb', line 71 def <=>(other) fail ArgumentError, "Expected Metanostic" unless other.is_a?(Metanostic) to_a <=> other.to_a end |
#can_be?(mode) ⇒ Boolean
Checks to see if the metanostic or any derived diagnostics can have the given mode.
118 119 120 |
# File 'lib/carbon/compiler/metanostic.rb', line 118 def can_be?(mode) Mode.singular?(mode) && Mode.is?(allowed, mode) end |
#hash ⇒ ::Numeric
Returns a numeric representation of this class for use of hashing.
79 80 81 |
# File 'lib/carbon/compiler/metanostic.rb', line 79 def hash to_a.hash end |
#inspect ⇒ ::String
Pretty inspect.
93 94 95 96 |
# File 'lib/carbon/compiler/metanostic.rb', line 93 def inspect "#<#{self.class} #{@name}(#{Mode.to_s(@default)}) " \ "[#{Mode.to_s(@allowed)}]>" end |
#to_a ⇒ (::Class, ::String, ::Integer, ::Integer, ::String)
Returns an array representation of this class. This is frozen.
86 87 88 |
# File 'lib/carbon/compiler/metanostic.rb', line 86 def to_a [self.class, @name, @allowed, @default, @message].freeze end |