1 /* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2 * Use of this file is governed by the BSD 3-clause license that
3 * can be found in the LICENSE.txt file in the project root.
8 #include "BaseErrorListener.h"
13 /// This implementation of <seealso cref="ANTLRErrorListener"/> can be used to identify
14 /// certain potential correctness and performance problems in grammars. "Reports"
15 /// are made by calling <seealso cref="Parser#notifyErrorListeners"/> with the appropriate
19 /// <li><b>Ambiguities</b>: These are cases where more than one path through the
20 /// grammar can match the input.</li>
21 /// <li><b>Weak context sensitivity</b>: These are cases where full-context
22 /// prediction resolved an SLL conflict to a unique alternative which equaled the
23 /// minimum alternative of the SLL conflict.</li>
24 /// <li><b>Strong (forced) context sensitivity</b>: These are cases where the
25 /// full-context prediction resolved an SLL conflict to a unique alternative,
26 /// <em>and</em> the minimum alternative of the SLL conflict was found to not be
27 /// a truly viable alternative. Two-stage parsing cannot be used for inputs where
28 /// this situation occurs.</li>
31 /// @author Sam Harwell
33 class ANTLR4CPP_PUBLIC DiagnosticErrorListener : public BaseErrorListener {
35 /// When {@code true}, only exactly known ambiguities are reported.
41 /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/> which only
42 /// reports exact ambiguities.
45 DiagnosticErrorListener();
48 /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/>, specifying
49 /// whether all ambiguities or only exact ambiguities are reported.
51 /// <param name="exactOnly"> {@code true} to report only exact ambiguities, otherwise
52 /// {@code false} to report all ambiguities. </param>
53 DiagnosticErrorListener(bool exactOnly);
55 virtual void reportAmbiguity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex, bool exact,
56 const antlrcpp::BitSet &ambigAlts, atn::ATNConfigSet *configs) override;
58 virtual void reportAttemptingFullContext(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
59 const antlrcpp::BitSet &conflictingAlts, atn::ATNConfigSet *configs) override;
61 virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
62 size_t prediction, atn::ATNConfigSet *configs) override;
65 virtual std::string getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa);
68 /// Computes the set of conflicting or ambiguous alternatives from a
69 /// configuration set, if that information was not already provided by the
72 /// <param name="reportedAlts"> The set of conflicting or ambiguous alternatives, as
73 /// reported by the parser. </param>
74 /// <param name="configs"> The conflicting or ambiguous configuration set. </param>
75 /// <returns> Returns {@code reportedAlts} if it is not {@code null}, otherwise
76 /// returns the set of alternatives represented in {@code configs}. </returns>
77 virtual antlrcpp::BitSet getConflictingAlts(const antlrcpp::BitSet &reportedAlts, atn::ATNConfigSet *configs);