source: trunk/yao/share/antlr-2.7.7/lib/cpp/antlr/Token.hpp

Last change on this file was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 2.2 KB
Line 
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
16namespace antlr {
17#endif
18
19struct TokenRef;
20
21/** A token is minimally a token type.  Subclasses can add the text matched
22 *  for the token and line info.
23 */
24class ANTLR_API Token
25{
26public:
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
44        Token()
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
80private:
81        friend struct TokenRef;
82        TokenRef* ref;
83
84        int type;                                                       ///< the type of the token
85
86        Token(RefToken other);
87        Token& operator=(const Token& other);
88        Token& operator=(RefToken other);
89
90        Token(const Token&);
91};
92
93extern ANTLR_API RefToken nullToken;
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???
98inline 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__
Note: See TracBrowser for help on using the repository browser.