164 Token(TokenType type, std::string lexeme, Location location)
165 : tok_type(type), lexeme(std::move(lexeme)), location(location) {}
166 bool is_comparison() {
167 return tok_type == TokLESS || tok_type == TokGreaterEqual ||
168 tok_type == TokLessEqual || tok_type == TokGREATER ||
169 tok_type == TokEQUAL;
171 bool is_logical() {
return tok_type == TokOR || tok_type == TokAND; }
172 Location get_location()
const {
return this->location; }
180 std::vector<std::shared_ptr<Token>> TokStream;
181 size_t current_index;
185 std::vector<std::shared_ptr<Token>> ErrStream;
187 TokenStream() : TokStream(), current_index(0), error(
false) {}
189 void push_back(
const std::shared_ptr<Token> &token) {
190 if (token->tok_type == TokINVALID) {
192 ErrStream.push_back(token);
194 TokStream.push_back(token);
198 bool hasErrors() {
return error; }
200 void push_back(
const Token &token) {
201 this->push_back(std::make_shared<Token>(token));
204 std::shared_ptr<Token> &exhaust_until(TokenType tokType) {
205 if (tokType == TokenType::TokEOF) {
206 current_index = TokStream.size() - 1;
207 return TokStream.back();
210 if (TokStream[current_index]->tok_type == tokType)
211 return TokStream[current_index++];
216 return TokStream.back();
219 bool isEnd() {
return current_index >= (TokStream.size() - 1); }
220 std::shared_ptr<Token> peek() {
return TokStream[current_index]; };
221 std::shared_ptr<Token> consume() {
223 current_index = std::min(TokStream.size() - 1, current_index + 1);
228 if (!TokStream.empty()) {
229 return TokStream[current_index]->get_location();