summaryrefslogtreecommitdiffstats
path: root/lib/antlr/antlr/MismatchedTokenException.h
blob: af3bdb8ce8ee510128b2e7c84c96f6768cf81a50 (plain)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef INC_MismatchedTokenException_h__
#define INC_MismatchedTokenException_h__

/* ANTLR Translator Generator
 * Project led by Terence Parr at http://www.jGuru.com
 * Software rights: http://www.antlr.org/license.html
 *
 * $Id$
 */

#include <antlr/config.h>
#include <antlr/RecognitionException.h>
#include <antlr/BitSet.h>
#include <antlr/Token.h>
#include <antlr/AST.h>
#include <vector>

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
namespace antlr {
#endif

class ANTLR_API MismatchedTokenException : public RecognitionException {
public:
	MismatchedTokenException();

	/// Expected range / not range
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefAST node_,
		int lower,
		int upper_,
		bool matchNot
	);

	// Expected token / not token
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefAST node_,
		int expecting_,
		bool matchNot
	);

	// Expected BitSet / not BitSet
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefAST node_,
		BitSet set_,
		bool matchNot
	);

	// Expected range / not range
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefToken token_,
		int lower,
		int upper_,
		bool matchNot,
		const ANTLR_USE_NAMESPACE(std)string& fileName_
	);

	// Expected token / not token
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefToken token_,
		int expecting_,
		bool matchNot,
		const ANTLR_USE_NAMESPACE(std)string& fileName_
	);

	// Expected BitSet / not BitSet
	MismatchedTokenException(
		const char* const* tokenNames_,
		const int numTokens_,
		RefToken token_,
		BitSet set_,
		bool matchNot,
		const ANTLR_USE_NAMESPACE(std)string& fileName_
	);
	~MismatchedTokenException() throw() {}

	/**
	 * Returns a clean error message (no line number/column information)
	 */
	ANTLR_USE_NAMESPACE(std)string getMessage() const;

public:
	/// The token that was encountered
	const RefToken token;
	/// The offending AST node if tree walking
	const RefAST node;
	/// taken from node or token object
	ANTLR_USE_NAMESPACE(std)string tokenText;

	/// Types of tokens
#ifndef NO_STATIC_CONSTS
	static const int TOKEN = 1;
	static const int NOT_TOKEN = 2;
	static const int RANGE = 3;
	static const int NOT_RANGE = 4;
	static const int SET = 5;
	static const int NOT_SET = 6;
#else
	enum {
		TOKEN = 1,
		NOT_TOKEN = 2,
		RANGE = 3,
		NOT_RANGE = 4,
		SET = 5,
		NOT_SET = 6
	};
#endif

public:
	/// One of the above
	int mismatchType;

	/// For TOKEN/NOT_TOKEN and RANGE/NOT_RANGE
	int expecting;

	/// For RANGE/NOT_RANGE (expecting is lower bound of range)
	int upper;

	/// For SET/NOT_SET
	BitSet set;

private:
	/// Token names array for formatting
	const char* const* tokenNames;
	/// Max number of tokens in tokenNames
	const int numTokens;
	/// Return token name for tokenType
	ANTLR_USE_NAMESPACE(std)string tokenName(int tokenType) const;
};

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
}
#endif

#endif //INC_MismatchedTokenException_h__