int is long, select column can be function, some fixes..
just to get it work.. needs improvement
This commit is contained in:
73
parser.h
73
parser.h
@@ -8,7 +8,6 @@
|
||||
|
||||
namespace usql {
|
||||
|
||||
|
||||
enum class ColumnType {
|
||||
integer_type,
|
||||
float_type,
|
||||
@@ -31,6 +30,7 @@ namespace usql {
|
||||
delete_from,
|
||||
update_table,
|
||||
load_table,
|
||||
save_table,
|
||||
column_name,
|
||||
column_value,
|
||||
function,
|
||||
@@ -47,11 +47,17 @@ namespace usql {
|
||||
struct ColNameNode : Node {
|
||||
std::string name;
|
||||
|
||||
ColNameNode(const std::string col_name) :
|
||||
Node(NodeType::column_name), name(col_name) {}
|
||||
ColNameNode(const std::string col_name) : Node(NodeType::column_name), name(col_name) {}
|
||||
};
|
||||
|
||||
struct SelectColNode : Node {
|
||||
std::unique_ptr<Node> value;
|
||||
std::string name;
|
||||
|
||||
SelectColNode(std::unique_ptr<Node> column, const std::string alias) :
|
||||
Node(NodeType::column_name), value(std::move(column)), name(alias) {}
|
||||
};
|
||||
|
||||
// TODO add order in row
|
||||
struct ColDefNode : Node {
|
||||
std::string name;
|
||||
ColumnType type;
|
||||
@@ -79,24 +85,20 @@ namespace usql {
|
||||
struct ValueNode : Node {
|
||||
ValueNode(NodeType type) : Node(type) {}
|
||||
|
||||
virtual int getIntValue() = 0;
|
||||
|
||||
virtual long getIntValue() = 0;
|
||||
virtual double getDoubleValue() = 0;
|
||||
|
||||
virtual std::string getStringValue() = 0;
|
||||
|
||||
virtual ~ValueNode() {};
|
||||
};
|
||||
|
||||
struct IntValueNode : ValueNode {
|
||||
int value;
|
||||
long value;
|
||||
|
||||
IntValueNode(int value) : ValueNode(NodeType::int_value), value(value) {}
|
||||
|
||||
int getIntValue() { return value; };
|
||||
IntValueNode(long value) : ValueNode(NodeType::int_value), value(value) {}
|
||||
|
||||
long getIntValue() { return value; };
|
||||
double getDoubleValue() { return (double) value; };
|
||||
|
||||
std::string getStringValue() { return std::to_string(value); }
|
||||
};
|
||||
|
||||
@@ -105,10 +107,8 @@ namespace usql {
|
||||
|
||||
FloatValueNode(double value) : ValueNode(NodeType::float_value), value(value) {}
|
||||
|
||||
int getIntValue() { return (int) value; };
|
||||
|
||||
long getIntValue() { return (int) value; };
|
||||
double getDoubleValue() { return value; };
|
||||
|
||||
std::string getStringValue() { return std::to_string(value); }
|
||||
};
|
||||
|
||||
@@ -117,10 +117,8 @@ namespace usql {
|
||||
|
||||
StringValueNode(std::string value) : ValueNode(NodeType::string_value), value(value) {}
|
||||
|
||||
int getIntValue() { return std::stoi(value); };
|
||||
|
||||
long getIntValue() { return std::stoi(value); };
|
||||
double getDoubleValue() { return std::stod(value); };
|
||||
|
||||
std::string getStringValue() { return value; };
|
||||
};
|
||||
|
||||
@@ -183,7 +181,6 @@ namespace usql {
|
||||
Node(NodeType::arithmetical_operator), op(op), left(std::move(left)), right(std::move(right)) {};
|
||||
};
|
||||
|
||||
|
||||
struct CreateTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<ColDefNode> cols_defs;
|
||||
@@ -192,11 +189,10 @@ namespace usql {
|
||||
Node(NodeType::create_table), table_name(name), cols_defs(defs) {}
|
||||
};
|
||||
|
||||
|
||||
struct InsertIntoTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<ColNameNode> cols_names;
|
||||
std::vector<std::unique_ptr<Node>> cols_values;
|
||||
std::string table_name;
|
||||
std::vector<ColNameNode> cols_names;
|
||||
std::vector<std::unique_ptr<Node>> cols_values;
|
||||
|
||||
InsertIntoTableNode(const std::string name, std::vector<ColNameNode> names, std::vector<std::unique_ptr<Node>> values) :
|
||||
Node(NodeType::insert_into), table_name(name), cols_names(names), cols_values(std::move(values)) {}
|
||||
@@ -204,14 +200,13 @@ namespace usql {
|
||||
|
||||
struct SelectFromTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<ColNameNode> cols_names;
|
||||
std::unique_ptr<std::vector<SelectColNode>> cols_names;
|
||||
std::unique_ptr<Node> where;
|
||||
|
||||
SelectFromTableNode(std::string name, std::vector<ColNameNode> names, std::unique_ptr<Node> where_clause) :
|
||||
Node(NodeType::select_from), table_name(name), cols_names(names), where(std::move(where_clause)) {}
|
||||
SelectFromTableNode(std::string name, std::unique_ptr<std::vector<SelectColNode>> names, std::unique_ptr<Node> where_clause) :
|
||||
Node(NodeType::select_from), table_name(name), cols_names(std::move(names)), where(std::move(where_clause)) {}
|
||||
};
|
||||
|
||||
|
||||
struct CreateTableAsSelectNode : Node {
|
||||
std::string table_name;
|
||||
std::unique_ptr<Node> select_table;
|
||||
@@ -220,7 +215,6 @@ namespace usql {
|
||||
Node(NodeType::create_table_as_select), table_name(name), select_table(std::move(table)) {}
|
||||
};
|
||||
|
||||
|
||||
struct UpdateTableNode : Node {
|
||||
std::string table_name;
|
||||
std::vector<ColNameNode> cols_names;
|
||||
@@ -239,7 +233,14 @@ namespace usql {
|
||||
|
||||
LoadIntoTableNode(const std::string name, std::string file) :
|
||||
Node(NodeType::load_table), table_name(name), filename(file) {}
|
||||
};
|
||||
|
||||
struct SaveTableNode : Node {
|
||||
std::string table_name;
|
||||
std::string filename;
|
||||
|
||||
SaveTableNode(const std::string name, std::string file) :
|
||||
Node(NodeType::save_table), table_name(name), filename(file) {}
|
||||
};
|
||||
|
||||
struct DeleteFromTableNode : Node {
|
||||
@@ -248,7 +249,6 @@ namespace usql {
|
||||
|
||||
DeleteFromTableNode(const std::string name, std::unique_ptr<Node> where_clause) :
|
||||
Node(NodeType::delete_from), table_name(name), where(std::move(where_clause)) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -262,34 +262,23 @@ namespace usql {
|
||||
|
||||
private:
|
||||
std::unique_ptr<Node> parse_create_table();
|
||||
|
||||
std::unique_ptr<Node> parse_insert_into_table();
|
||||
|
||||
std::unique_ptr<Node> parse_value();
|
||||
|
||||
std::unique_ptr<Node> parse_select_from_table();
|
||||
|
||||
std::unique_ptr<Node> parse_delete_from_table();
|
||||
|
||||
std::unique_ptr<Node> parse_update_table();
|
||||
|
||||
std::unique_ptr<Node> parse_load_table();
|
||||
|
||||
std::unique_ptr<Node> parse_save_table();
|
||||
std::unique_ptr<Node> parse_where_clause();
|
||||
|
||||
std::unique_ptr<Node> parse_operand_node();
|
||||
|
||||
RelationalOperatorType parse_relational_operator();
|
||||
|
||||
LogicalOperatorType parse_logical_operator();
|
||||
|
||||
ArithmeticalOperatorType parse_arithmetical_operator();
|
||||
|
||||
private:
|
||||
Lexer lexer;
|
||||
Lexer m_lexer;
|
||||
|
||||
std::unique_ptr<Node> parse_relational_expression();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user