summaryrefslogtreecommitdiffstats
path: root/lib/antlr/antlr/Token.hpp
blob: cd56fc3c08599d704d7bb1914e0ec01575e5400a (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
#ifndef INC_Token_hpp__
#define INC_Token_hpp__

/* 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.hpp>
#include <antlr/TokenRefCount.hpp>
#include <string>

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
namespace antlr {
#endif

struct TokenRef;

/** A token is minimally a token type.  Subclasses can add the text matched
 *  for the token and line info.
 */
class ANTLR_API Token
{
public:
	// constants
#ifndef NO_STATIC_CONSTS
	static const int MIN_USER_TYPE = 4;
	static const int NULL_TREE_LOOKAHEAD = 3;
	static const int INVALID_TYPE = 0;
	static const int EOF_TYPE = 1;
	static const int SKIP = -1;
#else
	enum {
		MIN_USER_TYPE = 4,
		NULL_TREE_LOOKAHEAD = 3,
		INVALID_TYPE = 0,
		EOF_TYPE = 1,
		SKIP = -1
	};
#endif

	Token()
	: ref(0)
	, type(INVALID_TYPE)
	{
	}
	Token(int t)
	: ref(0)
	, type(t)
	{
	}
	Token(int t, const ANTLR_USE_NAMESPACE(std)string& txt)
	: ref(0)
	, type(t)
	{
		setText(txt);
	}
	virtual ~Token()
	{
	}

	virtual int getColumn() const;
	virtual int getLine() const;
	virtual ANTLR_USE_NAMESPACE(std)string getText() const;
	virtual const ANTLR_USE_NAMESPACE(std)string& getFilename() const;
	virtual int getType() const;

	virtual void setColumn(int c);

	virtual void setLine(int l);
	virtual void setText(const ANTLR_USE_NAMESPACE(std)string& t);
	virtual void setType(int t);

	virtual void setFilename( const std::string& file );

	virtual ANTLR_USE_NAMESPACE(std)string toString() const;

private:
	friend struct TokenRef;
	TokenRef* ref;

	int type; 							///< the type of the token

	Token(RefToken other);
	Token& operator=(const Token& other);
	Token& operator=(RefToken other);

	Token(const Token&);
};

extern ANTLR_API RefToken nullToken;

#ifdef NEEDS_OPERATOR_LESS_THAN
// RK: Added after 2.7.2 previously it was undefined.
// AL: what to return if l and/or r point to nullToken???
inline bool operator<( RefToken l, RefToken r )
{
	return nullToken == l ? ( nullToken == r ? false : true ) : l->getType() < r->getType();
}
#endif

#ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
}
#endif

#endif //INC_Token_hpp__