Class: Antlr4::Runtime::DiagnosticErrorListener

Inherits:
BaseErrorListener show all
Defined in:
lib/antlr4/runtime/diagnostic_error_listener.rb

Instance Method Summary collapse

Methods inherited from BaseErrorListener

#syntax_error

Methods inherited from ANTLRErrorListener

#syntax_error

Constructor Details

#initialize(exact_only = true) ⇒ DiagnosticErrorListener

Returns a new instance of DiagnosticErrorListener


3
4
5
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 3

def initialize(exact_only = true)
  @exact_only = exact_only
end

Instance Method Details

#conflicting_alts(reported_alts, configs) ⇒ Object


47
48
49
50
51
52
53
54
55
56
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 47

def conflicting_alts(reported_alts, configs)
  return reported_alts unless reported_alts.nil?

  result = BitSet.new
  configs.each do |config|
    result.set(config.alt)
  end

  result
end

#decision_description(recognizer, dfa) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 34

def decision_description(recognizer, dfa)
  decision = dfa.decision
  rule_index = dfa.atn_start_state.rule_index

  rule_names = recognizer.rule_names
  return decision.to_s if rule_index < 0 || rule_index >= rule_names.length

  rule_name = rule_names[rule_index]
  return decision.to_s if rule_name.nil? || rule_name.empty?

  String.format('%d (%s)', decision, rule_name)
end

#report_ambiguity(recognizer, dfa, start_index, stop_index, exact, ambig_alts, configs) ⇒ Object


7
8
9
10
11
12
13
14
15
16
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 7

def report_ambiguity(recognizer, dfa, start_index, stop_index, exact, ambig_alts, configs)
  return if @exact_only && !exact

  format = "reportAmbiguity d=%s: ambig_alts=%s, input='%s'"
  decision = decision_description(recognizer, dfa)
  conflicting_alts = conflicting_alts(ambig_alts, configs)
  text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
  message = String.format(format, decision, conflicting_alts, text)
  recognizer.notify_error_listeners(message)
end

#report_attempting_full_context(recognizer, dfa, start_index, stop_index, _conflicting_alts, _configs) ⇒ Object


18
19
20
21
22
23
24
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 18

def report_attempting_full_context(recognizer, dfa, start_index, stop_index, _conflicting_alts, _configs)
  format = "reportAttemptingFullContext d=%s, input='%s'"
  decision = decision_description(recognizer, dfa)
  text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
  message = String.format(format, decision, text)
  recognizer.notify_error_listeners(message)
end

#report_context_sensitivity(recognizer, dfa, start_index, stop_index, _prediction, _configs) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/antlr4/runtime/diagnostic_error_listener.rb', line 26

def report_context_sensitivity(recognizer, dfa, start_index, stop_index, _prediction, _configs)
  format = "reportContextSensitivity d=%s, input='%s'"
  decision = decision_description(recognizer, dfa)
  text = recognizer.getTokenStream.text(Interval.of(start_index, stop_index))
  message = String.format(format, decision, text)
  recognizer.notify_error_listeners(message)
end