

Public Member Functions | |
| RecognitionException () | |
| Used for remote debugger deserialization. | |
| RecognitionException (string message) | |
| RecognitionException (string message, Exception inner) | |
| RecognitionException (IIntStream input) | |
| RecognitionException (string message, IIntStream input) | |
| RecognitionException (string message, Exception inner, IIntStream input) | |
Public Attributes | |
| bool | approximateLineInfo |
| If you are parsing a tree node stream, you will encounter some imaginary nodes w/o line/col info. We now search backwards looking for most recent token with line/col info, but notify getErrorHeader() that info is approximate. | |
Protected Member Functions | |
| void | ExtractInformationFromTreeNodeStream (IIntStream input) |
Protected Attributes | |
| IIntStream | input |
| What input stream did the error occur in? | |
| int | index |
| What is index of token/char were we looking at when the error occurred? | |
| IToken | token |
| The current Token when an error occurred. Since not all streams can retrieve the ith Token, we have to track the Token object. | |
| object | node |
| [Tree parser] Node with the problem. | |
| int | c |
| The current char when an error occurred. For lexers. | |
| int | line |
| Track the line at which the error occurred in case this is generated from a lexer. We need to track this since the unexpected char doesn't carry the line info. | |
| int | charPositionInLine |
Properties | |
| IIntStream | Input [get, set] |
| Returns the input stream in which the error occurred. | |
| int | Index [get, set] |
| Returns the token/char index in the stream when the error occurred. | |
| IToken | Token [get, set] |
| Returns the current Token when the error occurred (for parsers although a tree parser might also set the token). | |
| object | Node [get, set] |
| Returns the [tree parser] node where the error occured (for tree parsers). | |
| int | Char [get, set] |
| Returns the current char when the error occurred (for lexers). | |
| int | CharPositionInLine [get, set] |
| Returns the character position in the line when the error occurred (for lexers). | |
| int | Line [get, set] |
| Returns the line at which the error occurred (for lexers). | |
| virtual int | UnexpectedType [get] |
| Returns the token type or char of the unexpected input element. | |
To avoid English-only error messages and to generally make things as flexible as possible, these exceptions are not created with strings, but rather the information necessary to generate an error. Then the various reporting methods in Parser and Lexer can be overridden to generate a localized error message. For example, MismatchedToken exceptions are built with the expected token type. So, don't expect getMessage() to return anything.
You can access the stack trace, which means that you can compute the complete trace of rules from the start symbol. This gives you considerable context information with which to generate useful error messages.
ANTLR generates code that throws exceptions upon recognition error and also generates code to catch these exceptions in each rule. If you want to quit upon first error, you can turn off the automatic error handling mechanism using rulecatch action, but you still need to override methods mismatch and recoverFromMismatchSet.
In general, the recognition exceptions can track where in a grammar a problem occurred and/or what was the expected input. While the parser knows its state (such as current input symbol and line info) that state can change before the exception is reported so current token index is computed and stored at exception time. From this info, you can perhaps print an entire line of input not just a single token, for example. Better to just say the recognizer had a problem and then let the parser figure out a fancy report.
Definition at line 74 of file RecognitionException.cs.
| Antlr.Runtime.RecognitionException.RecognitionException | ( | ) |
| Antlr.Runtime.RecognitionException.RecognitionException | ( | string | message | ) |
Definition at line 84 of file RecognitionException.cs.
| Antlr.Runtime.RecognitionException.RecognitionException | ( | string | message, | |
| Exception | inner | |||
| ) |
Definition at line 89 of file RecognitionException.cs.
| Antlr.Runtime.RecognitionException.RecognitionException | ( | IIntStream | input | ) |
Definition at line 94 of file RecognitionException.cs.
| Antlr.Runtime.RecognitionException.RecognitionException | ( | string | message, | |
| IIntStream | input | |||
| ) |
Definition at line 99 of file RecognitionException.cs.
| Antlr.Runtime.RecognitionException.RecognitionException | ( | string | message, | |
| Exception | inner, | |||
| IIntStream | input | |||
| ) |
Definition at line 104 of file RecognitionException.cs.
| void Antlr.Runtime.RecognitionException.ExtractInformationFromTreeNodeStream | ( | IIntStream | input | ) | [protected] |
Definition at line 227 of file RecognitionException.cs.
IIntStream Antlr.Runtime.RecognitionException.input [protected] |
int Antlr.Runtime.RecognitionException.index [protected] |
What is index of token/char were we looking at when the error occurred?
Definition at line 292 of file RecognitionException.cs.
IToken Antlr.Runtime.RecognitionException.token [protected] |
The current Token when an error occurred. Since not all streams can retrieve the ith Token, we have to track the Token object.
Definition at line 298 of file RecognitionException.cs.
object Antlr.Runtime.RecognitionException.node [protected] |
int Antlr.Runtime.RecognitionException.c [protected] |
The current char when an error occurred. For lexers.
Definition at line 304 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.line [protected] |
Track the line at which the error occurred in case this is generated from a lexer. We need to track this since the unexpected char doesn't carry the line info.
Definition at line 310 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.charPositionInLine [protected] |
Definition at line 312 of file RecognitionException.cs.
If you are parsing a tree node stream, you will encounter some imaginary nodes w/o line/col info. We now search backwards looking for most recent token with line/col info, but notify getErrorHeader() that info is approximate.
Definition at line 320 of file RecognitionException.cs.
IIntStream Antlr.Runtime.RecognitionException.Input [get, set] |
Returns the input stream in which the error occurred.
Definition at line 137 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.Index [get, set] |
Returns the token/char index in the stream when the error occurred.
Definition at line 146 of file RecognitionException.cs.
IToken Antlr.Runtime.RecognitionException.Token [get, set] |
Returns the current Token when the error occurred (for parsers although a tree parser might also set the token).
Definition at line 156 of file RecognitionException.cs.
object Antlr.Runtime.RecognitionException.Node [get, set] |
Returns the [tree parser] node where the error occured (for tree parsers).
Definition at line 165 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.Char [get, set] |
Returns the current char when the error occurred (for lexers).
Definition at line 174 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.CharPositionInLine [get, set] |
Returns the character position in the line when the error occurred (for lexers).
Definition at line 184 of file RecognitionException.cs.
int Antlr.Runtime.RecognitionException.Line [get, set] |
Returns the line at which the error occurred (for lexers).
Definition at line 193 of file RecognitionException.cs.
virtual int Antlr.Runtime.RecognitionException.UnexpectedType [get] |
Returns the token type or char of the unexpected input element.
Definition at line 202 of file RecognitionException.cs.
1.5.5