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