ANTLR Support Libraries 2.7.1+
|
00001 #ifndef INC_Token_hpp__ 00002 #define INC_Token_hpp__ 00003 00004 /* ANTLR Translator Generator 00005 * Project led by Terence Parr at http://www.jGuru.com 00006 * Software rights: http://www.antlr.org/license.html 00007 * 00008 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/Token.hpp#2 $ 00009 */ 00010 00011 #include <antlr/config.hpp> 00012 #include <antlr/TokenRefCount.hpp> 00013 #include <string> 00014 00015 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00016 namespace antlr { 00017 #endif 00018 00019 struct TokenRef; 00020 00024 class ANTLR_API Token 00025 { 00026 public: 00027 // constants 00028 #ifndef NO_STATIC_CONSTS 00029 static const int MIN_USER_TYPE = 4; 00030 static const int NULL_TREE_LOOKAHEAD = 3; 00031 static const int INVALID_TYPE = 0; 00032 static const int EOF_TYPE = 1; 00033 static const int SKIP = -1; 00034 #else 00035 enum { 00036 MIN_USER_TYPE = 4, 00037 NULL_TREE_LOOKAHEAD = 3, 00038 INVALID_TYPE = 0, 00039 EOF_TYPE = 1, 00040 SKIP = -1 00041 }; 00042 #endif 00043 00044 Token() 00045 : ref(0) 00046 , type(INVALID_TYPE) 00047 { 00048 } 00049 Token(int t) 00050 : ref(0) 00051 , type(t) 00052 { 00053 } 00054 Token(int t, const ANTLR_USE_NAMESPACE(std)string& txt) 00055 : ref(0) 00056 , type(t) 00057 { 00058 setText(txt); 00059 } 00060 virtual ~Token() 00061 { 00062 } 00063 00064 virtual int getColumn() const; 00065 virtual int getLine() const; 00066 virtual ANTLR_USE_NAMESPACE(std)string getText() const; 00067 virtual const ANTLR_USE_NAMESPACE(std)string& getFilename() const; 00068 virtual int getType() const; 00069 00070 virtual void setColumn(int c); 00071 00072 virtual void setLine(int l); 00073 virtual void setText(const ANTLR_USE_NAMESPACE(std)string& t); 00074 virtual void setType(int t); 00075 00076 virtual void setFilename( const std::string& file ); 00077 00078 virtual ANTLR_USE_NAMESPACE(std)string toString() const; 00079 00080 private: 00081 friend struct TokenRef; 00082 TokenRef* ref; 00083 00084 int type; 00085 00086 Token(RefToken other); 00087 Token& operator=(const Token& other); 00088 Token& operator=(RefToken other); 00089 00090 Token(const Token&); 00091 }; 00092 00093 extern ANTLR_API RefToken nullToken; 00094 00095 #ifdef NEEDS_OPERATOR_LESS_THAN 00096 // RK: Added after 2.7.2 previously it was undefined. 00097 // AL: what to return if l and/or r point to nullToken??? 00098 inline bool operator<( RefToken l, RefToken r ) 00099 { 00100 return nullToken == l ? ( nullToken == r ? false : true ) : l->getType() < r->getType(); 00101 } 00102 #endif 00103 00104 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE 00105 } 00106 #endif 00107 00108 #endif //INC_Token_hpp__