-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.cpp
More file actions
35 lines (29 loc) · 1.04 KB
/
Copy pathlexer.cpp
File metadata and controls
35 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "lexer.hpp"
void Lexer::lex(const std::string &input) {
std::regex re(Lexer::get_valid_regex(), std::regex::extended);
auto input_begin = std::sregex_iterator(input.begin(), input.end(), re);
auto input_end = std::sregex_iterator();
for (auto it = input_begin; it != input_end; ++it) {
size_t idx = 0;
for (; idx < it->size(); idx++) {
if (!it->str(idx + 1).empty()) {
break;
}
}
this->tokens.push_back(
make_pair(it->str(), Lexer::get_token_at_idx((int)idx)));
}
}
const bool Lexer::has_next_token() const noexcept {
return this->next_token_pos < (int) this->tokens.size();
}
const std::pair<std::string, Token> Lexer::get_prev_token() const noexcept {
return this->tokens[this->prev_token_pos];
}
const std::pair<std::string, Token> Lexer::get_curr_token() noexcept {
std::pair<std::string, Token> token = this->tokens[this->next_token_pos];
this->prev_token_pos = this->curr_token_pos;
this->curr_token_pos = this->next_token_pos;
this->next_token_pos++;
return std::move(token);
}