vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
token.h
1#ifndef QUERY_TOKEN_H
2#define QUERY_TOKEN_H
3
4#include <cstdint>
5#include <string>
6#include <unordered_map>
7#include <unordered_set>
8
9namespace vkdb {
14using Lexeme = std::string;
15
20enum class TokenType {
21 SELECT, PUT, DELETE, CREATE, DROP, ADD, REMOVE,
22 DATA, AVG, SUM, COUNT, MIN, MAX,
23 TABLE, TABLES, TAGS, ALL, BETWEEN, AND, AT, WHERE, FROM, INTO, TO,
24 EQUAL, COMMA, SEMICOLON,
25 IDENTIFIER, NUMBER,
26 END_OF_FILE, UNKNOWN
27};
28
33static const std::unordered_set<TokenType> QUERY_BASE_WORDS{
34 TokenType::SELECT, TokenType::PUT, TokenType::DELETE,
35 TokenType::CREATE, TokenType::DROP, TokenType::ADD, TokenType::REMOVE,
36 TokenType::TABLES
37};
38
43static const std::unordered_map<TokenType, std::string> TOKEN_TYPE_TO_STRING{
44 {TokenType::SELECT, "SELECT"},
45 {TokenType::PUT, "PUT"},
46 {TokenType::DELETE, "DELETE"},
47 {TokenType::CREATE, "CREATE"},
48 {TokenType::DROP, "DROP"},
49 {TokenType::ADD, "ADD"},
50 {TokenType::REMOVE, "REMOVE"},
51 {TokenType::TABLES, "TABLES"},
52 {TokenType::DATA, "DATA"},
53 {TokenType::AVG, "AVG"},
54 {TokenType::SUM, "SUM"},
55 {TokenType::COUNT, "COUNT"},
56 {TokenType::MIN, "MIN"},
57 {TokenType::MAX, "MAX"},
58 {TokenType::TABLE, "TABLE"},
59 {TokenType::TAGS, "TAGS"},
60 {TokenType::ALL, "ALL"},
61 {TokenType::BETWEEN, "BETWEEN"},
62 {TokenType::AND, "AND"},
63 {TokenType::AT, "AT"},
64 {TokenType::WHERE, "WHERE"},
65 {TokenType::FROM, "FROM"},
66 {TokenType::INTO, "INTO"},
67 {TokenType::TO, "TO"},
68 {TokenType::EQUAL, "EQUAL"},
69 {TokenType::COMMA, "COMMA"},
70 {TokenType::SEMICOLON, "SEMICOLON"},
71 {TokenType::IDENTIFIER, "IDENTIFIER"},
72 {TokenType::NUMBER, "NUMBER"},
73 {TokenType::END_OF_FILE, "END_OF_FILE"},
74 {TokenType::UNKNOWN, "UNKNOWN"}
75};
76
81class Token {
82public:
83 using size_type = uint64_t;
84
89 Token() = delete;
90
100 explicit Token(
101 TokenType type,
102 const Lexeme& lexeme,
103 size_type line,
104 size_type column
105 ) noexcept;
106
111 Token(Token&&) noexcept = default;
112
117 Token& operator=(Token&&) noexcept = default;
118
123 Token(const Token&) noexcept = default;
124
129 Token& operator=(const Token&) noexcept = default;
130
135 ~Token() noexcept = default;
136
144 [[nodiscard]] bool operator==(const Token& other) const noexcept;
145
151 [[nodiscard]] TokenType type() const noexcept;
152
158 [[nodiscard]] Lexeme lexeme() const noexcept;
159
165 [[nodiscard]] size_type line() const noexcept;
166
172 [[nodiscard]] size_type column() const noexcept;
173
179 [[nodiscard]] std::string str() const noexcept;
180
181private:
186 TokenType type_;
187
192 Lexeme lexeme_;
193
198 size_type line_;
199
204 size_type column_;
205};
206} // namespace vkdb
207
208#endif // QUERY_TOKEN_H
Represents a token.
Definition token.h:81
size_type column() const noexcept
Get the column number of the token.
Definition token.cpp:34
Token()=delete
Deleted default constructor.
Lexeme lexeme() const noexcept
Get the lexeme of the token.
Definition token.cpp:26
size_type line() const noexcept
Get the line number of the token.
Definition token.cpp:30
TokenType type() const noexcept
Get the type of the token.
Definition token.cpp:22
Token(Token &&) noexcept=default
Move-construct a Token object.
std::string str() const noexcept
Get the string representation of the token.
Definition token.cpp:38
STL namespace.