1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <antlr/config.hpp>
#include <antlr/RecognitionException.hpp>
#include <antlr/BitSet.hpp>
#include <antlr/String.hpp>
#include "MismatchedUnicodeCharException.hpp"
#include "UnicodeCharScanner.hpp"
MismatchedUnicodeCharException::MismatchedUnicodeCharException()
: RecognitionException("Mismatched char")
{
}
// Expected range / not range
MismatchedUnicodeCharException::MismatchedUnicodeCharException(
char_type c,
char_type lower,
char_type up,
bool matchNot,
UnicodeCharScanner* cs
)
: RecognitionException("Mismatched char",
cs->getFilename(),
cs->getLine(), cs->getColumn())
, mismatchType(matchNot ? NOT_RANGE : RANGE)
, foundChar(c)
, expecting(lower)
, upper(up)
, scanner(cs)
{
}
// Expected char / not char
MismatchedUnicodeCharException::MismatchedUnicodeCharException(
char_type c,
char_type expect,
bool matchNot,
UnicodeCharScanner* cs
) : RecognitionException("Mismatched char",
cs->getFilename(),
cs->getLine(), cs->getColumn())
, mismatchType(matchNot ? NOT_CHAR : CHAR)
, foundChar(c)
, expecting(expect)
, scanner(cs)
{
}
// Expected BitSet / not BitSet
MismatchedUnicodeCharException::MismatchedUnicodeCharException(
char_type c,
antlr::BitSet s,
bool matchNot,
UnicodeCharScanner* cs
) : RecognitionException("Mismatched char",
cs->getFilename(),
cs->getLine(), cs->getColumn())
, mismatchType(matchNot ? NOT_SET : SET)
, foundChar(c)
, set(s)
, scanner(cs)
{
}
MismatchedUnicodeCharException::~MismatchedUnicodeCharException() throw() {}
/**
* Returns a clean error message (no line number/column information)
*/
std::string MismatchedUnicodeCharException::getMessage() const
{
ANTLR_USE_NAMESPACE(std)string s;
switch (mismatchType) {
case CHAR :
s += "expecting '" + antlr::charName(expecting) + "', found '" + antlr::charName(foundChar) + "'";
break;
case NOT_CHAR :
s += "expecting anything but '" + antlr::charName(expecting) + "'; got it anyway";
break;
case RANGE :
s += "expecting token in range: '" + antlr::charName(expecting) + "'..'" + antlr::charName(upper) + "', found '" + antlr::charName(foundChar) + "'";
break;
case NOT_RANGE :
s += "expecting token NOT in range: " + antlr::charName(expecting) + "'..'" + antlr::charName(upper) + "', found '" + antlr::charName(foundChar) + "'";
break;
case SET :
case NOT_SET :
{
s += ANTLR_USE_NAMESPACE(std)string("expecting ") + (mismatchType == NOT_SET ? "NOT " : "") + "one of (";
ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray();
for ( unsigned int i = 0; i < elems.size(); i++ )
{
s += " '";
s += antlr::charName(elems[i]);
s += "'";
}
s += "), found '" + antlr::charName(foundChar) + "'";
}
break;
default :
s += RecognitionException::getMessage();
break;
}
return s;
}
|