4 * Created on: Aug 26, 2012
8 #ifndef LOADER_TOKENIZER_H_
9 #define LOADER_TOKENIZER_H_
21 explicit Tokenizer(std::istream &in)
22 : in(in), line(1), isPutback(false), skipComments(true) { }
25 Tokenizer(const Tokenizer &);
26 Tokenizer &operator =(const Tokenizer &);
33 ANGLE_BRACKET_OPEN = '{',
34 ANGLE_BRACKET_CLOSE = '}',
41 PARENTHESIS_OPEN = '(',
42 PARENTHESIS_CLOSE = ')',
47 KEYWORD_INCLUDE = 'i',
54 Token() : type(UNKNOWN), number(0) { }
55 explicit Token(Type t) : type(t), number(0) { }
63 class LexerError: public std::runtime_error {
65 LexerError(int line, const std::string &msg)
66 : std::runtime_error(msg), line(line) { }
67 int Line() const { return line; }
75 void Putback(const Token &);
76 int Line() const { return line; }
84 Token ReadIdentifier();
87 Token ReadMultilineComment();
89 bool CheckKeyword(Token &);
100 inline const char *TokenTypeToString(Tokenizer::Token::Type t) {
102 case Tokenizer::Token::ANGLE_BRACKET_OPEN:
103 return "ANGLE_BRACKET_OPEN";
104 case Tokenizer::Token::ANGLE_BRACKET_CLOSE:
105 return "ANGLE_BRACKET_CLOSE";
106 case Tokenizer::Token::CHEVRON_OPEN:
107 return "CHEVRON_OPEN";
108 case Tokenizer::Token::CHEVRON_CLOSE:
109 return "CHEVRON_CLOSE";
110 case Tokenizer::Token::COLON:
112 case Tokenizer::Token::COMMA:
114 case Tokenizer::Token::BRACKET_OPEN:
115 return "BRACKET_OPEN";
116 case Tokenizer::Token::BRACKET_CLOSE:
117 return "BRACKET_CLOSE";
118 case Tokenizer::Token::PARENTHESIS_OPEN:
119 return "PARENTHESIS_OPEN";
120 case Tokenizer::Token::PARENTHESIS_CLOSE:
121 return "PARENTHESIS_CLOSE";
122 case Tokenizer::Token::NUMBER:
124 case Tokenizer::Token::STRING:
126 case Tokenizer::Token::KEYWORD_EXPORT:
127 return "KEYWORD_EXPORT";
128 case Tokenizer::Token::KEYWORD_FALSE:
129 return "KEYWORD_FALSE";
130 case Tokenizer::Token::KEYWORD_INCLUDE:
131 return "KEYWORD_INCLUDE";
132 case Tokenizer::Token::KEYWORD_TRUE:
133 return "KEYWORD_TRUE";
134 case Tokenizer::Token::IDENTIFIER:
136 case Tokenizer::Token::TYPE_NAME:
143 inline std::ostream &operator <<(std::ostream &out, Tokenizer::Token::Type t) {
144 out << TokenTypeToString(t);
150 #endif /* LOADER_TOKENIZER_H_ */