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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
/** \file
* Contains the definition of a basic ANTLR3 exception structure created
* by a recognizer when errors are found/predicted.
*/
#ifndef _ANTLR3_EXCEPTION_H
#define _ANTLR3_EXCEPTION_H
// [The "BSD licence"]
// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
// http://www.temporal-wave.com
// http://www.linkedin.com/in/jimidle
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. The name of the author may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <antlr3defs.h>
/** Indicates that the recognizer received a token
* in the input that was not predicted.
*/
#define ANTLR3_RECOGNITION_EXCEPTION 1
/** Name of exception #ANTLR3_RECOGNITION_EXCEPTION
*/
#define ANTLR3_RECOGNITION_EX_NAME "org.antlr.runtime.RecognitionException"
/** Indicates that the recognizer was expecting one token and found a
* a different one.
*/
#define ANTLR3_MISMATCHED_TOKEN_EXCEPTION 2
/** Name of #ANTLR3_MISMATCHED_TOKEN_EXCEPTION
*/
#define ANTLR3_MISMATCHED_EX_NAME "org.antlr.runtime.MismatchedTokenException"
/** Recognizer could not find a valid alternative from the input
*/
#define ANTLR3_NO_VIABLE_ALT_EXCEPTION 3
/** Name of #ANTLR3_NO_VIABLE_ALT_EXCEPTION
*/
#define ANTLR3_NO_VIABLE_ALT_NAME "org.antlr.runtime.NoViableAltException"
/* Character in a set was not found
*/
#define ANTLR3_MISMATCHED_SET_EXCEPTION 4
/* Name of #ANTLR3_MISMATCHED_SET_EXCEPTION
*/
#define ANTLR3_MISMATCHED_SET_NAME "org.antlr.runtime.MismatchedSetException"
/* A rule predicting at least n elements found less than that,
* such as: WS: " "+;
*/
#define ANTLR3_EARLY_EXIT_EXCEPTION 5
/* Name of #ANTLR3_EARLY_EXIT_EXCEPTION
*/
#define ANTLR3_EARLY_EXIT_NAME "org.antlr.runtime.EarlyExitException"
#define ANTLR3_FAILED_PREDICATE_EXCEPTION 6
#define ANTLR3_FAILED_PREDICATE_NAME "org.antlr.runtime.FailedPredicateException"
#define ANTLR3_MISMATCHED_TREE_NODE_EXCEPTION 7
#define ANTLR3_MISMATCHED_TREE_NODE_NAME "org.antlr.runtime.MismatchedTreeNodeException"
#define ANTLR3_REWRITE_EARLY_EXCEPTION 8
#define ANTLR3_REWRITE_EARLY_EXCEPTION_NAME "org.antlr.runtime.tree.RewriteEarlyExitException"
#define ANTLR3_UNWANTED_TOKEN_EXCEPTION 9
#define ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME "org.antlr.runtime.UnwantedTokenException"
#define ANTLR3_MISSING_TOKEN_EXCEPTION 10
#define ANTLR3_MISSING_TOKEN_EXCEPTION_NAME "org.antlr.runtime.MissingTokenException"
#ifdef __cplusplus
extern "C" {
#endif
/** Base structure for an ANTLR3 exception tracker
*/
typedef struct ANTLR3_EXCEPTION_struct
{
/// Set to one of the exception type defines:
///
/// - #ANTLR3_RECOGNITION_EXCEPTION
/// - #ANTLR3_MISMATCHED_TOKEN_EXCEPTION
/// - #ANTLR3_NO_VIABLE_ALT_EXCEPTION
/// - #ANTLR3_MISMATCHED_SET_EXCEPTION
/// - #ANTLR3_EARLY_EXIT_EXCEPTION
/// - #ANTLR3_FAILED_PREDICATE_EXCEPTION
/// - #ANTLR3_EARLY_EXIT_EXCEPTION
///
ANTLR3_UINT32 type;
/** The string name of the exception
*/
void * name;
/** The printable message that goes with this exception, in your preferred
* encoding format. ANTLR just uses ASCII by default but you can ignore these
* messages or convert them to another format or whatever of course. They are
* really internal messages that you then decide how to print out in a form that
* the users of your product will understand, as they are unlikely to know what
* to do with "Recognition exception at: [[TOK_GERUND..... " ;-)
*/
void * message;
/** Name of the file/input source for reporting. Note that this may be NULL!!
*/
pANTLR3_STRING streamName;
/** If set to ANTLR3_TRUE, this indicates that the message element of this structure
* should be freed by calling ANTLR3_FREE() when the exception is destroyed.
*/
ANTLR3_BOOLEAN freeMessage;
/** Indicates the index of the 'token' we were looking at when the
* exception occurred.
*/
ANTLR3_MARKER index;
/** Indicates what the current token/tree was when the error occurred. Since not
* all input streams will be able to retrieve the nth token, we track it here
* instead. This is for parsers, and even tree parsers may set this.
*/
void * token;
/** Indicates the token we were expecting to see next when the error occurred
*/
ANTLR3_UINT32 expecting;
/** Indicates a set of tokens that we were expecting to see one of when the
* error occurred. It is a following bitset list, so you can use load it and use ->toIntList() on it
* to generate an array of integer tokens that it represents.
*/
pANTLR3_BITSET_LIST expectingSet;
/** If this is a tree parser exception then the node is set to point to the node
* that caused the issue.
*/
void * node;
/** The current character when an error occurred - for lexers.
*/
ANTLR3_UCHAR c;
/** 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.
*/
ANTLR3_UINT32 line;
/** Character position in the line where the error occurred.
*/
ANTLR3_INT32 charPositionInLine;
/** decision number for NVE
*/
ANTLR3_UINT32 decisionNum;
/** State for NVE
*/
ANTLR3_UINT32 state;
/** Rule name for failed predicate exception
*/
void * ruleName;
/** Pointer to the next exception in the chain (if any)
*/
struct ANTLR3_EXCEPTION_struct * nextException;
/** Pointer to the input stream that this exception occurred in.
*/
pANTLR3_INT_STREAM input;
/** Pointer for you, the programmer to add anything you like to an exception.
*/
void * custom;
/** Pointer to a routine that is called to free the custom exception structure
* when the exception is destroyed. Set to NULL if nothing should be done.
*/
void (*freeCustom) (void * custom);
void (*print) (struct ANTLR3_EXCEPTION_struct * ex);
void (*freeEx) (struct ANTLR3_EXCEPTION_struct * ex);
}
ANTLR3_EXCEPTION;
#ifdef __cplusplus
}
#endif
#endif
|