summaryrefslogtreecommitdiff
path: root/deps/v8/third_party/antlr4/runtime/Cpp/runtime/src/DiagnosticErrorListener.h
blob: e6214ca775e7048219b326ee61ab0e4fd50e98da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
 * Use of this file is governed by the BSD 3-clause license that
 * can be found in the LICENSE.txt file in the project root.
 */

#pragma once

#include "BaseErrorListener.h"

namespace antlr4 {

/// <summary>
/// This implementation of <seealso cref="ANTLRErrorListener"/> can be used to
/// identify certain potential correctness and performance problems in grammars.
/// "Reports" are made by calling <seealso cref="Parser#notifyErrorListeners"/>
/// with the appropriate message.
///
/// <ul>
/// <li><b>Ambiguities</b>: These are cases where more than one path through the
/// grammar can match the input.</li>
/// <li><b>Weak context sensitivity</b>: 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><b>Strong (forced)
/// context sensitivity</b>: These are cases where the full-context prediction
/// resolved an SLL conflict to a unique alternative, <em>and</em> 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>
///
/// @author Sam Harwell
/// </summary>
class ANTLR4CPP_PUBLIC DiagnosticErrorListener : public BaseErrorListener {
  /// <summary>
  /// When {@code true}, only exactly known ambiguities are reported.
  /// </summary>
 protected:
  const bool exactOnly;

  /// <summary>
  /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/>
  /// which only reports exact ambiguities.
  /// </summary>
 public:
  DiagnosticErrorListener();

  /// <summary>
  /// Initializes a new instance of <seealso cref="DiagnosticErrorListener"/>,
  /// specifying whether all ambiguities or only exact ambiguities are reported.
  /// </summary>
  /// <param name="exactOnly"> {@code true} to report only exact ambiguities,
  /// otherwise
  /// {@code false} to report all ambiguities. </param>
  DiagnosticErrorListener(bool exactOnly);

  virtual void reportAmbiguity(Parser* recognizer, const dfa::DFA& dfa,
                               size_t startIndex, size_t stopIndex, bool exact,
                               const antlrcpp::BitSet& ambigAlts,
                               atn::ATNConfigSet* configs) override;

  virtual void reportAttemptingFullContext(
      Parser* recognizer, const dfa::DFA& dfa, size_t startIndex,
      size_t stopIndex, const antlrcpp::BitSet& conflictingAlts,
      atn::ATNConfigSet* configs) override;

  virtual void reportContextSensitivity(Parser* recognizer, const dfa::DFA& dfa,
                                        size_t startIndex, size_t stopIndex,
                                        size_t prediction,
                                        atn::ATNConfigSet* configs) override;

 protected:
  virtual std::string getDecisionDescription(Parser* recognizer,
                                             const dfa::DFA& dfa);

  /// <summary>
  /// Computes the set of conflicting or ambiguous alternatives from a
  /// configuration set, if that information was not already provided by the
  /// parser.
  /// </summary>
  /// <param name="reportedAlts"> The set of conflicting or ambiguous
  /// alternatives, as reported by the parser. </param> <param name="configs">
  /// The conflicting or ambiguous configuration set. </param> <returns> Returns
  /// {@code reportedAlts} if it is not {@code null}, otherwise returns the set
  /// of alternatives represented in {@code configs}. </returns>
  virtual antlrcpp::BitSet getConflictingAlts(
      const antlrcpp::BitSet& reportedAlts, atn::ATNConfigSet* configs);
};

}  // namespace antlr4