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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 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.
*/
using Antlr4.Runtime;
using Antlr4.Runtime.Misc;
using Antlr4.Runtime.Sharpen;
using System.IO;
namespace Antlr4.Runtime
{
/// <summary>
/// The interface for defining strategies to deal with syntax errors encountered
/// during a parse by ANTLR-generated parsers.
/// </summary>
/// <remarks>
/// The interface for defining strategies to deal with syntax errors encountered
/// during a parse by ANTLR-generated parsers. We distinguish between three
/// different kinds of errors:
/// <ul>
/// <li>The parser could not figure out which path to take in the ATN (none of
/// the available alternatives could possibly match)</li>
/// <li>The current input does not match what we were looking for</li>
/// <li>A predicate evaluated to false</li>
/// </ul>
/// Implementations of this interface report syntax errors by calling
/// <see cref="Parser.NotifyErrorListeners(string)"/>
/// .
/// <p>TODO: what to do about lexers</p>
/// </remarks>
public interface IAntlrErrorStrategy
{
/// <summary>
/// Reset the error handler state for the specified
/// <paramref name="recognizer"/>
/// .
/// </summary>
/// <param name="recognizer">the parser instance</param>
void Reset(Parser recognizer);
/// <summary>
/// This method is called when an unexpected symbol is encountered during an
/// inline match operation, such as
/// <see cref="Parser.Match(int)"/>
/// . If the error
/// strategy successfully recovers from the match failure, this method
/// returns the
/// <see cref="IToken"/>
/// instance which should be treated as the
/// successful result of the match.
/// <p>Note that the calling code will not report an error if this method
/// returns successfully. The error strategy implementation is responsible
/// for calling
/// <see cref="Parser.NotifyErrorListeners(string)"/>
/// as appropriate.</p>
/// </summary>
/// <param name="recognizer">the parser instance</param>
/// <exception cref="RecognitionException">
/// if the error strategy was not able to
/// recover from the unexpected input symbol
/// </exception>
/// <exception cref="Antlr4.Runtime.RecognitionException"/>
[return: NotNull]
IToken RecoverInline(Parser recognizer);
/// <summary>
/// This method is called to recover from exception
/// <paramref name="e"/>
/// . This method is
/// called after
/// <see cref="ReportError(Parser, RecognitionException)"/>
/// by the default exception handler
/// generated for a rule method.
/// </summary>
/// <seealso cref="ReportError(Parser, RecognitionException)"/>
/// <param name="recognizer">the parser instance</param>
/// <param name="e">the recognition exception to recover from</param>
/// <exception cref="RecognitionException">
/// if the error strategy could not recover from
/// the recognition exception
/// </exception>
/// <exception cref="Antlr4.Runtime.RecognitionException"/>
void Recover(Parser recognizer, RecognitionException e);
/// <summary>
/// This method provides the error handler with an opportunity to handle
/// syntactic or semantic errors in the input stream before they result in a
/// <see cref="RecognitionException"/>
/// .
/// <p>The generated code currently contains calls to
/// <see cref="Sync(Parser)"/>
/// after
/// entering the decision state of a closure block (
/// <c>(...)*</c>
/// or
/// <c>(...)+</c>
/// ).</p>
/// <p>For an implementation based on Jim Idle's "magic sync" mechanism, see
/// <see cref="DefaultErrorStrategy.Sync(Parser)"/>
/// .</p>
/// </summary>
/// <seealso cref="DefaultErrorStrategy.Sync(Parser)"/>
/// <param name="recognizer">the parser instance</param>
/// <exception cref="RecognitionException">
/// if an error is detected by the error
/// strategy but cannot be automatically recovered at the current state in
/// the parsing process
/// </exception>
/// <exception cref="Antlr4.Runtime.RecognitionException"/>
void Sync(Parser recognizer);
/// <summary>
/// Tests whether or not
/// <paramref name="recognizer"/>
/// is in the process of recovering
/// from an error. In error recovery mode,
/// <see cref="Parser.Consume()"/>
/// adds
/// symbols to the parse tree by calling
/// <see cref="ParserRuleContext.AddErrorNode(IToken)"/>
/// instead of
/// <see cref="ParserRuleContext.AddChild(IToken)"/>
/// .
/// </summary>
/// <param name="recognizer">the parser instance</param>
/// <returns>
///
/// <see langword="true"/>
/// if the parser is currently recovering from a parse
/// error, otherwise
/// <see langword="false"/>
/// </returns>
bool InErrorRecoveryMode(Parser recognizer);
/// <summary>
/// This method is called by when the parser successfully matches an input
/// symbol.
/// </summary>
/// <remarks>
/// This method is called by when the parser successfully matches an input
/// symbol.
/// </remarks>
/// <param name="recognizer">the parser instance</param>
void ReportMatch(Parser recognizer);
/// <summary>
/// Report any kind of
/// <see cref="RecognitionException"/>
/// . This method is called by
/// the default exception handler generated for a rule method.
/// </summary>
/// <param name="recognizer">the parser instance</param>
/// <param name="e">the recognition exception to report</param>
void ReportError(Parser recognizer, RecognitionException e);
}
}