Class: Parser::Diagnostic::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/diagnostic/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer = nil) ⇒ Engine

Returns a new instance of Engine.



9
10
11
12
13
14
# File 'lib/parser/diagnostic/engine.rb', line 9

def initialize(consumer=nil)
  @consumer             = consumer

  @all_errors_are_fatal = false
  @ignore_warnings      = false
end

Instance Attribute Details

#all_errors_are_fatalObject

Returns the value of attribute all_errors_are_fatal.



6
7
8
# File 'lib/parser/diagnostic/engine.rb', line 6

def all_errors_are_fatal
  @all_errors_are_fatal
end

#consumerObject

Returns the value of attribute consumer.



4
5
6
# File 'lib/parser/diagnostic/engine.rb', line 4

def consumer
  @consumer
end

#ignore_warningsObject

Returns the value of attribute ignore_warnings.



7
8
9
# File 'lib/parser/diagnostic/engine.rb', line 7

def ignore_warnings
  @ignore_warnings
end

Instance Method Details

#ignore?(diagnostic) ⇒ Boolean (protected)

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/parser/diagnostic/engine.rb', line 32

def ignore?(diagnostic)
  @ignore_warnings &&
        diagnostic.level == :warning
end

#process(diagnostic) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/parser/diagnostic/engine.rb', line 16

def process(diagnostic)
  if ignore?(diagnostic)
    # do nothing
  elsif @consumer
    @consumer.call(diagnostic)
  end

  if raise?(diagnostic)
    raise Parser::SyntaxError, diagnostic.message
  end

  self
end

#raise?(diagnostic) ⇒ Boolean (protected)

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/parser/diagnostic/engine.rb', line 37

def raise?(diagnostic)
  (@all_errors_are_fatal &&
      diagnostic.level == :error) ||
    diagnostic.level == :fatal
end