| 1 |
/* ANTLR Translator Generator |
| 2 |
* Project led by Terence Parr at http://www.jGuru.com |
| 3 |
* Software rights: http://www.antlr.org/license.html |
| 4 |
* |
| 5 |
* $Id: MismatchedCharException.cpp,v 1.1 2005-12-02 15:38:02 tim Exp $ |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "antlr/CharScanner.hpp" |
| 9 |
#include "antlr/MismatchedCharException.hpp" |
| 10 |
#include "antlr/String.hpp" |
| 11 |
|
| 12 |
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
| 13 |
namespace antlr { |
| 14 |
#endif |
| 15 |
|
| 16 |
MismatchedCharException::MismatchedCharException() |
| 17 |
: RecognitionException("Mismatched char") |
| 18 |
{} |
| 19 |
|
| 20 |
// Expected range / not range |
| 21 |
MismatchedCharException::MismatchedCharException( |
| 22 |
int c, |
| 23 |
int lower, |
| 24 |
int upper_, |
| 25 |
bool matchNot, |
| 26 |
CharScanner* scanner_ |
| 27 |
) : RecognitionException("Mismatched char", |
| 28 |
scanner_->getFilename(), |
| 29 |
scanner_->getLine(), scanner_->getColumn()) |
| 30 |
, mismatchType(matchNot ? NOT_RANGE : RANGE) |
| 31 |
, foundChar(c) |
| 32 |
, expecting(lower) |
| 33 |
, upper(upper_) |
| 34 |
, scanner(scanner_) |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
// Expected token / not token |
| 39 |
MismatchedCharException::MismatchedCharException( |
| 40 |
int c, |
| 41 |
int expecting_, |
| 42 |
bool matchNot, |
| 43 |
CharScanner* scanner_ |
| 44 |
) : RecognitionException("Mismatched char", |
| 45 |
scanner_->getFilename(), |
| 46 |
scanner_->getLine(), scanner_->getColumn()) |
| 47 |
, mismatchType(matchNot ? NOT_CHAR : CHAR) |
| 48 |
, foundChar(c) |
| 49 |
, expecting(expecting_) |
| 50 |
, scanner(scanner_) |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
// Expected BitSet / not BitSet |
| 55 |
MismatchedCharException::MismatchedCharException( |
| 56 |
int c, |
| 57 |
BitSet set_, |
| 58 |
bool matchNot, |
| 59 |
CharScanner* scanner_ |
| 60 |
) : RecognitionException("Mismatched char", |
| 61 |
scanner_->getFilename(), |
| 62 |
scanner_->getLine(), scanner_->getColumn()) |
| 63 |
, mismatchType(matchNot ? NOT_SET : SET) |
| 64 |
, foundChar(c) |
| 65 |
, set(set_) |
| 66 |
, scanner(scanner_) |
| 67 |
{ |
| 68 |
} |
| 69 |
|
| 70 |
ANTLR_USE_NAMESPACE(std)string MismatchedCharException::getMessage() const |
| 71 |
{ |
| 72 |
ANTLR_USE_NAMESPACE(std)string s; |
| 73 |
|
| 74 |
switch (mismatchType) { |
| 75 |
case CHAR : |
| 76 |
s += "expecting '" + charName(expecting) + "', found '" + charName(foundChar) + "'"; |
| 77 |
break; |
| 78 |
case NOT_CHAR : |
| 79 |
s += "expecting anything but '" + charName(expecting) + "'; got it anyway"; |
| 80 |
break; |
| 81 |
case RANGE : |
| 82 |
s += "expecting token in range: '" + charName(expecting) + "'..'" + charName(upper) + "', found '" + charName(foundChar) + "'"; |
| 83 |
break; |
| 84 |
case NOT_RANGE : |
| 85 |
s += "expecting token NOT in range: " + charName(expecting) + "'..'" + charName(upper) + "', found '" + charName(foundChar) + "'"; |
| 86 |
break; |
| 87 |
case SET : |
| 88 |
case NOT_SET : |
| 89 |
{ |
| 90 |
s += ANTLR_USE_NAMESPACE(std)string("expecting ") + (mismatchType == NOT_SET ? "NOT " : "") + "one of ("; |
| 91 |
ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray(); |
| 92 |
for ( unsigned int i = 0; i < elems.size(); i++ ) |
| 93 |
{ |
| 94 |
s += " '"; |
| 95 |
s += charName(elems[i]); |
| 96 |
s += "'"; |
| 97 |
} |
| 98 |
s += "), found '" + charName(foundChar) + "'"; |
| 99 |
} |
| 100 |
break; |
| 101 |
default : |
| 102 |
s += RecognitionException::getMessage(); |
| 103 |
break; |
| 104 |
} |
| 105 |
|
| 106 |
return s; |
| 107 |
} |
| 108 |
|
| 109 |
#ifndef NO_STATIC_CONSTS |
| 110 |
const int MismatchedCharException::CHAR; |
| 111 |
const int MismatchedCharException::NOT_CHAR; |
| 112 |
const int MismatchedCharException::RANGE; |
| 113 |
const int MismatchedCharException::NOT_RANGE; |
| 114 |
const int MismatchedCharException::SET; |
| 115 |
const int MismatchedCharException::NOT_SET; |
| 116 |
#endif |
| 117 |
|
| 118 |
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE |
| 119 |
} |
| 120 |
#endif |