/proc/self/cwd/external/antlr4-cpp-runtime~/runtime/src/RecognitionException.h
Line | Count | Source |
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 "Exceptions.h" |
9 | | |
10 | | namespace antlr4 { |
11 | | |
12 | | /// The root of the ANTLR exception hierarchy. In general, ANTLR tracks just |
13 | | /// 3 kinds of errors: prediction errors, failed predicate errors, and |
14 | | /// mismatched input errors. In each case, the parser knows where it is |
15 | | /// in the input, where it is in the ATN, the rule invocation stack, |
16 | | /// and what kind of problem occurred. |
17 | | class ANTLR4CPP_PUBLIC RecognitionException : public RuntimeException { |
18 | | private: |
19 | | /// The Recognizer where this exception originated. |
20 | | Recognizer *_recognizer; |
21 | | IntStream *_input; |
22 | | ParserRuleContext *_ctx; |
23 | | |
24 | | /// The current Token when an error occurred. Since not all streams |
25 | | /// support accessing symbols by index, we have to track the Token |
26 | | /// instance itself. |
27 | | Token *_offendingToken; |
28 | | |
29 | | size_t _offendingState; |
30 | | |
31 | | public: |
32 | | RecognitionException(Recognizer *recognizer, IntStream *input, ParserRuleContext *ctx, |
33 | | Token *offendingToken = nullptr); |
34 | | RecognitionException(const std::string &message, Recognizer *recognizer, IntStream *input, |
35 | | ParserRuleContext *ctx, Token *offendingToken = nullptr); |
36 | 12.6k | RecognitionException(RecognitionException const&) = default; |
37 | | ~RecognitionException(); |
38 | | RecognitionException& operator=(RecognitionException const&) = default; |
39 | | |
40 | | /// Get the ATN state number the parser was in at the time the error |
41 | | /// occurred. For NoViableAltException and |
42 | | /// LexerNoViableAltException exceptions, this is the |
43 | | /// DecisionState number. For others, it is the state whose outgoing |
44 | | /// edge we couldn't match. |
45 | | /// |
46 | | /// If the state number is not known, this method returns -1. |
47 | | virtual size_t getOffendingState() const; |
48 | | |
49 | | protected: |
50 | | void setOffendingState(size_t offendingState); |
51 | | |
52 | | /// Gets the set of input symbols which could potentially follow the |
53 | | /// previously matched symbol at the time this exception was thrown. |
54 | | /// |
55 | | /// If the set of expected tokens is not known and could not be computed, |
56 | | /// this method returns an empty set. |
57 | | /// |
58 | | /// @returns The set of token types that could potentially follow the current |
59 | | /// state in the ATN, or an empty set if the information is not available. |
60 | | public: |
61 | | virtual misc::IntervalSet getExpectedTokens() const; |
62 | | |
63 | | /// <summary> |
64 | | /// Gets the <seealso cref="RuleContext"/> at the time this exception was thrown. |
65 | | /// <p/> |
66 | | /// If the context is not available, this method returns {@code null}. |
67 | | /// </summary> |
68 | | /// <returns> The <seealso cref="RuleContext"/> at the time this exception was thrown. |
69 | | /// If the context is not available, this method returns {@code null}. </returns> |
70 | | virtual RuleContext* getCtx() const; |
71 | | |
72 | | /// <summary> |
73 | | /// Gets the input stream which is the symbol source for the recognizer where |
74 | | /// this exception was thrown. |
75 | | /// <p/> |
76 | | /// If the input stream is not available, this method returns {@code null}. |
77 | | /// </summary> |
78 | | /// <returns> The input stream which is the symbol source for the recognizer |
79 | | /// where this exception was thrown, or {@code null} if the stream is not |
80 | | /// available. </returns> |
81 | | virtual IntStream* getInputStream() const; |
82 | | |
83 | | virtual Token* getOffendingToken() const; |
84 | | |
85 | | /// <summary> |
86 | | /// Gets the <seealso cref="Recognizer"/> where this exception occurred. |
87 | | /// <p/> |
88 | | /// If the recognizer is not available, this method returns {@code null}. |
89 | | /// </summary> |
90 | | /// <returns> The recognizer where this exception occurred, or {@code null} if |
91 | | /// the recognizer is not available. </returns> |
92 | | virtual Recognizer* getRecognizer() const; |
93 | | |
94 | | private: |
95 | | void InitializeInstanceFields(); |
96 | | }; |
97 | | |
98 | | } // namespace antlr4 |