fixes and improvements

exceptions related code needs work
This commit is contained in:
2021-07-22 23:57:42 +02:00
parent 977a9cd198
commit 6d4fe43a3b
15 changed files with 174 additions and 102 deletions

View File

@@ -65,11 +65,13 @@ namespace usql {
bool column_nullable{true};
// column name
if (m_lexer.tokenType() != TokenType::identifier) { /* TODO handle error */ }
if (m_lexer.tokenType() != TokenType::identifier) {
throw Exception("syntax error, expected identifier");
}
column_name = m_lexer.consumeCurrentToken().token_string;
// column type and optionally len
if (m_lexer.tokenType() == TokenType::keyword_int) {
if (m_lexer.tokenType() == TokenType::keyword_integer) {
column_type = ColumnType::integer_type;
m_lexer.nextToken();
} else if (m_lexer.tokenType() == TokenType::keyword_float) {
@@ -81,9 +83,13 @@ namespace usql {
m_lexer.skipToken(TokenType::open_paren);
if (m_lexer.tokenType() == TokenType::int_number) {
column_len = std::stoi(m_lexer.consumeCurrentToken().token_string);
} else { /* TODO handle error */ }
} else {
throw Exception("syntax error, expected int number");
}
m_lexer.skipToken(TokenType::close_paren);
} else { /* TODO handle error */ }
} else {
throw Exception("syntax error, column type expected");
}
if (m_lexer.tokenType() == TokenType::keyword_not) {
m_lexer.nextToken();
@@ -169,7 +175,7 @@ std::unique_ptr<Node> Parser::parse_value() {
return std::make_unique<ColNameNode>(name);
}
throw Exception("Syntax error");
throw Exception("Syntax error, current token: " + m_lexer.currentToken().token_string);
}
std::unique_ptr<Node> Parser::parse_select_from_table() {
@@ -326,6 +332,8 @@ std::unique_ptr<Node> Parser::parse_select_from_table() {
return std::make_unique<StringValueNode>(tokenString);
case TokenType::identifier:
return std::make_unique<DatabaseValueNode>(tokenString);
case TokenType::keyword_null:
return std::make_unique<NullValueNode>();
default:;
throw Exception("Unknown operand node");
}