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:
24 explicit BasicParser(ITokenizer* tokenizer);
25 std::unique_ptr<Statement> parse(const std::string& query) override;
26 void setTokenizer(ITokenizer* tokenizer) override;
27
28 private:
29 ITokenizer* _tokenizer;
30 Token _currentToken;
31
32 void advance();
33 bool match(TokenType type);
34 bool matchKeyword(const std::string& keyword);
35 bool matchIdentifier(const std::string& identifier);
36 void expect(TokenType type, const std::string& errorMsg);
37 void expectKeyword(const std::string& keyword, const std::string& errorMsg);
38 void throwError(const std::string& message);
39
40 std::unique_ptr<Statement> parseStatement();
41 std::unique_ptr<SelectStatement> parseSelect();
42 std::unique_ptr<InsertStatement> parseInsert();
43 std::unique_ptr<UpdateStatement> parseUpdate();
44 std::unique_ptr<DeleteStatement> parseDelete();
45 std::unique_ptr<CreateStatement> parseCreate();
46 std::unique_ptr<DropStatement> parseDrop();
47 std::unique_ptr<ListStatement> parseList();
48
49 std::unique_ptr<Expression> parseExpression();
50 std::unique_ptr<Expression> parseComparison();
51 std::unique_ptr<Expression> parsePrimary();
52
53 std::unique_ptr<WhereClause> parseWhereClause();
54 };
55}
56
57#endif // QUERY_BASIC_PARSER_H
void setTokenizer(ITokenizer *tokenizer) override
Set the tokenizer to use.
Definition BasicParser.cpp:47
BasicParser()
Default constructor.
Definition BasicParser.cpp:8
std::unique_ptr< Statement > parse(const std::string &query) override
Parse a SQL query string.
Definition BasicParser.cpp:26
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
Token struct defined by type, value and pos.
Definition Token.h:31