]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3exception.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3exception.h
1 /** \file\r
2  *  Contains the definition of a basic ANTLR3 exception structure created\r
3  *  by a recognizer when errors are found/predicted.\r
4  */\r
5 #ifndef _ANTLR3_EXCEPTION_H\r
6 #define _ANTLR3_EXCEPTION_H\r
7 \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
12 //\r
13 // All rights reserved.\r
14 //\r
15 // Redistribution and use in source and binary forms, with or without\r
16 // modification, are permitted provided that the following conditions\r
17 // are met:\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
25 //\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
36 \r
37 #include    <antlr3defs.h>\r
38 \r
39 /** Indicates that the recognizer received a token\r
40  *  in the input that was not predicted.\r
41  */\r
42 #define ANTLR3_RECOGNITION_EXCEPTION        1\r
43 \r
44 /** Name of exception #ANTLR3_RECOGNITION_EXCEPTION\r
45  */\r
46 #define ANTLR3_RECOGNITION_EX_NAME  "Recognition Exception"\r
47 \r
48 /** Indicates that the recognizer was expecting one token and found a\r
49  *  a different one.\r
50  */\r
51 #define ANTLR3_MISMATCHED_TOKEN_EXCEPTION   2\r
52 \r
53 /** Name of #ANTLR3_MISMATCHED_TOKEN_EXCEPTION\r
54  */\r
55 #define ANTLR3_MISMATCHED_EX_NAME   "Mismatched Token Exception"\r
56 \r
57 /** Recognizer could not find a valid alternative from the input\r
58  */\r
59 #define ANTLR3_NO_VIABLE_ALT_EXCEPTION      3\r
60 \r
61 /** Name of #ANTLR3_NO_VIABLE_ALT_EXCEPTION\r
62  */\r
63 #define ANTLR3_NO_VIABLE_ALT_NAME   "No Viable Alt"\r
64 \r
65 /* Character in a set was not found\r
66  */\r
67 #define ANTLR3_MISMATCHED_SET_EXCEPTION     4\r
68 \r
69 /* Name of #ANTLR3_MISMATCHED_SET_EXCEPTION\r
70  */\r
71 #define ANTLR3_MISMATCHED_SET_NAME  "Mismatched set"\r
72 \r
73 /* A rule predicting at least n elements found less than that,\r
74  * such as: WS: " "+;\r
75  */\r
76 #define ANTLR3_EARLY_EXIT_EXCEPTION         5\r
77 \r
78 /* Name of #ANTLR3_EARLY_EXIT_EXCEPTION\r
79  */\r
80 #define ANTLR3_EARLY_EXIT_NAME       "Early exit"\r
81 \r
82 #define ANTLR3_FAILED_PREDICATE_EXCEPTION   6\r
83 #define ANTLR3_FAILED_PREDICATE_NAME        "Predicate failed!"\r
84 \r
85 #define ANTLR3_MISMATCHED_TREE_NODE_EXCEPTION   7\r
86 #define ANTLR3_MISMATCHED_TREE_NODE_NAME    "Mismatched tree node!"\r
87 \r
88 #define ANTLR3_REWRITE_EARLY_EXCEPTION  8\r
89 #define ANTLR3_REWRITE_EARLY_EXCEPTION_NAME    "Mismatched tree node!"\r
90 \r
91 #define ANTLR3_UNWANTED_TOKEN_EXCEPTION 9\r
92 #define ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME    "Extraneous token"\r
93 \r
94 #define ANTLR3_MISSING_TOKEN_EXCEPTION  10\r
95 #define ANTLR3_MISSING_TOKEN_EXCEPTION_NAME    "Missing token"\r
96 \r
97 #ifdef __cplusplus\r
98 extern "C" {\r
99 #endif\r
100 \r
101 /** Base structure for an ANTLR3 exception tracker\r
102  */\r
103 typedef struct ANTLR3_EXCEPTION_struct\r
104 {\r
105         /// Set to one of the exception type defines:\r
106         ///\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
114     ///\r
115     ANTLR3_UINT32   type;\r
116 \r
117     /** The string name of the exception\r
118      */\r
119     void    *       name;\r
120 \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
127      */\r
128     void    *       message;\r
129 \r
130     /** Name of the file/input source for reporting. Note that this may be NULL!!\r
131      */\r
132     pANTLR3_STRING streamName;\r
133 \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
136      */\r
137     ANTLR3_BOOLEAN  freeMessage;\r
138 \r
139     /** Indicates the index of the 'token' we were looking at when the\r
140      *  exception occurred.\r
141      */\r
142     ANTLR3_MARKER  index;\r
143 \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
147      */\r
148     void        * token;\r
149 \r
150     /** Indicates the token we were expecting to see next when the error occurred\r
151      */\r
152     ANTLR3_UINT32   expecting;\r
153 \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
157      */\r
158     pANTLR3_BITSET_LIST  expectingSet;\r
159 \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
162      */\r
163     void        * node;\r
164 \r
165     /** The current character when an error occurred - for lexers.\r
166      */\r
167     ANTLR3_UCHAR   c;\r
168 \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
172      */\r
173     ANTLR3_UINT32   line;\r
174 \r
175     /** Character position in the line where the error occurred.\r
176      */\r
177     ANTLR3_INT32   charPositionInLine;\r
178 \r
179     /** decision number for NVE\r
180      */\r
181     ANTLR3_UINT32   decisionNum;\r
182 \r
183     /** State for NVE\r
184      */\r
185     ANTLR3_UINT32   state;\r
186 \r
187     /** Rule name for failed predicate exception\r
188      */\r
189     void            * ruleName;\r
190 \r
191     /** Pointer to the next exception in the chain (if any)\r
192      */\r
193     struct ANTLR3_EXCEPTION_struct * nextException;\r
194 \r
195     /** Pointer to the input stream that this exception occurred in.\r
196      */\r
197     pANTLR3_INT_STREAM    input;\r
198 \r
199     /** Pointer for you, the programmer to add anything you like to an exception.\r
200      */\r
201     void    *       custom;\r
202 \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
205      */\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
209 \r
210 }\r
211     ANTLR3_EXCEPTION;\r
212 \r
213 #ifdef __cplusplus\r
214 }\r
215 #endif\r
216 \r
217 \r
218 #endif\r