ANTLR Support Libraries 2.7.1+
Token.hpp
Go to the documentation of this file.
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: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/antlr/Token.hpp#2 $
9  */
10 
11 #include <antlr/config.hpp>
12 #include <antlr/TokenRefCount.hpp>
13 #include <string>
14 
15 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
16 namespace antlr {
17 #endif
18 
19 struct TokenRef;
20 
25 {
26 public:
27  // constants
28 #ifndef NO_STATIC_CONSTS
29  static const int MIN_USER_TYPE = 4;
30  static const int NULL_TREE_LOOKAHEAD = 3;
31  static const int INVALID_TYPE = 0;
32  static const int EOF_TYPE = 1;
33  static const int SKIP = -1;
34 #else
35  enum {
36  MIN_USER_TYPE = 4,
37  NULL_TREE_LOOKAHEAD = 3,
38  INVALID_TYPE = 0,
39  EOF_TYPE = 1,
40  SKIP = -1
41  };
42 #endif
43 
45  : ref(0)
46  , type(INVALID_TYPE)
47  {
48  }
49  Token(int t)
50  : ref(0)
51  , type(t)
52  {
53  }
54  Token(int t, const ANTLR_USE_NAMESPACE(std)string& txt)
55  : ref(0)
56  , type(t)
57  {
58  setText(txt);
59  }
60  virtual ~Token()
61  {
62  }
63 
64  virtual int getColumn() const;
65  virtual int getLine() const;
66  virtual ANTLR_USE_NAMESPACE(std)string getText() const;
67  virtual const ANTLR_USE_NAMESPACE(std)string& getFilename() const;
68  virtual int getType() const;
69 
70  virtual void setColumn(int c);
71 
72  virtual void setLine(int l);
73  virtual void setText(const ANTLR_USE_NAMESPACE(std)string& t);
74  virtual void setType(int t);
75 
76  virtual void setFilename( const std::string& file );
77 
78  virtual ANTLR_USE_NAMESPACE(std)string toString() const;
79 
80 private:
81  friend struct TokenRef;
83 
84  int type;
85 
86  Token(RefToken other);
87  Token& operator=(const Token& other);
88  Token& operator=(RefToken other);
89 
90  Token(const Token&);
91 };
92 
94 
95 #ifdef NEEDS_OPERATOR_LESS_THAN
96 // RK: Added after 2.7.2 previously it was undefined.
97 // AL: what to return if l and/or r point to nullToken???
98 inline bool operator<( RefToken l, RefToken r )
99 {
100  return nullToken == l ? ( nullToken == r ? false : true ) : l->getType() < r->getType();
101 }
102 #endif
103 
104 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
105 }
106 #endif
107 
108 #endif //INC_Token_hpp__
Definition: ANTLRException.hpp:15
Token(int t)
Definition: Token.hpp:49
RefToken nullToken
Definition: Token.cpp:68
#define ANTLR_API
Definition: config.hpp:22
Definition: TokenRefCount.hpp:19
TokenRef & operator=(const TokenRef &)
virtual ~Token()
Definition: Token.hpp:60
int type
the type of the token
Definition: Token.hpp:84
TokenRef * ref
Definition: Token.hpp:82
#define ANTLR_USE_NAMESPACE(_x_)
Definition: config.hpp:18
Definition: Token.hpp:24
Token(int t, const std ::string &txt)
Definition: Token.hpp:54
Token()
Definition: Token.hpp:44