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
111
112
113
114
115
116
117
118
119
120
|
/* ANTLR Translator Generator
* Project led by Terence Parr at http://www.jGuru.com
* Software rights: http://www.antlr.org/license.html
*
* $Id$
*/
#include "antlr/CharScanner.h"
#include "antlr/MismatchedCharException.h"
#include "antlr/String.h"
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
namespace antlr {
#endif
MismatchedCharException::MismatchedCharException()
: RecognitionException("Mismatched char")
{}
// Expected range / not range
MismatchedCharException::MismatchedCharException(
int c,
int lower,
int upper_,
bool matchNot,
CharScanner* scanner_
) : RecognitionException("Mismatched char",
scanner_->getFilename(),
scanner_->getLine(), scanner_->getColumn())
, mismatchType(matchNot ? NOT_RANGE : RANGE)
, foundChar(c)
, expecting(lower)
, upper(upper_)
, scanner(scanner_)
{
}
// Expected token / not token
MismatchedCharException::MismatchedCharException(
int c,
int expecting_,
bool matchNot,
CharScanner* scanner_
) : RecognitionException("Mismatched char",
scanner_->getFilename(),
scanner_->getLine(), scanner_->getColumn())
, mismatchType(matchNot ? NOT_CHAR : CHAR)
, foundChar(c)
, expecting(expecting_)
, scanner(scanner_)
{
}
// Expected BitSet / not BitSet
MismatchedCharException::MismatchedCharException(
int c,
BitSet set_,
bool matchNot,
CharScanner* scanner_
) : RecognitionException("Mismatched char",
scanner_->getFilename(),
scanner_->getLine(), scanner_->getColumn())
, mismatchType(matchNot ? NOT_SET : SET)
, foundChar(c)
, set(set_)
, scanner(scanner_)
{
}
ANTLR_USE_NAMESPACE(std)string MismatchedCharException::getMessage() const
{
ANTLR_USE_NAMESPACE(std)string s;
switch (mismatchType) {
case CHAR :
s += "expecting '" + charName(expecting) + "', found '" + charName(foundChar) + "'";
break;
case NOT_CHAR :
s += "expecting anything but '" + charName(expecting) + "'; got it anyway";
break;
case RANGE :
s += "expecting token in range: '" + charName(expecting) + "'..'" + charName(upper) + "', found '" + charName(foundChar) + "'";
break;
case NOT_RANGE :
s += "expecting token NOT in range: " + charName(expecting) + "'..'" + charName(upper) + "', found '" + 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 += charName(elems[i]);
s += "'";
}
s += "), found '" + charName(foundChar) + "'";
}
break;
default :
s += RecognitionException::getMessage();
break;
}
return s;
}
#ifndef NO_STATIC_CONSTS
const int MismatchedCharException::CHAR;
const int MismatchedCharException::NOT_CHAR;
const int MismatchedCharException::RANGE;
const int MismatchedCharException::NOT_RANGE;
const int MismatchedCharException::SET;
const int MismatchedCharException::NOT_SET;
#endif
#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
}
#endif
|