some renamings
This commit is contained in:
61
parser.cpp
61
parser.cpp
@@ -106,9 +106,8 @@ namespace usql {
|
||||
|
||||
|
||||
std::unique_ptr<Node> Parser::parse_insert_into_table() {
|
||||
std::vector<Node> exec_code{};
|
||||
std::vector<ColNameNode> cols_names{};
|
||||
std::vector<std::unique_ptr<Node>> cols_values{};
|
||||
std::vector<ColNameNode> column_names{};
|
||||
std::vector<std::unique_ptr<Node>> column_values{};
|
||||
|
||||
m_lexer.skipToken(TokenType::keyword_insert);
|
||||
m_lexer.skipToken(TokenType::keyword_into);
|
||||
@@ -121,7 +120,7 @@ namespace usql {
|
||||
m_lexer.skipToken(TokenType::open_paren);
|
||||
do {
|
||||
if (m_lexer.tokenType() != TokenType::identifier) { /* TODO handle error */ }
|
||||
cols_names.push_back(m_lexer.consumeCurrentToken().token_string);
|
||||
column_names.push_back(m_lexer.consumeCurrentToken().token_string);
|
||||
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
} while (m_lexer.tokenType() != TokenType::close_paren);
|
||||
@@ -132,15 +131,14 @@ namespace usql {
|
||||
// column values
|
||||
m_lexer.skipToken(TokenType::open_paren);
|
||||
do {
|
||||
// cols_values.push_back(m_lexer.consumeCurrentToken().token_string);
|
||||
auto col_value = parse_value();
|
||||
cols_values.push_back(std::move(col_value));
|
||||
column_values.push_back(std::move(col_value));
|
||||
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
} while (m_lexer.tokenType() != TokenType::close_paren);
|
||||
m_lexer.skipToken(TokenType::close_paren);
|
||||
|
||||
return std::make_unique<InsertIntoTableNode>(table_name, cols_names, std::move(cols_values));
|
||||
return std::make_unique<InsertIntoTableNode>(table_name, column_names, std::move(column_values));
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> Parser::parse_value() {
|
||||
@@ -148,29 +146,29 @@ std::unique_ptr<Node> Parser::parse_value() {
|
||||
return std::make_unique<IntValueNode>(std::stoi(m_lexer.consumeCurrentToken().token_string));
|
||||
}
|
||||
if (m_lexer.tokenType() == TokenType::double_number) {
|
||||
return std::make_unique<FloatValueNode>(std::stof(m_lexer.consumeCurrentToken().token_string));
|
||||
return std::make_unique<DoubleValueNode>(std::stof(m_lexer.consumeCurrentToken().token_string));
|
||||
}
|
||||
if (m_lexer.tokenType() == TokenType::string_literal) {
|
||||
return std::make_unique<StringValueNode>(m_lexer.consumeCurrentToken().token_string);
|
||||
}
|
||||
if (m_lexer.tokenType() == TokenType::identifier && m_lexer.nextTokenType() == TokenType::open_paren) {
|
||||
// function
|
||||
std::string function_name = m_lexer.consumeCurrentToken().token_string;
|
||||
std::vector<std::unique_ptr<Node>> pars;
|
||||
|
||||
m_lexer.skipToken(TokenType::open_paren);
|
||||
while (m_lexer.tokenType() != TokenType::close_paren) { // TODO handle errors
|
||||
pars.push_back(parse_value());
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
}
|
||||
m_lexer.skipToken(TokenType::close_paren);
|
||||
return std::make_unique<FunctionNode>(function_name, std::move(pars));
|
||||
}
|
||||
if (m_lexer.tokenType() == TokenType::identifier) {
|
||||
std::string name = m_lexer.consumeCurrentToken().token_string;
|
||||
|
||||
// function
|
||||
if (m_lexer.tokenType() == TokenType::open_paren) {
|
||||
std::vector<std::unique_ptr<Node>> pars;
|
||||
|
||||
m_lexer.skipToken(TokenType::open_paren);
|
||||
while (m_lexer.tokenType() != TokenType::close_paren) { // TODO handle errors
|
||||
pars.push_back(parse_value());
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
}
|
||||
m_lexer.skipToken(TokenType::close_paren);
|
||||
return std::make_unique<FunctionNode>(name, std::move(pars));
|
||||
} else {
|
||||
return std::make_unique<ColNameNode>(name);
|
||||
}
|
||||
return std::make_unique<ColNameNode>(name);
|
||||
}
|
||||
|
||||
throw Exception("Syntax error");
|
||||
}
|
||||
|
||||
@@ -178,23 +176,26 @@ std::unique_ptr<Node> Parser::parse_select_from_table() {
|
||||
auto cols = std::make_unique<std::vector<SelectColNode>>();
|
||||
|
||||
m_lexer.skipToken(TokenType::keyword_select);
|
||||
|
||||
int i = 1;
|
||||
while (m_lexer.tokenType() != TokenType::keyword_from) {
|
||||
auto col_value = parse_value();
|
||||
std::string alias;
|
||||
if (col_value->node_type == NodeType::column_name) {
|
||||
alias = ((ColNameNode*) col_value.get())->name;
|
||||
auto column_value = parse_value();
|
||||
std::string column_alias;
|
||||
|
||||
if (column_value->node_type == NodeType::column_name) {
|
||||
column_alias = ((ColNameNode*) column_value.get())->name;
|
||||
} else {
|
||||
alias = "c" + std::to_string(i);
|
||||
column_alias = "c" + std::to_string(i);
|
||||
i++;
|
||||
}
|
||||
|
||||
cols->push_back(SelectColNode{std::move(col_value), alias});
|
||||
cols->push_back(SelectColNode{std::move(column_value), column_alias});
|
||||
|
||||
m_lexer.skipTokenOptional(TokenType::comma);
|
||||
}
|
||||
|
||||
m_lexer.skipToken(TokenType::keyword_from);
|
||||
|
||||
std::string table_name = m_lexer.consumeCurrentToken().token_string;
|
||||
|
||||
std::unique_ptr<Node> where_node = parse_where_clause();
|
||||
@@ -320,7 +321,7 @@ std::unique_ptr<Node> Parser::parse_select_from_table() {
|
||||
case TokenType::int_number:
|
||||
return std::make_unique<IntValueNode>(std::stoi(tokenString));
|
||||
case TokenType::double_number:
|
||||
return std::make_unique<FloatValueNode>(std::stod(tokenString));
|
||||
return std::make_unique<DoubleValueNode>(std::stod(tokenString));
|
||||
case TokenType::string_literal:
|
||||
return std::make_unique<StringValueNode>(tokenString);
|
||||
case TokenType::identifier:
|
||||
|
||||
Reference in New Issue
Block a user