usql updated

This commit is contained in:
vaclavt
2022-02-17 20:42:30 +01:00
parent 765f2bc673
commit 7ad26ba427
7 changed files with 201 additions and 85 deletions

View File

@@ -5,6 +5,17 @@ namespace usql {
// TOOD handle premature eof
std::string column_type_name(const ColumnType type) {
if (type == ColumnType::integer_type) return "integer_type";
if (type == ColumnType::float_type) return "float_type";
if (type == ColumnType::varchar_type) return "varchar_type";
if (type == ColumnType::date_type) return "date_type";
if (type == ColumnType::bool_type) return "bool_type";
throw Exception("invalid column type: " + (int)type);
};
Parser::Parser() {
m_lexer = Lexer{};
}
@@ -433,39 +444,39 @@ namespace usql {
// function call
if (token_typcol == TokenType::identifier && m_lexer.nextTokenType() == TokenType::open_paren) {
std::string function_name = m_lexer.consumeToken(TokenType::identifier).token_string;
std::vector<std::unique_ptr<Node>> pars;
std::string function_name = m_lexer.consumeToken(TokenType::identifier).token_string;
std::vector<std::unique_ptr<Node>> pars;
m_lexer.skipToken(TokenType::open_paren);
while (m_lexer.tokenType() != TokenType::close_paren && m_lexer.tokenType() != TokenType::eof) {
pars.push_back(parse_expression());
m_lexer.skipTokenOptional(TokenType::comma);
}
m_lexer.skipToken(TokenType::close_paren);
return std::make_unique<FunctionNode>(function_name, std::move(pars));
m_lexer.skipToken(TokenType::open_paren);
while (m_lexer.tokenType() != TokenType::close_paren && m_lexer.tokenType() != TokenType::eof) {
pars.push_back(parse_expression());
m_lexer.skipTokenOptional(TokenType::comma);
}
m_lexer.skipToken(TokenType::close_paren);
return std::make_unique<FunctionNode>(function_name, std::move(pars));
}
// numbers and strings
std::string tokenString = m_lexer.consumeToken().token_string;
if (token_typcol == TokenType::int_number)
return std::make_unique<IntValueNode>(std::stoi(tokenString));
return std::make_unique<IntValueNode>(std::stoi(tokenString));
if (token_typcol == TokenType::double_number)
return std::make_unique<DoubleValueNode>(std::stod(tokenString));
return std::make_unique<DoubleValueNode>(std::stod(tokenString));
if (token_typcol == TokenType::string_literal)
return std::make_unique<StringValueNode>(tokenString);
return std::make_unique<StringValueNode>(tokenString);
// db column
if (token_typcol == TokenType::identifier)
return std::make_unique<DatabaseValueNode>(tokenString);
return std::make_unique<DatabaseValueNode>(tokenString);
// null
if (token_typcol == TokenType::keyword_null)
return std::make_unique<NullValueNode>();
return std::make_unique<NullValueNode>();
// true / false
if (token_typcol == TokenType::keyword_true || token_typcol == TokenType::keyword_false)
return std::make_unique<BooleanValueNode>(token_typcol == TokenType::keyword_true);
return std::make_unique<BooleanValueNode>(token_typcol == TokenType::keyword_true);
// token * for count(*)
if (token_typcol == TokenType::multiply)
@@ -529,4 +540,3 @@ namespace usql {
}
} // namespace