4 * Created on: Aug 26, 2012
8 #ifndef LOADER_TOKENIZER_H_
9 #define LOADER_TOKENIZER_H_
21 explicit Tokenizer(std::istream &in) : in(in), isPutback(false) { }
24 Tokenizer(const Tokenizer &);
25 Tokenizer &operator =(const Tokenizer &);
32 ANGLE_BRACKET_OPEN = '{',
33 ANGLE_BRACKET_CLOSE = '}',
50 Token() : type(UNKNOWN), number(0) { }
51 explicit Token(Type t) : type(t), number(0) { }
59 class LexerError: public std::runtime_error {
61 explicit LexerError(const std::string &msg) : std::runtime_error(msg) { }
66 void Putback(const Token &);
73 Token ReadIdentifier();
75 bool CheckKeyword(Token &);
84 inline const char *TokenTypeToString(Tokenizer::Token::Type t) {
86 case Tokenizer::Token::ANGLE_BRACKET_OPEN:
87 return "ANGLE_BRACKET_OPEN";
88 case Tokenizer::Token::ANGLE_BRACKET_CLOSE:
89 return "ANGLE_BRACKET_CLOSE";
90 case Tokenizer::Token::CHEVRON_OPEN:
91 return "CHEVRON_OPEN";
92 case Tokenizer::Token::CHEVRON_CLOSE:
93 return "CHEVRON_CLOSE";
94 case Tokenizer::Token::COLON:
96 case Tokenizer::Token::COMMA:
98 case Tokenizer::Token::BRACKET_OPEN:
99 return "BRACKET_OPEN";
100 case Tokenizer::Token::BRACKET_CLOSE:
101 return "BRACKET_CLOSE";
102 case Tokenizer::Token::NUMBER:
104 case Tokenizer::Token::STRING:
106 case Tokenizer::Token::KEYWORD_EXPORT:
107 return "KEYWORD_EXPORT";
108 case Tokenizer::Token::KEYWORD_FALSE:
109 return "KEYWORD_FALSE";
110 case Tokenizer::Token::KEYWORD_INCLUDE:
111 return "KEYWORD_INCLUDE";
112 case Tokenizer::Token::KEYWORD_TRUE:
113 return "KEYWORD_TRUE";
114 case Tokenizer::Token::IDENTIFIER:
116 case Tokenizer::Token::TYPE_NAME:
123 inline std::ostream &operator <<(std::ostream &out, Tokenizer::Token::Type t) {
124 out << TokenTypeToString(t);
130 #endif /* LOADER_TOKENIZER_H_ */