1*16467b97STreehugger Robot /** \file 2*16467b97STreehugger Robot * Contains the definition of a basic ANTLR3 exception structure created 3*16467b97STreehugger Robot * by a recognizer when errors are found/predicted. 4*16467b97STreehugger Robot */ 5*16467b97STreehugger Robot #ifndef _ANTLR3_EXCEPTION_H 6*16467b97STreehugger Robot #define _ANTLR3_EXCEPTION_H 7*16467b97STreehugger Robot 8*16467b97STreehugger Robot // [The "BSD licence"] 9*16467b97STreehugger Robot // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC 10*16467b97STreehugger Robot // http://www.temporal-wave.com 11*16467b97STreehugger Robot // http://www.linkedin.com/in/jimidle 12*16467b97STreehugger Robot // 13*16467b97STreehugger Robot // All rights reserved. 14*16467b97STreehugger Robot // 15*16467b97STreehugger Robot // Redistribution and use in source and binary forms, with or without 16*16467b97STreehugger Robot // modification, are permitted provided that the following conditions 17*16467b97STreehugger Robot // are met: 18*16467b97STreehugger Robot // 1. Redistributions of source code must retain the above copyright 19*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer. 20*16467b97STreehugger Robot // 2. Redistributions in binary form must reproduce the above copyright 21*16467b97STreehugger Robot // notice, this list of conditions and the following disclaimer in the 22*16467b97STreehugger Robot // documentation and/or other materials provided with the distribution. 23*16467b97STreehugger Robot // 3. The name of the author may not be used to endorse or promote products 24*16467b97STreehugger Robot // derived from this software without specific prior written permission. 25*16467b97STreehugger Robot // 26*16467b97STreehugger Robot // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27*16467b97STreehugger Robot // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28*16467b97STreehugger Robot // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29*16467b97STreehugger Robot // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30*16467b97STreehugger Robot // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31*16467b97STreehugger Robot // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32*16467b97STreehugger Robot // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33*16467b97STreehugger Robot // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34*16467b97STreehugger Robot // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35*16467b97STreehugger Robot // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36*16467b97STreehugger Robot 37*16467b97STreehugger Robot #include <antlr3defs.h> 38*16467b97STreehugger Robot 39*16467b97STreehugger Robot /** Indicates that the recognizer received a token 40*16467b97STreehugger Robot * in the input that was not predicted. 41*16467b97STreehugger Robot */ 42*16467b97STreehugger Robot #define ANTLR3_RECOGNITION_EXCEPTION 1 43*16467b97STreehugger Robot 44*16467b97STreehugger Robot /** Name of exception #ANTLR3_RECOGNITION_EXCEPTION 45*16467b97STreehugger Robot */ 46*16467b97STreehugger Robot #define ANTLR3_RECOGNITION_EX_NAME "org.antlr.runtime.RecognitionException" 47*16467b97STreehugger Robot 48*16467b97STreehugger Robot /** Indicates that the recognizer was expecting one token and found a 49*16467b97STreehugger Robot * a different one. 50*16467b97STreehugger Robot */ 51*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_TOKEN_EXCEPTION 2 52*16467b97STreehugger Robot 53*16467b97STreehugger Robot /** Name of #ANTLR3_MISMATCHED_TOKEN_EXCEPTION 54*16467b97STreehugger Robot */ 55*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_EX_NAME "org.antlr.runtime.MismatchedTokenException" 56*16467b97STreehugger Robot 57*16467b97STreehugger Robot /** Recognizer could not find a valid alternative from the input 58*16467b97STreehugger Robot */ 59*16467b97STreehugger Robot #define ANTLR3_NO_VIABLE_ALT_EXCEPTION 3 60*16467b97STreehugger Robot 61*16467b97STreehugger Robot /** Name of #ANTLR3_NO_VIABLE_ALT_EXCEPTION 62*16467b97STreehugger Robot */ 63*16467b97STreehugger Robot #define ANTLR3_NO_VIABLE_ALT_NAME "org.antlr.runtime.NoViableAltException" 64*16467b97STreehugger Robot 65*16467b97STreehugger Robot /* Character in a set was not found 66*16467b97STreehugger Robot */ 67*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_SET_EXCEPTION 4 68*16467b97STreehugger Robot 69*16467b97STreehugger Robot /* Name of #ANTLR3_MISMATCHED_SET_EXCEPTION 70*16467b97STreehugger Robot */ 71*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_SET_NAME "org.antlr.runtime.MismatchedSetException" 72*16467b97STreehugger Robot 73*16467b97STreehugger Robot /* A rule predicting at least n elements found less than that, 74*16467b97STreehugger Robot * such as: WS: " "+; 75*16467b97STreehugger Robot */ 76*16467b97STreehugger Robot #define ANTLR3_EARLY_EXIT_EXCEPTION 5 77*16467b97STreehugger Robot 78*16467b97STreehugger Robot /* Name of #ANTLR3_EARLY_EXIT_EXCEPTION 79*16467b97STreehugger Robot */ 80*16467b97STreehugger Robot #define ANTLR3_EARLY_EXIT_NAME "org.antlr.runtime.EarlyExitException" 81*16467b97STreehugger Robot 82*16467b97STreehugger Robot #define ANTLR3_FAILED_PREDICATE_EXCEPTION 6 83*16467b97STreehugger Robot #define ANTLR3_FAILED_PREDICATE_NAME "org.antlr.runtime.FailedPredicateException" 84*16467b97STreehugger Robot 85*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_TREE_NODE_EXCEPTION 7 86*16467b97STreehugger Robot #define ANTLR3_MISMATCHED_TREE_NODE_NAME "org.antlr.runtime.MismatchedTreeNodeException" 87*16467b97STreehugger Robot 88*16467b97STreehugger Robot #define ANTLR3_REWRITE_EARLY_EXCEPTION 8 89*16467b97STreehugger Robot #define ANTLR3_REWRITE_EARLY_EXCEPTION_NAME "org.antlr.runtime.tree.RewriteEarlyExitException" 90*16467b97STreehugger Robot 91*16467b97STreehugger Robot #define ANTLR3_UNWANTED_TOKEN_EXCEPTION 9 92*16467b97STreehugger Robot #define ANTLR3_UNWANTED_TOKEN_EXCEPTION_NAME "org.antlr.runtime.UnwantedTokenException" 93*16467b97STreehugger Robot 94*16467b97STreehugger Robot #define ANTLR3_MISSING_TOKEN_EXCEPTION 10 95*16467b97STreehugger Robot #define ANTLR3_MISSING_TOKEN_EXCEPTION_NAME "org.antlr.runtime.MissingTokenException" 96*16467b97STreehugger Robot 97*16467b97STreehugger Robot #ifdef __cplusplus 98*16467b97STreehugger Robot extern "C" { 99*16467b97STreehugger Robot #endif 100*16467b97STreehugger Robot 101*16467b97STreehugger Robot /** Base structure for an ANTLR3 exception tracker 102*16467b97STreehugger Robot */ 103*16467b97STreehugger Robot typedef struct ANTLR3_EXCEPTION_struct 104*16467b97STreehugger Robot { 105*16467b97STreehugger Robot /// Set to one of the exception type defines: 106*16467b97STreehugger Robot /// 107*16467b97STreehugger Robot /// - #ANTLR3_RECOGNITION_EXCEPTION 108*16467b97STreehugger Robot /// - #ANTLR3_MISMATCHED_TOKEN_EXCEPTION 109*16467b97STreehugger Robot /// - #ANTLR3_NO_VIABLE_ALT_EXCEPTION 110*16467b97STreehugger Robot /// - #ANTLR3_MISMATCHED_SET_EXCEPTION 111*16467b97STreehugger Robot /// - #ANTLR3_EARLY_EXIT_EXCEPTION 112*16467b97STreehugger Robot /// - #ANTLR3_FAILED_PREDICATE_EXCEPTION 113*16467b97STreehugger Robot /// - #ANTLR3_EARLY_EXIT_EXCEPTION 114*16467b97STreehugger Robot /// 115*16467b97STreehugger Robot ANTLR3_UINT32 type; 116*16467b97STreehugger Robot 117*16467b97STreehugger Robot /** The string name of the exception 118*16467b97STreehugger Robot */ 119*16467b97STreehugger Robot void * name; 120*16467b97STreehugger Robot 121*16467b97STreehugger Robot /** The printable message that goes with this exception, in your preferred 122*16467b97STreehugger Robot * encoding format. ANTLR just uses ASCII by default but you can ignore these 123*16467b97STreehugger Robot * messages or convert them to another format or whatever of course. They are 124*16467b97STreehugger Robot * really internal messages that you then decide how to print out in a form that 125*16467b97STreehugger Robot * the users of your product will understand, as they are unlikely to know what 126*16467b97STreehugger Robot * to do with "Recognition exception at: [[TOK_GERUND..... " ;-) 127*16467b97STreehugger Robot */ 128*16467b97STreehugger Robot void * message; 129*16467b97STreehugger Robot 130*16467b97STreehugger Robot /** Name of the file/input source for reporting. Note that this may be NULL!! 131*16467b97STreehugger Robot */ 132*16467b97STreehugger Robot pANTLR3_STRING streamName; 133*16467b97STreehugger Robot 134*16467b97STreehugger Robot /** If set to ANTLR3_TRUE, this indicates that the message element of this structure 135*16467b97STreehugger Robot * should be freed by calling ANTLR3_FREE() when the exception is destroyed. 136*16467b97STreehugger Robot */ 137*16467b97STreehugger Robot ANTLR3_BOOLEAN freeMessage; 138*16467b97STreehugger Robot 139*16467b97STreehugger Robot /** Indicates the index of the 'token' we were looking at when the 140*16467b97STreehugger Robot * exception occurred. 141*16467b97STreehugger Robot */ 142*16467b97STreehugger Robot ANTLR3_MARKER index; 143*16467b97STreehugger Robot 144*16467b97STreehugger Robot /** Indicates what the current token/tree was when the error occurred. Since not 145*16467b97STreehugger Robot * all input streams will be able to retrieve the nth token, we track it here 146*16467b97STreehugger Robot * instead. This is for parsers, and even tree parsers may set this. 147*16467b97STreehugger Robot */ 148*16467b97STreehugger Robot void * token; 149*16467b97STreehugger Robot 150*16467b97STreehugger Robot /** Indicates the token we were expecting to see next when the error occurred 151*16467b97STreehugger Robot */ 152*16467b97STreehugger Robot ANTLR3_UINT32 expecting; 153*16467b97STreehugger Robot 154*16467b97STreehugger Robot /** Indicates a set of tokens that we were expecting to see one of when the 155*16467b97STreehugger Robot * error occurred. It is a following bitset list, so you can use load it and use ->toIntList() on it 156*16467b97STreehugger Robot * to generate an array of integer tokens that it represents. 157*16467b97STreehugger Robot */ 158*16467b97STreehugger Robot pANTLR3_BITSET_LIST expectingSet; 159*16467b97STreehugger Robot 160*16467b97STreehugger Robot /** If this is a tree parser exception then the node is set to point to the node 161*16467b97STreehugger Robot * that caused the issue. 162*16467b97STreehugger Robot */ 163*16467b97STreehugger Robot void * node; 164*16467b97STreehugger Robot 165*16467b97STreehugger Robot /** The current character when an error occurred - for lexers. 166*16467b97STreehugger Robot */ 167*16467b97STreehugger Robot ANTLR3_UCHAR c; 168*16467b97STreehugger Robot 169*16467b97STreehugger Robot /** Track the line at which the error occurred in case this is 170*16467b97STreehugger Robot * generated from a lexer. We need to track this since the 171*16467b97STreehugger Robot * unexpected char doesn't carry the line info. 172*16467b97STreehugger Robot */ 173*16467b97STreehugger Robot ANTLR3_UINT32 line; 174*16467b97STreehugger Robot 175*16467b97STreehugger Robot /** Character position in the line where the error occurred. 176*16467b97STreehugger Robot */ 177*16467b97STreehugger Robot ANTLR3_INT32 charPositionInLine; 178*16467b97STreehugger Robot 179*16467b97STreehugger Robot /** decision number for NVE 180*16467b97STreehugger Robot */ 181*16467b97STreehugger Robot ANTLR3_UINT32 decisionNum; 182*16467b97STreehugger Robot 183*16467b97STreehugger Robot /** State for NVE 184*16467b97STreehugger Robot */ 185*16467b97STreehugger Robot ANTLR3_UINT32 state; 186*16467b97STreehugger Robot 187*16467b97STreehugger Robot /** Rule name for failed predicate exception 188*16467b97STreehugger Robot */ 189*16467b97STreehugger Robot void * ruleName; 190*16467b97STreehugger Robot 191*16467b97STreehugger Robot /** Pointer to the next exception in the chain (if any) 192*16467b97STreehugger Robot */ 193*16467b97STreehugger Robot struct ANTLR3_EXCEPTION_struct * nextException; 194*16467b97STreehugger Robot 195*16467b97STreehugger Robot /** Pointer to the input stream that this exception occurred in. 196*16467b97STreehugger Robot */ 197*16467b97STreehugger Robot pANTLR3_INT_STREAM input; 198*16467b97STreehugger Robot 199*16467b97STreehugger Robot /** Pointer for you, the programmer to add anything you like to an exception. 200*16467b97STreehugger Robot */ 201*16467b97STreehugger Robot void * custom; 202*16467b97STreehugger Robot 203*16467b97STreehugger Robot /** Pointer to a routine that is called to free the custom exception structure 204*16467b97STreehugger Robot * when the exception is destroyed. Set to NULL if nothing should be done. 205*16467b97STreehugger Robot */ 206*16467b97STreehugger Robot void (*freeCustom) (void * custom); 207*16467b97STreehugger Robot void (*print) (struct ANTLR3_EXCEPTION_struct * ex); 208*16467b97STreehugger Robot void (*freeEx) (struct ANTLR3_EXCEPTION_struct * ex); 209*16467b97STreehugger Robot 210*16467b97STreehugger Robot } 211*16467b97STreehugger Robot ANTLR3_EXCEPTION; 212*16467b97STreehugger Robot 213*16467b97STreehugger Robot #ifdef __cplusplus 214*16467b97STreehugger Robot } 215*16467b97STreehugger Robot #endif 216*16467b97STreehugger Robot 217*16467b97STreehugger Robot 218*16467b97STreehugger Robot #endif 219