Class: DiagnosticErrorListener
- Inherits:
-
ErrorListener
- Object
- ErrorListener
- DiagnosticErrorListener
- Defined in:
- lib/antlr4/error/DiagnosticErrorListener.rb
Overview
This implementation of ANTLRErrorListener can be used to identify certain potential correctness and performance problems in grammars. “Reports” are made by calling Parser#notifyErrorListeners with the appropriate message.
<ul> <li>Ambiguities: These are cases where more than one path through the grammar can match the input.</li> <li>Weak context sensitivity: These are cases where full-context prediction resolved an SLL conflict to a unique alternative which equaled the minimum alternative of the SLL conflict.</li> <li>Strong (forced) context sensitivity: These are cases where the full-context prediction resolved an SLL conflict to a unique alternative, and the minimum alternative of the SLL conflict was found to not be a truly viable alternative. Two-stage parsing cannot be used for inputs where this situation occurs.</li> </ul>
Instance Attribute Summary collapse
-
#exactOnly ⇒ Object
Returns the value of attribute exactOnly.
Instance Method Summary collapse
-
#getConflictingAlts(reportedAlts, configs) ⇒ Object
Computes the set of conflicting or ambiguous alternatives from a configuration set, if that information was not already provided by the parser.
- #getDecisionDescription(recognizer, dfa) ⇒ Object
-
#initialize(exactOnly = true) ⇒ DiagnosticErrorListener
constructor
A new instance of DiagnosticErrorListener.
- #reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) ⇒ Object
- #reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) ⇒ Object
- #reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) ⇒ Object
Methods inherited from ErrorListener
Constructor Details
#initialize(exactOnly = true) ⇒ DiagnosticErrorListener
Returns a new instance of DiagnosticErrorListener.
55 56 57 58 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 55 def initialize(exactOnly=true) # whether all ambiguities or only exact ambiguities are reported. @exactOnly = exactOnly end |
Instance Attribute Details
#exactOnly ⇒ Object
Returns the value of attribute exactOnly.
54 55 56 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 54 def exactOnly @exactOnly end |
Instance Method Details
#getConflictingAlts(reportedAlts, configs) ⇒ Object
Computes the set of conflicting or ambiguous alternatives from a configuration set, if that information was not already provided by the parser.
reported by the parser. returns the set of alternatives represented in configs.
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 125 def getConflictingAlts(reportedAlts, configs) if not reportedAlts.nil? then return reportedAlts end result = Set.new for config in configs result.add(config.alt) end return result end |
#getDecisionDescription(recognizer, dfa) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 97 def getDecisionDescription(recognizer, dfa) decision = dfa.decision ruleIndex = dfa.atnStartState.ruleIndex ruleNames = recognizer.ruleNames if ruleIndex < 0 or ruleIndex >= ruleNames.length return decision.to_s end ruleName = ruleNames[ruleIndex] if ruleName.nil? or ruleName.zero? then return decision.to_s end return "#{decision} (#{ruleName})" end |
#reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 60 def reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) return if self.exactOnly and not exact StringIO.open { |buf| buf.write("reportAmbiguity d=") buf.write(self.getDecisionDescription(recognizer, dfa)) buf.write(": ambigAlts=") buf.write(self.getConflictingAlts(ambigAlts, configs).to_s) buf.write(", input='") buf.write(recognizer.getTokenStream().getText(startIndex, stopIndex)) # getText buf.write("'") recognizer.notifyErrorListeners(buf.string()) } end |
#reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 75 def reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) StringIO.open {|buf| buf.write("reportAttemptingFullContext d=") buf.write(self.getDecisionDescription(recognizer, dfa)) buf.write(", input='") buf.write(recognizer.getTokenStream().getText(startIndex, stopIndex)) buf.write("'") recognizer.notifyErrorListeners(buf.string()) } end |
#reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/antlr4/error/DiagnosticErrorListener.rb', line 86 def reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) StringIO.open {|buf| buf.write("reportContextSensitivity d=") buf.write(self.getDecisionDescription(recognizer, dfa)) buf.write(", input='") buf.write(recognizer.getTokenStream().getText(startIndex, stopIndex)) buf.write("'") recognizer.notifyErrorListeners(buf.string()) } end |