]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/MismatchedTokenException.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/MismatchedTokenException.cpp#2 $
8 #include "antlr/MismatchedTokenException.hpp"
9 #include "antlr/String.hpp"
11 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
15 MismatchedTokenException::MismatchedTokenException()
16 : RecognitionException("Mismatched Token: expecting any AST node","<AST>",-1,-1)
24 // Expected range / not range
25 MismatchedTokenException::MismatchedTokenException(
26 const char* const* tokenNames_
,
32 ) : RecognitionException("Mismatched Token","<AST>",-1,-1)
35 , tokenText( (node_
? node_
->toString(): ANTLR_USE_NAMESPACE(std
)string("<empty tree>")) )
36 , mismatchType(matchNot
? NOT_RANGE
: RANGE
)
39 , tokenNames(tokenNames_
)
40 , numTokens(numTokens_
)
44 // Expected token / not token
45 MismatchedTokenException::MismatchedTokenException(
46 const char* const* tokenNames_
,
51 ) : RecognitionException("Mismatched Token","<AST>",-1,-1)
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_
)
62 // Expected BitSet / not BitSet
63 MismatchedTokenException::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_
)
80 // Expected range / not range
81 MismatchedTokenException::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_
)
101 // Expected token / not token
102 MismatchedTokenException::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_
)
120 // Expected BitSet / not BitSet
121 MismatchedTokenException::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_
)
139 ANTLR_USE_NAMESPACE(std
)string
MismatchedTokenException::getMessage() const
141 ANTLR_USE_NAMESPACE(std
)string s
;
142 switch (mismatchType
) {
144 s
+= "expecting " + tokenName(expecting
) + ", found '" + tokenText
+ "'";
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
]);
165 s
+= "), found '" + tokenText
+ "'";
169 s
= RecognitionException::getMessage();
175 ANTLR_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
186 const int MismatchedTokenException::TOKEN
;
187 const int MismatchedTokenException::NOT_TOKEN
;
188 const int MismatchedTokenException::RANGE
;
189 const int MismatchedTokenException::NOT_RANGE
;
190 const int MismatchedTokenException::SET
;
191 const int MismatchedTokenException::NOT_SET
;
194 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE