xale-db 1.0
minimal SQL engine, written in c++
Loading...
Searching...
No Matches
BasicParser.h
Go to the documentation of this file.
1#ifndef QUERY_BASIC_PARSER_H
2#define QUERY_BASIC_PARSER_H
3
5#include "Query/IParser.h"
6#include "Query/ITokenizer.h"
7#include "Query/Token.h"
8#include "Query/Statement.h"
9
10#include <algorithm>
11#include <cctype>
12#include <memory>
13#include <string>
14
15namespace Xale::Query
16{
20 class BasicParser : public IParser
21 {
22 public:
27
32 explicit BasicParser(ITokenizer* tokenizer);
33
40 std::unique_ptr<Statement> parse(const std::string& query) override;
41
46 void setTokenizer(ITokenizer* tokenizer) override;
47
48 private:
49 ITokenizer* _tokenizer;
50 Token _currentToken;
51
55 void advance();
56
62 bool match(TokenType type);
63
69 bool matchKeyword(const std::string& keyword);
70
76 bool matchIdentifier(const std::string& identifier);
77
84 void expect(TokenType type, const std::string& errorMsg);
85
92 void expectKeyword(const std::string& keyword, const std::string& errorMsg);
93
99 void throwError(const std::string& message);
100
106 std::unique_ptr<Statement> parseStatement();
107
113 std::unique_ptr<SelectStatement> parseSelect();
114
120 std::unique_ptr<InsertStatement> parseInsert();
121
127 std::unique_ptr<UpdateStatement> parseUpdate();
128
134 std::unique_ptr<DeleteStatement> parseDelete();
135
141 std::unique_ptr<CreateStatement> parseCreate();
142
148 std::unique_ptr<DropStatement> parseDrop();
149
153 std::unique_ptr<ListStatement> parseList();
154
160 JoinClause parseJoinClause();
161
167 std::unique_ptr<Expression> parseExpression();
168
174 std::unique_ptr<Expression> parseComparison();
175
181 std::unique_ptr<Expression> parsePrimary();
182
188 std::unique_ptr<WhereClause> parseWhereClause();
189 };
190}
191
192#endif // QUERY_BASIC_PARSER_H
void setTokenizer(ITokenizer *tokenizer) override
Set the tokenizer to use.
Definition BasicParser.cpp:34
BasicParser()
Default constructor.
Definition BasicParser.cpp:5
std::unique_ptr< Statement > parse(const std::string &query) override
Parse a SQL query string.
Definition BasicParser.cpp:13
Interface for SQL parsers.
Definition IParser.h:16
Interface for SQL tokenizer that converts an input string into a sequence of tokens.
Definition ITokenizer.h:15
Definition BasicParser.h:16
TokenType
Types of possible tokens.
Definition Token.h:13
Represents a JOIN clause (INNER JOIN only for now).
Definition Statement.h:99
Token struct defined by type, value and pos.
Definition Token.h:32