8#include "antlr/MismatchedTokenException.hpp"
9#include "antlr/String.hpp"
11#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
15MismatchedTokenException::MismatchedTokenException()
16 : RecognitionException(
"Mismatched Token: expecting any AST node",
"<AST>",-1,-1)
25MismatchedTokenException::MismatchedTokenException(
26 const char*
const* tokenNames_,
35 , tokenText( (node_ ? node_->toString(): ANTLR_USE_NAMESPACE(std)string(
"<empty tree>")) )
36 , mismatchType(matchNot ? NOT_RANGE : RANGE)
39 , tokenNames(tokenNames_)
40 , numTokens(numTokens_)
45MismatchedTokenException::MismatchedTokenException(
46 const char*
const* tokenNames_,
54 , tokenText( (node_ ? node_->toString(): ANTLR_USE_NAMESPACE(std)string(
"<empty tree>")) )
55 , mismatchType(matchNot ? NOT_TOKEN : TOKEN)
56 , expecting(expecting_)
57 , tokenNames(tokenNames_)
58 , numTokens(numTokens_)
63MismatchedTokenException::MismatchedTokenException(
64 const char*
const* tokenNames_,
69) : RecognitionException(
"Mismatched Token",
"<AST>",-1,-1)
72 , tokenText( (node_ ? node_->toString(): ANTLR_USE_NAMESPACE(std)string(
"<empty tree>")) )
73 , mismatchType(matchNot ? NOT_SET : SET)
75 , tokenNames(tokenNames_)
76 , numTokens(numTokens_)
81MismatchedTokenException::MismatchedTokenException(
82 const char*
const* tokenNames_,
88 const ANTLR_USE_NAMESPACE(std)
string& fileName_
89) : RecognitionException(
"Mismatched Token",fileName_,token_->getLine(),token_->getColumn())
92 , tokenText(token_->getText())
93 , mismatchType(matchNot ? NOT_RANGE : RANGE)
96 , tokenNames(tokenNames_)
97 , numTokens(numTokens_)
102MismatchedTokenException::MismatchedTokenException(
103 const char*
const* tokenNames_,
104 const int numTokens_,
108 const ANTLR_USE_NAMESPACE(std)
string& fileName_
109) : RecognitionException(
"Mismatched Token",fileName_,token_->getLine(),token_->getColumn())
112 , tokenText(token_->getText())
113 , mismatchType(matchNot ? NOT_TOKEN : TOKEN)
114 , expecting(expecting_)
115 , tokenNames(tokenNames_)
116 , numTokens(numTokens_)
121MismatchedTokenException::MismatchedTokenException(
122 const char*
const* tokenNames_,
123 const int numTokens_,
127 const ANTLR_USE_NAMESPACE(std)
string& fileName_
128) : RecognitionException(
"Mismatched Token",fileName_,token_->getLine(),token_->getColumn())
131 , tokenText(token_->getText())
132 , mismatchType(matchNot ? NOT_SET : SET)
134 , tokenNames(tokenNames_)
135 , numTokens(numTokens_)
141 ANTLR_USE_NAMESPACE(std)
string s;
147 s +=
"expecting anything but " + tokenName(
expecting) +
"; got it anyway";
150 s +=
"expecting token in range: " + tokenName(
expecting) +
".." + tokenName(
upper) +
", found '" +
tokenText +
"'";
153 s +=
"expecting token NOT in range: " + tokenName(
expecting) +
".." + tokenName(
upper) +
", found '" +
tokenText +
"'";
158 s += ANTLR_USE_NAMESPACE(std)string(
"expecting ") + (
mismatchType == NOT_SET ?
"NOT " :
"") +
"one of (";
159 ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray();
160 for (
unsigned int i = 0; i < elems.size(); i++ )
163 s += tokenName(elems[i]);
175ANTLR_USE_NAMESPACE(std)
string MismatchedTokenException::tokenName(
int tokenType)
const
177 if (tokenType == Token::INVALID_TYPE)
178 return "<Set of tokens>";
179 else if (tokenType < 0 || tokenType >= numTokens)
180 return ANTLR_USE_NAMESPACE(std)string(
"<") + tokenType +
">";
182 return tokenNames[tokenType];
185#ifndef NO_STATIC_CONSTS
187const int MismatchedTokenException::NOT_TOKEN;
188const int MismatchedTokenException::RANGE;
189const int MismatchedTokenException::NOT_RANGE;
190const int MismatchedTokenException::SET;
191const int MismatchedTokenException::NOT_SET;
194#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
virtual std::string getMessage() const
Return error message without additional info (if present)
int mismatchType
One of the above.
int expecting
For TOKEN/NOT_TOKEN and RANGE/NOT_RANGE.
std::string tokenText
taken from node or token object
static const int TOKEN
Types of tokens.
std::string getMessage() const
Returns a clean error message (no line number/column information)
int upper
For RANGE/NOT_RANGE (expecting is lower bound of range)