summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-04-23 13:22:42 -0400
committerAndreas Kling <kling@serenityos.org>2021-04-23 22:36:07 +0200
commite62e76ca1a346d6910cda96c3b585bffae7d0958 (patch)
treea48c42cd2dbdb8000f0a558f8b68f608ca6441da /Userland/Libraries/LibSQL
parent27685bc7993425e2ca02cf9497b648b9d9a2a453 (diff)
downloadserenity-e62e76ca1a346d6910cda96c3b585bffae7d0958.zip
LibSQL: Parse terminating semi-colon in top-level statement parser
Currently, every parse_*_statement method ends by parsing a semi-colon. This will prevent nested statements, e.g. a SELECT statement may be nested in a CREATE TABLE statement. Move the semi-colon expectation up and out of the individual statement parsers.
Diffstat (limited to 'Userland/Libraries/LibSQL')
-rw-r--r--Userland/Libraries/LibSQL/Parser.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/Userland/Libraries/LibSQL/Parser.cpp b/Userland/Libraries/LibSQL/Parser.cpp
index 4e8e813eb6..69b30e37ad 100644
--- a/Userland/Libraries/LibSQL/Parser.cpp
+++ b/Userland/Libraries/LibSQL/Parser.cpp
@@ -16,12 +16,17 @@ Parser::Parser(Lexer lexer)
NonnullRefPtr<Statement> Parser::next_statement()
{
+ auto terminate_statement = [this](auto statement) {
+ consume(TokenType::SemiColon);
+ return statement;
+ };
+
if (match(TokenType::With)) {
auto common_table_expression_list = parse_common_table_expression_list();
- return parse_statement_with_expression_list(move(common_table_expression_list));
+ return terminate_statement(parse_statement_with_expression_list(move(common_table_expression_list)));
}
- return parse_statement();
+ return terminate_statement(parse_statement());
}
NonnullRefPtr<Statement> Parser::parse_statement()
@@ -83,8 +88,6 @@ NonnullRefPtr<CreateTable> Parser::parse_create_table_statement()
// FIXME: Parse "table-constraint".
- consume(TokenType::SemiColon);
-
return create_ast_node<CreateTable>(move(schema_name), move(table_name), move(column_definitions), is_temporary, is_error_if_table_exists);
}
@@ -104,8 +107,6 @@ NonnullRefPtr<DropTable> Parser::parse_drop_table_statement()
String table_name;
parse_schema_and_table_name(schema_name, table_name);
- consume(TokenType::SemiColon);
-
return create_ast_node<DropTable>(move(schema_name), move(table_name), is_error_if_table_does_not_exist);
}
@@ -124,8 +125,6 @@ NonnullRefPtr<Delete> Parser::parse_delete_statement(RefPtr<CommonTableExpressio
if (match(TokenType::Returning))
returning_clause = parse_returning_clause();
- consume(TokenType::SemiColon);
-
return create_ast_node<Delete>(move(common_table_expression_list), move(qualified_table_name), move(where_clause), move(returning_clause));
}
@@ -192,8 +191,6 @@ NonnullRefPtr<Select> Parser::parse_select_statement(RefPtr<CommonTableExpressio
limit_clause = create_ast_node<LimitClause>(move(limit_expression), move(offset_expression));
}
- consume(TokenType::SemiColon);
-
return create_ast_node<Select>(move(common_table_expression_list), select_all, move(result_column_list), move(table_or_subquery_list), move(where_clause), move(group_by_clause), move(ordering_term_list), move(limit_clause));
}