a bit of further work

This commit is contained in:
2021-06-30 23:29:09 +02:00
parent 5c7908ac4b
commit b55115f7c3
10 changed files with 309 additions and 56 deletions

View File

@@ -15,7 +15,10 @@ enum class ColumnType {
enum class NodeType {
create_table,
insert_into,
select_from,
column_name,
column_value,
column_def,
not_implemented_yet,
error
@@ -27,14 +30,30 @@ struct Node {
Node(const NodeType type) : node_type(type) {}
};
struct ColNameNode : Node {
std::string name;
ColNameNode(const std::string col_name) :
Node(NodeType::column_name), name(col_name) {}
};
struct ColValueNode : Node {
std::string value;
ColValueNode(const std::string col_value) :
Node(NodeType::column_value), value(col_value) {}
};
// TODO add order in row
struct ColDefNode : Node {
std::string name;
ColumnType type;
int length;
int order;
int length;
bool null;
ColDefNode(const std::string col_name, const ColumnType col_type, int col_len, bool nullable) :
Node(NodeType::column_def), name(col_name), type(col_type), length(col_len), null(nullable) {}
ColDefNode(const std::string col_name, const ColumnType col_type, int col_order, int col_len, bool nullable) :
Node(NodeType::column_def), name(col_name), type(col_type), order(col_order), length(col_len), null(nullable) {}
};
struct CreateTableNode : Node {
@@ -45,6 +64,29 @@ struct CreateTableNode : Node {
Node(NodeType::create_table), table_name(name), cols_defs(defs) {}
};
struct InsertIntoTableNode : Node {
std::string table_name;
std::vector<ColNameNode> cols_names;
std::vector<ColValueNode> cols_values;
InsertIntoTableNode(const std::string name, std::vector<ColNameNode> names, std::vector<ColValueNode> values) :
Node(NodeType::insert_into), table_name(name), cols_names(names), cols_values(values) {}
};
struct SelectFromTableNode : Node {
std::string table_name;
std::vector<ColNameNode> cols_names;
std::vector<Node> where;
SelectFromTableNode(const std::string name, std::vector<ColNameNode> names, std::vector<Node> where_clause) :
Node(NodeType::select_from), table_name(name), cols_names(names), where(where_clause) {}
};
struct UpdateTableNode : Node { };
struct DeleteFromTableNode : Node { };
class Parser {
private:
@@ -56,7 +98,8 @@ public:
private:
std::unique_ptr<Node> parse_create_table();
std::unique_ptr<Node> parse_select();
std::unique_ptr<Node> parse_insert_into_table();
std::unique_ptr<Node> parse_select_from_table();
private:
Lexer lexer;