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 = '}',
40 PARENTHESIS_OPEN = '(',
41 PARENTHESIS_CLOSE = ')',
52 Token() : type(UNKNOWN), number(0) { }
53 explicit Token(Type t) : type(t), number(0) { }
61 class LexerError: public std::runtime_error {
63 explicit LexerError(const std::string &msg) : std::runtime_error(msg) { }
68 void Putback(const Token &);
75 Token ReadIdentifier();
77 bool CheckKeyword(Token &);
86 inline const char *TokenTypeToString(Tokenizer::Token::Type t) {
88 case Tokenizer::Token::ANGLE_BRACKET_OPEN:
89 return "ANGLE_BRACKET_OPEN";
90 case Tokenizer::Token::ANGLE_BRACKET_CLOSE:
91 return "ANGLE_BRACKET_CLOSE";
92 case Tokenizer::Token::CHEVRON_OPEN:
93 return "CHEVRON_OPEN";
94 case Tokenizer::Token::CHEVRON_CLOSE:
95 return "CHEVRON_CLOSE";
96 case Tokenizer::Token::COLON:
98 case Tokenizer::Token::COMMA:
100 case Tokenizer::Token::BRACKET_OPEN:
101 return "BRACKET_OPEN";
102 case Tokenizer::Token::BRACKET_CLOSE:
103 return "BRACKET_CLOSE";
104 case Tokenizer::Token::PARENTHESIS_OPEN:
105 return "PARENTHESIS_OPEN";
106 case Tokenizer::Token::PARENTHESIS_CLOSE:
107 return "PARENTHESIS_CLOSE";
108 case Tokenizer::Token::NUMBER:
110 case Tokenizer::Token::STRING:
112 case Tokenizer::Token::KEYWORD_EXPORT:
113 return "KEYWORD_EXPORT";
114 case Tokenizer::Token::KEYWORD_FALSE:
115 return "KEYWORD_FALSE";
116 case Tokenizer::Token::KEYWORD_INCLUDE:
117 return "KEYWORD_INCLUDE";
118 case Tokenizer::Token::KEYWORD_TRUE:
119 return "KEYWORD_TRUE";
120 case Tokenizer::Token::IDENTIFIER:
122 case Tokenizer::Token::TYPE_NAME:
129 inline std::ostream &operator <<(std::ostream &out, Tokenizer::Token::Type t) {
130 out << TokenTypeToString(t);
136 #endif /* LOADER_TOKENIZER_H_ */