00001
00002
00003
00004
00005
00006
00007
00008
#include "antlr/MismatchedTokenException.hpp"
00009
#include "antlr/String.hpp"
00010
00011
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00012
namespace antlr {
00013
#endif
00014
00015 MismatchedTokenException::MismatchedTokenException()
00016 :
RecognitionException("Mismatched
Token: expecting any
AST node","<
AST>",-1,-1)
00017 , token(0)
00018 , node(
nullASTptr)
00019 , tokenNames(0)
00020 , numTokens(0)
00021 {
00022 }
00023
00024
00025 MismatchedTokenException::MismatchedTokenException(
00026
const char*
const* tokenNames_,
00027
const int numTokens_,
00028
RefAST node_,
00029
int lower,
00030
int upper_,
00031
bool matchNot
00032 ) :
RecognitionException("Mismatched
Token","<
AST>",-1,-1)
00033 , token(0)
00034 , node(node_)
00035 , tokenText( (node_ ? node_->toString():
ANTLR_USE_NAMESPACE(std)string("<
empty tree>")) )
00036 , mismatchType(matchNot ? NOT_RANGE : RANGE)
00037 , expecting(lower)
00038 , upper(upper_)
00039 , tokenNames(tokenNames_)
00040 , numTokens(numTokens_)
00041 {
00042 }
00043
00044
00045 MismatchedTokenException::MismatchedTokenException(
00046
const char*
const* tokenNames_,
00047
const int numTokens_,
00048
RefAST node_,
00049
int expecting_,
00050
bool matchNot
00051 ) :
RecognitionException("Mismatched
Token","<
AST>",-1,-1)
00052 , token(0)
00053 , node(node_)
00054 , tokenText( (node_ ? node_->toString():
ANTLR_USE_NAMESPACE(std)string("<
empty tree>")) )
00055 , mismatchType(matchNot ? NOT_TOKEN : TOKEN)
00056 , expecting(expecting_)
00057 , tokenNames(tokenNames_)
00058 , numTokens(numTokens_)
00059 {
00060 }
00061
00062
00063 MismatchedTokenException::MismatchedTokenException(
00064
const char*
const* tokenNames_,
00065
const int numTokens_,
00066
RefAST node_,
00067
BitSet set_,
00068
bool matchNot
00069 ) :
RecognitionException("Mismatched
Token","<
AST>",-1,-1)
00070 , token(0)
00071 , node(node_)
00072 , tokenText( (node_ ? node_->toString():
ANTLR_USE_NAMESPACE(std)string("<
empty tree>")) )
00073 , mismatchType(matchNot ? NOT_SET : SET)
00074 , set(set_)
00075 , tokenNames(tokenNames_)
00076 , numTokens(numTokens_)
00077 {
00078 }
00079
00080
00081 MismatchedTokenException::MismatchedTokenException(
00082
const char*
const* tokenNames_,
00083
const int numTokens_,
00084
RefToken token_,
00085
int lower,
00086
int upper_,
00087
bool matchNot,
00088
const ANTLR_USE_NAMESPACE(std)string& fileName_
00089 ) :
RecognitionException("Mismatched
Token",fileName_,token_->getLine(),token_->getColumn())
00090 , token(token_)
00091 , node(
nullASTptr)
00092 , tokenText(token_->getText())
00093 , mismatchType(matchNot ? NOT_RANGE : RANGE)
00094 , expecting(lower)
00095 , upper(upper_)
00096 , tokenNames(tokenNames_)
00097 , numTokens(numTokens_)
00098 {
00099 }
00100
00101
00102 MismatchedTokenException::MismatchedTokenException(
00103
const char*
const* tokenNames_,
00104
const int numTokens_,
00105
RefToken token_,
00106
int expecting_,
00107
bool matchNot,
00108
const ANTLR_USE_NAMESPACE(std)string& fileName_
00109 ) :
RecognitionException("Mismatched
Token",fileName_,token_->getLine(),token_->getColumn())
00110 , token(token_)
00111 , node(
nullASTptr)
00112 , tokenText(token_->getText())
00113 , mismatchType(matchNot ? NOT_TOKEN : TOKEN)
00114 , expecting(expecting_)
00115 , tokenNames(tokenNames_)
00116 , numTokens(numTokens_)
00117 {
00118 }
00119
00120
00121 MismatchedTokenException::MismatchedTokenException(
00122
const char*
const* tokenNames_,
00123
const int numTokens_,
00124
RefToken token_,
00125
BitSet set_,
00126
bool matchNot,
00127
const ANTLR_USE_NAMESPACE(std)string& fileName_
00128 ) :
RecognitionException("Mismatched
Token",fileName_,token_->getLine(),token_->getColumn())
00129 , token(token_)
00130 , node(
nullASTptr)
00131 , tokenText(token_->getText())
00132 , mismatchType(matchNot ? NOT_SET : SET)
00133 , set(set_)
00134 , tokenNames(tokenNames_)
00135 , numTokens(numTokens_)
00136 {
00137 }
00138
00139 ANTLR_USE_NAMESPACE(std)string
MismatchedTokenException::getMessage()
const
00140
{
00141
ANTLR_USE_NAMESPACE(std)string s;
00142
switch (mismatchType) {
00143
case TOKEN:
00144 s +=
"expecting " + tokenName(expecting) +
", found '" + tokenText +
"'";
00145
break;
00146
case NOT_TOKEN:
00147 s +=
"expecting anything but " + tokenName(expecting) +
"; got it anyway";
00148
break;
00149
case RANGE:
00150 s +=
"expecting token in range: " + tokenName(expecting) +
".." + tokenName(upper) +
", found '" + tokenText +
"'";
00151
break;
00152
case NOT_RANGE:
00153 s +=
"expecting token NOT in range: " + tokenName(expecting) +
".." + tokenName(upper) +
", found '" + tokenText +
"'";
00154
break;
00155
case SET:
00156
case NOT_SET:
00157 {
00158 s +=
ANTLR_USE_NAMESPACE(std)string(
"expecting ") + (mismatchType == NOT_SET ?
"NOT " :
"") +
"one of (";
00159
ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray();
00160
for (
unsigned int i = 0; i < elems.size(); i++ )
00161 {
00162 s +=
" ";
00163 s += tokenName(elems[i]);
00164 }
00165 s +=
"), found '" + tokenText +
"'";
00166 }
00167
break;
00168
default:
00169 s =
RecognitionException::getMessage();
00170
break;
00171 }
00172
return s;
00173 }
00174
00175 ANTLR_USE_NAMESPACE(std)string
MismatchedTokenException::tokenName(
int tokenType)
const
00176
{
00177
if (tokenType == Token::INVALID_TYPE)
00178
return "<Set of tokens>";
00179
else if (tokenType < 0 || tokenType >= numTokens)
00180
return ANTLR_USE_NAMESPACE(std)string(
"<") + tokenType +
">";
00181
else
00182
return tokenNames[tokenType];
00183 }
00184
00185
#ifndef NO_STATIC_CONSTS
00186 const int MismatchedTokenException::TOKEN;
00187 const int MismatchedTokenException::NOT_TOKEN;
00188 const int MismatchedTokenException::RANGE;
00189 const int MismatchedTokenException::NOT_RANGE;
00190 const int MismatchedTokenException::SET;
00191 const int MismatchedTokenException::NOT_SET;
00192
#endif
00193
00194
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00195
}
00196
#endif