class Parser::Diagnostic::Engine


@return [Boolean]
When set to ‘true` warnings will be ignored.
@!attribute [rw] ignore_warnings
@return [Boolean]
{Parser::SyntaxError} being raised.
When set to `true` any error that is encountered will result in
@!attribute [rw] all_errors_are_fatal
@return [#call(Diagnostic)]
@!attribute [rw] consumer
@api public
engine.process(diagnostic) # => “unexpected token abc”
:warning, :unexpected_token, { :token => ’abc’ }, buffer, 1..2)
diagnostic = Parser::Diagnostic.new(
engine = Parser::Diagnostic::Engine.new(consumer)
end
puts diagnostic.message
consumer = lambda do |diagnostic|
buffer = Parser::Source::Buffer.new(__FILE__, source: ‘foobar’)
@example
diagnostics by delegating them to registered consumers.
{Parser::Diagnostic::Engine} provides a basic API for dealing with
#

def ignore?(diagnostic)

Returns:
  • (Boolean) -

Parameters:
  • diagnostic (Parser::Diagnostic) --
def ignore?(diagnostic)
  @ignore_warnings &&
        diagnostic.level == :warning
end

def initialize(consumer=nil)

Parameters:
  • consumer (#call(Diagnostic)) --
def initialize(consumer=nil)
  @consumer             = consumer
  @all_errors_are_fatal = false
  @ignore_warnings      = false
end

def process(diagnostic)

Other tags:
    See: raise? -
    See: ignore? -

Returns:
  • (Parser::Diagnostic::Engine) -

Parameters:
  • diagnostic (Parser::Diagnostic) --
def process(diagnostic)
  if ignore?(diagnostic)
    # do nothing
  elsif @consumer
    @consumer.call(diagnostic)
  end
  if raise?(diagnostic)
    raise Parser::SyntaxError, diagnostic
  end
  self
end

def raise?(diagnostic)

Returns:
  • (Boolean) -

Parameters:
  • diagnostic (Parser::Diagnostic) --
def raise?(diagnostic)
  (@all_errors_are_fatal &&
      diagnostic.level == :error) ||
    diagnostic.level == :fatal
end