awic compiles again.
[fail.git] / src / core / idlparser / token.h
blobf148a7245d2bc57f7c5ad0ee4aed76f13a91bd29
1 #ifndef AWFUL_IDLPARSE_TOKEN_H_
2 #define AWFUL_IDLPARSE_TOKEN_H_
4 #include <boost/wave.hpp>
5 #include <boost/wave/cpplexer/cpp_lex_token.hpp>
7 namespace awful { namespace idlparser
9 // Custom token types.
10 enum TokenType
12 TT_UNKNOWN,
13 TT_IDENTIFIER,
14 TT_STRING,
15 TT_POINTER,
16 TT_CONSTPOINTER,
17 TT_WEAKPOINTER,
18 TT_WEAKCONSTPOINTER,
19 TT_GENERICPOINTER,
20 TT_VECTOR,
21 TT_LIST,
22 TT_SET,
23 TT_MAP,
24 TT_UNORDERED_SET,
25 TT_UNORDERED_MAP,
26 TT_PAIR,
27 TT_SIGNAL,
28 TT_DYNAMICBUFFER,
30 TT_UINT8_T,
31 TT_INT8_T,
32 TT_UINT16_T,
33 TT_INT16_T,
34 TT_UINT32_T,
35 TT_INT32_T,
36 TT_UINT64_T,
37 TT_INT64_T
40 class TokenTransTable
42 public:
43 TokenTransTable();
44 static TokenType Translate( const char* pIdentifier_ );
46 private:
47 static TokenTransTable s_Instance;
48 std::map< std::string, TokenType > m_TransMap;
51 // This wraps a wave token. Like the wave token, it can be cast into token_id.
52 // It can also be cast into TokenTypes, which provides enums for custom keywords.
53 // Note that the cutsom keywords are of token_id T_IDENTIFIER, so the grammar shouldn't
54 // use T_IDENTIFIER but rather TT_IDENTIFIER from the TokenType enum above, which will
55 // designate tokens that are actual identifiers and not custom keywords originally recognized
56 // as T_IDENTIFIER by wave's cpplexer.
57 template< typename T > class Token
59 public:
60 Token()
64 Token( const T& InputTok_ )
66 *this = InputTok_;
69 const Token& operator=( const T& InputTok_ )
71 m_WrappedToken = InputTok_;
72 m_Type = TT_UNKNOWN;
74 if( m_WrappedToken == boost::wave::T_IDENTIFIER )
75 m_Type = TokenTransTable::Translate( m_WrappedToken.get_value().c_str() );
77 return *this;
80 operator boost::wave::token_id() const
82 return m_WrappedToken;
85 operator TokenType() const
87 return m_Type;
90 const typename T::string_type& get_value() const
92 return m_WrappedToken.get_value();
95 const typename T::position_type& get_position() const
97 return m_WrappedToken.get_position();
100 private:
101 T m_WrappedToken;
102 TokenType m_Type;
106 #endif