1 #ifndef INC_MismatchedTokenException_hpp__ 2 #define INC_MismatchedTokenException_hpp__ 3 4 /* ANTLR Translator Generator 5 * Project led by Terence Parr at http://www.jGuru.com 6 * Software rights: http://www.antlr.org/license.html 7 * 8 * $Id$ 9 */ 10 11 #include <antlr/config.hpp> 12 #include <antlr/RecognitionException.hpp> 13 #include <antlr/BitSet.hpp> 14 #include <antlr/Token.hpp> 15 #include <antlr/AST.hpp> 16 #include <vector> 17 18 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 19 namespace antlr { 20 #endif 21 22 class ANTLR_API MismatchedTokenException : public RecognitionException { 23 public: 24 MismatchedTokenException(); 25 26 /// Expected range / not range 27 MismatchedTokenException( 28 const char* const* tokenNames_, 29 const int numTokens_, 30 RefAST node_, 31 int lower, 32 int upper_, 33 bool matchNot 34 ); 35 36 // Expected token / not token 37 MismatchedTokenException( 38 const char* const* tokenNames_, 39 const int numTokens_, 40 RefAST node_, 41 int expecting_, 42 bool matchNot 43 ); 44 45 // Expected BitSet / not BitSet 46 MismatchedTokenException( 47 const char* const* tokenNames_, 48 const int numTokens_, 49 RefAST node_, 50 BitSet set_, 51 bool matchNot 52 ); 53 54 // Expected range / not range 55 MismatchedTokenException( 56 const char* const* tokenNames_, 57 const int numTokens_, 58 RefToken token_, 59 int lower, 60 int upper_, 61 bool matchNot, 62 const ANTLR_USE_NAMESPACE(std)string& fileName_ 63 ); 64 65 // Expected token / not token 66 MismatchedTokenException( 67 const char* const* tokenNames_, 68 const int numTokens_, 69 RefToken token_, 70 int expecting_, 71 bool matchNot, 72 const ANTLR_USE_NAMESPACE(std)string& fileName_ 73 ); 74 75 // Expected BitSet / not BitSet 76 MismatchedTokenException( 77 const char* const* tokenNames_, 78 const int numTokens_, 79 RefToken token_, 80 BitSet set_, 81 bool matchNot, 82 const ANTLR_USE_NAMESPACE(std)string& fileName_ 83 ); ~MismatchedTokenException()84 ~MismatchedTokenException() throw() {} 85 86 /** 87 * Returns a clean error message (no line number/column information) 88 */ 89 ANTLR_USE_NAMESPACE(std)string getMessage() const; 90 91 public: 92 /// The token that was encountered 93 const RefToken token; 94 /// The offending AST node if tree walking 95 const RefAST node; 96 /// taken from node or token object 97 ANTLR_USE_NAMESPACE(std)string tokenText; 98 99 /// Types of tokens 100 #ifndef NO_STATIC_CONSTS 101 static const int TOKEN = 1; 102 static const int NOT_TOKEN = 2; 103 static const int RANGE = 3; 104 static const int NOT_RANGE = 4; 105 static const int SET = 5; 106 static const int NOT_SET = 6; 107 #else 108 enum { 109 TOKEN = 1, 110 NOT_TOKEN = 2, 111 RANGE = 3, 112 NOT_RANGE = 4, 113 SET = 5, 114 NOT_SET = 6 115 }; 116 #endif 117 118 public: 119 /// One of the above 120 int mismatchType; 121 122 /// For TOKEN/NOT_TOKEN and RANGE/NOT_RANGE 123 int expecting; 124 125 /// For RANGE/NOT_RANGE (expecting is lower bound of range) 126 int upper; 127 128 /// For SET/NOT_SET 129 BitSet set; 130 131 private: 132 /// Token names array for formatting 133 const char* const* tokenNames; 134 /// Max number of tokens in tokenNames 135 const int numTokens; 136 /// Return token name for tokenType 137 ANTLR_USE_NAMESPACE(std)string tokenName(int tokenType) const; 138 }; 139 140 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 141 } 142 #endif 143 144 #endif //INC_MismatchedTokenException_hpp__ 145