lib/antlr/src/MismatchedCharException.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
#include "antlr/CharScanner.hpp"
00009
#include "antlr/MismatchedCharException.hpp"
00010
#include "antlr/String.hpp"
00011
00012
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00013
namespace antlr {
00014
#endif
00015
00016 MismatchedCharException::MismatchedCharException()
00017 :
RecognitionException("Mismatched char")
00018 {}
00019
00020
00021 MismatchedCharException::MismatchedCharException(
00022
int c,
00023
int lower,
00024
int upper_,
00025
bool matchNot,
00026
CharScanner* scanner_
00027 ) :
RecognitionException("Mismatched char",
00028 scanner_->getFilename(),
00029 scanner_->getLine(), scanner_->getColumn())
00030 , mismatchType(matchNot ? NOT_RANGE : RANGE)
00031 , foundChar(c)
00032 , expecting(lower)
00033 , upper(upper_)
00034 , scanner(scanner_)
00035 {
00036 }
00037
00038
00039 MismatchedCharException::MismatchedCharException(
00040
int c,
00041
int expecting_,
00042
bool matchNot,
00043
CharScanner* scanner_
00044 ) :
RecognitionException("Mismatched char",
00045 scanner_->getFilename(),
00046 scanner_->getLine(), scanner_->getColumn())
00047 , mismatchType(matchNot ? NOT_CHAR : CHAR)
00048 , foundChar(c)
00049 , expecting(expecting_)
00050 , scanner(scanner_)
00051 {
00052 }
00053
00054
00055 MismatchedCharException::MismatchedCharException(
00056
int c,
00057
BitSet set_,
00058
bool matchNot,
00059
CharScanner* scanner_
00060 ) :
RecognitionException("Mismatched char",
00061 scanner_->getFilename(),
00062 scanner_->getLine(), scanner_->getColumn())
00063 , mismatchType(matchNot ? NOT_SET : SET)
00064 , foundChar(c)
00065 , set(set_)
00066 , scanner(scanner_)
00067 {
00068 }
00069
00070 ANTLR_USE_NAMESPACE(std)string
MismatchedCharException::getMessage()
const
00071
{
00072
ANTLR_USE_NAMESPACE(std)string s;
00073
00074
switch (mismatchType) {
00075
case CHAR :
00076 s +=
"expecting '" +
charName(expecting) +
"', found '" +
charName(foundChar) +
"'";
00077
break;
00078
case NOT_CHAR :
00079 s +=
"expecting anything but '" +
charName(expecting) +
"'; got it anyway";
00080
break;
00081
case RANGE :
00082 s +=
"expecting token in range: '" +
charName(expecting) +
"'..'" +
charName(upper) +
"', found '" +
charName(foundChar) +
"'";
00083
break;
00084
case NOT_RANGE :
00085 s +=
"expecting token NOT in range: " +
charName(expecting) +
"'..'" +
charName(upper) +
"', found '" +
charName(foundChar) +
"'";
00086
break;
00087
case SET :
00088
case NOT_SET :
00089 {
00090 s +=
ANTLR_USE_NAMESPACE(std)string(
"expecting ") + (mismatchType == NOT_SET ?
"NOT " :
"") +
"one of (";
00091
ANTLR_USE_NAMESPACE(std)vector<unsigned int> elems = set.toArray();
00092
for (
unsigned int i = 0; i < elems.size(); i++ )
00093 {
00094 s +=
" '";
00095 s +=
charName(elems[i]);
00096 s +=
"'";
00097 }
00098 s +=
"), found '" +
charName(foundChar) +
"'";
00099 }
00100
break;
00101
default :
00102 s +=
RecognitionException::getMessage();
00103
break;
00104 }
00105
00106
return s;
00107 }
00108
00109
#ifndef NO_STATIC_CONSTS
00110 const int MismatchedCharException::CHAR;
00111 const int MismatchedCharException::NOT_CHAR;
00112 const int MismatchedCharException::RANGE;
00113 const int MismatchedCharException::NOT_RANGE;
00114 const int MismatchedCharException::SET;
00115 const int MismatchedCharException::NOT_SET;
00116
#endif
00117
00118
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
00119
}
00120
#endif
This file is part of the documentation for KDevelop Version 3.0.4.