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] diagnostic level
@see LEVELS
@!attribute [r] level
@api public
#

def initialize(level, message, location, highlights=[])

Parameters:
  • highlights (Array) --
  • location (Parser::Source::Range) --
  • message (String) --
  • level (Symbol) --
def initialize(level, message, location, highlights=[])
  unless LEVELS.include?(level)
    raise ArgumentError,
          "Diagnostic#level must be one of #{LEVELS.join(', ')}; " \
          "#{level.inspect} provided."
  end
  @level       = level
  @message     = message.to_s.dup.freeze
  @location    = location
  @highlights  = highlights.dup.freeze
  freeze
end

def render

Returns:
  • (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