1 #ifndef LOADER_TOKENIZER_H_
2 #define LOADER_TOKENIZER_H_
14 explicit Tokenizer(std::istream &in)
15 : in(in), line(1), isPutback(false), skipComments(true) { }
18 Tokenizer(const Tokenizer &);
19 Tokenizer &operator =(const Tokenizer &);
26 ANGLE_BRACKET_OPEN = '{',
27 ANGLE_BRACKET_CLOSE = '}',
34 PARENTHESIS_OPEN = '(',
35 PARENTHESIS_CLOSE = ')',
40 KEYWORD_INCLUDE = 'i',
51 Token() : type(UNKNOWN), number(0) { }
52 explicit Token(Type t) : type(t), number(0) { }
60 class LexerError: public std::runtime_error {
62 LexerError(int line, const std::string &msg)
63 : std::runtime_error(msg), line(line) { }
64 int Line() const { return line; }
72 void Putback(const Token &);
73 int Line() const { return line; }
81 Token ReadIdentifier();
84 Token ReadMultilineComment();
86 bool CheckKeyword(Token &);
97 inline const char *TokenTypeToString(Tokenizer::Token::Type t) {
99 case Tokenizer::Token::ANGLE_BRACKET_OPEN:
100 return "ANGLE_BRACKET_OPEN";
101 case Tokenizer::Token::ANGLE_BRACKET_CLOSE:
102 return "ANGLE_BRACKET_CLOSE";
103 case Tokenizer::Token::CHEVRON_OPEN:
104 return "CHEVRON_OPEN";
105 case Tokenizer::Token::CHEVRON_CLOSE:
106 return "CHEVRON_CLOSE";
107 case Tokenizer::Token::COLON:
109 case Tokenizer::Token::COMMA:
111 case Tokenizer::Token::COMMAND:
113 case Tokenizer::Token::BRACKET_OPEN:
114 return "BRACKET_OPEN";
115 case Tokenizer::Token::BRACKET_CLOSE:
116 return "BRACKET_CLOSE";
117 case Tokenizer::Token::PARENTHESIS_OPEN:
118 return "PARENTHESIS_OPEN";
119 case Tokenizer::Token::PARENTHESIS_CLOSE:
120 return "PARENTHESIS_CLOSE";
121 case Tokenizer::Token::NUMBER:
123 case Tokenizer::Token::REGISTER:
125 case Tokenizer::Token::SCRIPT_BEGIN:
126 return "SCRIPT_BEGIN";
127 case Tokenizer::Token::SCRIPT_END:
129 case Tokenizer::Token::STRING:
131 case Tokenizer::Token::KEYWORD_EXPORT:
132 return "KEYWORD_EXPORT";
133 case Tokenizer::Token::KEYWORD_FALSE:
134 return "KEYWORD_FALSE";
135 case Tokenizer::Token::KEYWORD_INCLUDE:
136 return "KEYWORD_INCLUDE";
137 case Tokenizer::Token::KEYWORD_TRUE:
138 return "KEYWORD_TRUE";
139 case Tokenizer::Token::IDENTIFIER:
141 case Tokenizer::Token::TYPE_NAME:
148 inline std::ostream &operator <<(std::ostream &out, Tokenizer::Token::Type t) {
149 out << TokenTypeToString(t);