6#include <unordered_map>
14static const std::unordered_map<Lexeme, TokenType> WORD_TO_TOKEN_TYPE{
15 {
"SELECT", TokenType::SELECT},
16 {
"PUT", TokenType::PUT},
17 {
"DELETE", TokenType::DELETE},
18 {
"CREATE", TokenType::CREATE},
19 {
"DROP", TokenType::DROP},
20 {
"ADD", TokenType::ADD},
21 {
"REMOVE", TokenType::REMOVE},
22 {
"TABLES", TokenType::TABLES},
23 {
"DATA", TokenType::DATA},
24 {
"AVG", TokenType::AVG},
25 {
"SUM", TokenType::SUM},
26 {
"COUNT", TokenType::COUNT},
27 {
"MIN", TokenType::MIN},
28 {
"MAX", TokenType::MAX},
29 {
"TABLE", TokenType::TABLE},
30 {
"TAGS", TokenType::TAGS},
31 {
"ALL", TokenType::ALL},
32 {
"BETWEEN", TokenType::BETWEEN},
33 {
"AND", TokenType::AND},
34 {
"AT", TokenType::AT},
35 {
"WHERE", TokenType::WHERE},
36 {
"FROM", TokenType::FROM},
37 {
"INTO", TokenType::INTO},
47 using size_type = uint64_t;
60 explicit Lexer(
const std::string& input)
noexcept;
109 [[nodiscard]]
bool is_whitespace(
char ch) const noexcept;
120 [[nodiscard]]
bool is_alpha(
char ch) const noexcept;
129 [[nodiscard]]
bool is_digit(
char ch) const noexcept;
138 [[nodiscard]]
bool is_alnum(
char ch) const noexcept;
147 [[nodiscard]]
bool chars_remaining() const noexcept;
156 [[nodiscard]]
char peek() const;
165 [[nodiscard]]
char peek_next() const;
182 template <
std::predicate<
char> Pred>
183 void advance_while(const Pred& pred) noexcept;
190 void lex_whitespace() noexcept;
198 [[nodiscard]]
Token lex_word() noexcept;
208 [[nodiscard]]
Token lex_number() noexcept;
215 void lex_comment() noexcept;
222 [[nodiscard]]
Token lex_equal() noexcept;
229 [[nodiscard]]
Token lex_comma() noexcept;
236 [[nodiscard]]
Token lex_semicolon() noexcept;
243 [[nodiscard]]
Token lex_unknown() noexcept;
250 [[nodiscard]]
Token lex_end_of_file() noexcept;
260 [[nodiscard]] Lexeme make_lexeme_from(size_type start) const;
269 [[nodiscard]]
Token make_token(
std::vector< Token > tokenize()
Tokenize the input string.
Lexer(Lexer &&) noexcept=default
Move-construct a new Lexer object.
Lexer()=delete
Deleted default constructor.