2 * Contains the definition of a basic ANTLR3 exception structure created
\r
3 * by a recognizer when errors are found/predicted.
\r
5 #ifndef _ANTLR3_EXCEPTION_H
\r
6 #define _ANTLR3_EXCEPTION_H
\r
8 // [The "BSD licence"]
\r
9 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
\r
10 // http://www.temporal-wave.com
\r
11 // http://www.linkedin.com/in/jimidle
\r
13 // All rights reserved.
\r
15 // Redistribution and use in source and binary forms, with or without
\r
16 // modification, are permitted provided that the following conditions
\r
18 // 1. Redistributions of source code must retain the above copyright
\r
19 // notice, this list of conditions and the following disclaimer.
\r
20 // 2. Redistributions in binary form must reproduce the above copyright
\r
21 // notice, this list of conditions and the following disclaimer in the
\r
22 // documentation and/or other materials provided with the distribution.
\r
23 // 3. The name of the author may not be used to endorse or promote products
\r
24 // derived from this software without specific prior written permission.
\r
26 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
27 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
28 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
29 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
30 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
31 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
32 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
33 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
34 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
35 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
37 #include <antlr3defs.h>
\r
39 /** Indicates that the recognizer received a token
\r
40 * in the input that was not predicted.
\r
42 #define ANTLR3_RECOGNITION_EXCEPTION 1
\r
44 /** Name of exception #ANTLR3_RECOGNITION_EXCEPTION
\r
46 #define ANTLR3_RECOGNITION_EX_NAME "Recognition Exception"
\r
48 /** Indicates that the recognizer was expecting one token and found a
\r
51 #define ANTLR3_MISMATCHED_TOKEN_EXCEPTION 2
\r
53 /** Name of #ANTLR3_MISMATCHED_TOKEN_EXCEPTION
\r
55 #define ANTLR3_MISMATCHED_EX_NAME "Mismatched Token Exception"
\r
57 /** Recognizer could not find a valid alternative from the input
\r
59 #define ANTLR3_NO_VIABLE_ALT_EXCEPTION 3
\r
61 /** Name of #ANTLR3_NO_VIABLE_ALT_EXCEPTION
\r
63 #define ANTLR3_NO_VIABLE_ALT_NAME "No Viable Alt"
\r
65 /* Character in a set was not found
\r
67 #define ANTLR3_MISMATCHED_SET_EXCEPTION 4
\r
69 /* Name of #ANTLR3_MISMATCHED_SET_EXCEPTION
\r
71 #define ANTLR3_MISMATCHED_SET_NAME "Mismatched set"
\r
73 /* A rule predicting at least n elements found less than that,
\r
74 * such as: WS: " "+;
\r
76 #define ANTLR3_EARLY_EXIT_EXCEPTION 5
\r
78 /* Name of #ANTLR3_EARLY_EXIT_EXCEPTION
\r
80 #define ANTLR3_EARLY_EXIT_NAME "Early exit"
\r
82 #define ANTLR3_FAILED_PREDICATE_EXCEPTION 6
\r
83 #define ANTLR3_FAILED_PREDICATE_NAME "Predicate failed!"
\r
85 #define ANTLR3_MISMATCHED_TREE_NODE_EXCEPTION 7
\r
86 #define ANTLR3_MISMATCHED_TREE_NODE_NAME "Mismatched tree node!"
\r
88 #define ANTLR3_REWRITE_EARLY_EXCEPTION 8
\r
89 #define ANTLR3_REWRITE_EARLY_EXCEPTION_NAME "Mismatched tree node!"
\r
91 #define ANTLR3_UNWANTED_TOKEN_EXCEPTION 9
\r
92 #define ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME "Extraneous token"
\r
94 #define ANTLR3_MISSING_TOKEN_EXCEPTION 10
\r
95 #define ANTLR3_MISSING_TOKEN_EXCEPTION_NAME "Missing token"
\r
101 /** Base structure for an ANTLR3 exception tracker
\r
103 typedef struct ANTLR3_EXCEPTION_struct
\r
105 /// Set to one of the exception type defines:
\r
107 /// - #ANTLR3_RECOGNITION_EXCEPTION
\r
108 /// - #ANTLR3_MISMATCHED_TOKEN_EXCEPTION
\r
109 /// - #ANTLR3_NO_VIABLE_ALT_EXCEPTION
\r
110 /// - #ANTLR3_MISMATCHED_SET_EXCEPTION
\r
111 /// - #ANTLR3_EARLY_EXIT_EXCEPTION
\r
112 /// - #ANTLR3_FAILED_PREDICATE_EXCEPTION
\r
113 /// - #ANTLR3_EARLY_EXIT_EXCEPTION
\r
115 ANTLR3_UINT32 type;
\r
117 /** The string name of the exception
\r
121 /** The printable message that goes with this exception, in your preferred
\r
122 * encoding format. ANTLR just uses ASCII by default but you can ignore these
\r
123 * messages or convert them to another format or whatever of course. They are
\r
124 * really internal messages that you then decide how to print out in a form that
\r
125 * the users of your product will understand, as they are unlikely to know what
\r
126 * to do with "Recognition exception at: [[TOK_GERUND..... " ;-)
\r
130 /** Name of the file/input source for reporting. Note that this may be NULL!!
\r
132 pANTLR3_STRING streamName;
\r
134 /** If set to ANTLR3_TRUE, this indicates that the message element of this structure
\r
135 * should be freed by calling ANTLR3_FREE() when the exception is destroyed.
\r
137 ANTLR3_BOOLEAN freeMessage;
\r
139 /** Indicates the index of the 'token' we were looking at when the
\r
140 * exception occurred.
\r
142 ANTLR3_MARKER index;
\r
144 /** Indicates what the current token/tree was when the error occurred. Since not
\r
145 * all input streams will be able to retrieve the nth token, we track it here
\r
146 * instead. This is for parsers, and even tree parsers may set this.
\r
150 /** Indicates the token we were expecting to see next when the error occurred
\r
152 ANTLR3_UINT32 expecting;
\r
154 /** Indicates a set of tokens that we were expecting to see one of when the
\r
155 * error occurred. It is a following bitset list, so you can use load it and use ->toIntList() on it
\r
156 * to generate an array of integer tokens that it represents.
\r
158 pANTLR3_BITSET_LIST expectingSet;
\r
160 /** If this is a tree parser exception then the node is set to point to the node
\r
161 * that caused the issue.
\r
165 /** The current character when an error occurred - for lexers.
\r
169 /** Track the line at which the error occurred in case this is
\r
170 * generated from a lexer. We need to track this since the
\r
171 * unexpected char doesn't carry the line info.
\r
173 ANTLR3_UINT32 line;
\r
175 /** Character position in the line where the error occurred.
\r
177 ANTLR3_INT32 charPositionInLine;
\r
179 /** decision number for NVE
\r
181 ANTLR3_UINT32 decisionNum;
\r
185 ANTLR3_UINT32 state;
\r
187 /** Rule name for failed predicate exception
\r
191 /** Pointer to the next exception in the chain (if any)
\r
193 struct ANTLR3_EXCEPTION_struct * nextException;
\r
195 /** Pointer to the input stream that this exception occurred in.
\r
197 pANTLR3_INT_STREAM input;
\r
199 /** Pointer for you, the programmer to add anything you like to an exception.
\r
203 /** Pointer to a routine that is called to free the custom exception structure
\r
204 * when the exception is destroyed. Set to NULL if nothing should be done.
\r
206 void (*freeCustom) (void * custom);
\r
207 void (*print) (struct ANTLR3_EXCEPTION_struct * ex);
\r
208 void (*freeEx) (struct ANTLR3_EXCEPTION_struct * ex);
\r