]> gitweb.ps.run Git - toc/blob - antlr4-cpp-runtime-4.9.2-source/runtime/src/DiagnosticErrorListener.h
add antlr source code and ReadMe
[toc] / antlr4-cpp-runtime-4.9.2-source / runtime / src / DiagnosticErrorListener.h
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.
4  */
5
6 #pragma once
7
8 #include "BaseErrorListener.h"
9
10 namespace antlr4 {
11
12   /// <summary>
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
16   /// message.
17   ///
18   /// <ul>
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>
29   /// </ul>
30   ///
31   /// @author Sam Harwell
32   /// </summary>
33   class ANTLR4CPP_PUBLIC DiagnosticErrorListener : public BaseErrorListener {
34     /// <summary>
35     /// When {@code true}, only exactly known ambiguities are reported.
36     /// </summary>
37   protected:
38     const bool exactOnly;
39
40     /// <summary>
41     /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/> which only
42     /// reports exact ambiguities.
43     /// </summary>
44   public:
45     DiagnosticErrorListener();
46
47     /// <summary>
48     /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/>, specifying
49     /// whether all ambiguities or only exact ambiguities are reported.
50     /// </summary>
51     /// <param name="exactOnly"> {@code true} to report only exact ambiguities, otherwise
52     /// {@code false} to report all ambiguities. </param>
53     DiagnosticErrorListener(bool exactOnly);
54
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;
57
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;
60
61     virtual void reportContextSensitivity(Parser *recognizer, const dfa::DFA &dfa, size_t startIndex, size_t stopIndex,
62       size_t prediction, atn::ATNConfigSet *configs) override;
63
64   protected:
65     virtual std::string getDecisionDescription(Parser *recognizer, const dfa::DFA &dfa);
66
67     /// <summary>
68     /// Computes the set of conflicting or ambiguous alternatives from a
69     /// configuration set, if that information was not already provided by the
70     /// parser.
71     /// </summary>
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);
78   };
79
80 } // namespace antlr4