class Parser::Diagnostic
@return [Array<Parser::Source::Range>]
Supplementary error-related source ranges.
@!attribute [r] highlights
@return [Parser::Source::Range]
Main error-related source range.
@!attribute [r] location
@return [String] error message
@!attribute [r] message
@return [Symbol] extended arguments that describe the error
@see Parser::MESSAGES
@!attribute [r] arguments
@return [Symbol] reason for error
@see Parser::MESSAGES
@!attribute [r] reason
@return [Symbol] diagnostic level
@see LEVELS
@!attribute [r] level
@api public
#
def initialize(level, reason, arguments, location, highlights=[])
-
highlights
(Array
) -- -
location
(Parser::Source::Range
) -- -
arguments
(Hash
) -- -
reason
(Symbol
) -- -
level
(Symbol
) --
def initialize(level, reason, arguments, location, highlights=[]) unless LEVELS.include?(level) raise ArgumentError, "Diagnostic#level must be one of #{LEVELS.join(', ')}; " \ "#{level.inspect} provided." end raise 'Expected a location' unless location @level = level @reason = reason @arguments = (arguments || {}).dup.freeze @location = location @highlights = highlights.dup.freeze freeze end
def message
-
(String)
- the rendered message.
def message MESSAGES[@reason] % @arguments end
def render
-
(Array
-)
def render source_line = @location.source_line highlight_line = ' ' * source_line.length @highlights.each do |hilight| range = hilight.column_range highlight_line[range] = '~' * hilight.size end range = @location.column_range highlight_line[range] = '^' * @location.size [ "#{@location.to_s}: #{@level}: #{message}", source_line, highlight_line, ] end