1 #ifndef INC_Token_hpp__
2 #define INC_Token_hpp__
3 
4 /* ANTLR Translator Generator
5  * Project led by Terence Parr at http://www.jGuru.com
6  * Software rights: http://www.antlr.org/license.html
7  *
8  * $Id: Token.hpp,v 1.1.1.1 2004-12-09 15:10:20 m_schellens Exp $
9  */
10 
11 #include <antlr/config.hpp>
12 #include <antlr/RefCount.hpp>
13 #include <string>
14 
15 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
16 namespace antlr {
17 #endif
18 
19 /** A token is minimally a token type.  Subclasses can add the text matched
20  *  for the token and line info.
21  */
22 
23 class ANTLR_API Token;
24 typedef RefCount<Token> RefToken;
25 
26 class ANTLR_API Token {
27 public:
28 	// constants
29 #ifndef NO_STATIC_CONSTS
30 	static const int MIN_USER_TYPE = 4;
31 	static const int NULL_TREE_LOOKAHEAD = 3;
32 	static const int INVALID_TYPE = 0;
33 	static const int EOF_TYPE = 1;
34 	static const int SKIP = -1;
35 #else
36 	enum {
37 		MIN_USER_TYPE = 4,
38 		NULL_TREE_LOOKAHEAD = 3,
39 		INVALID_TYPE = 0,
40 		EOF_TYPE = 1,
41 		SKIP = -1
42 	};
43 #endif
44 
45 	// each Token has at least a token type
46 	int type; //=INVALID_TYPE;
47 
48 public:
49 	// the illegal token object
50 	static RefToken badToken; // = new Token(INVALID_TYPE, "<no text>");
51 
52 	Token();
53 	Token(int t);
54 	Token(int t, const ANTLR_USE_NAMESPACE(std)string& txt);
55 
56 	virtual int getColumn() const;
57 	virtual int getLine() const;
58 	virtual ANTLR_USE_NAMESPACE(std)string getText() const;
59 	virtual int getType() const;
60 
61 	virtual void setColumn(int c);
62 
63 	virtual void setLine(int l);
64 	virtual void setText(const ANTLR_USE_NAMESPACE(std)string& t);
65 	virtual void setType(int t);
66 
67 	virtual ANTLR_USE_NAMESPACE(std)string toString() const;
68 
69 	virtual ~Token();
70 private:
71 	Token(const Token&);
72 	const Token& operator=(const Token&);
73 };
74 
75 extern ANTLR_API RefToken nullToken;
76 
77 #ifdef NEEDS_OPERATOR_LESS_THAN
78 // RK: Added after 2.7.2 previously it was undefined.
79 // AL: what to return if l and/or r point to nullToken???
operator <(RefToken l,RefToken r)80 inline bool operator<( RefToken l, RefToken r )
81 {
82 	return nullToken == l ? ( nullToken == r ? false : true ) : l->getType() < r->getType();
83 }
84 #endif
85 
86 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
87 }
88 #endif
89 
90 #endif //INC_Token_hpp__
91