diff --git a/Userland/Libraries/LibSQL/Parser.cpp b/Userland/Libraries/LibSQL/Parser.cpp index 7ed51e7f7e6..7752a62e6ae 100644 --- a/Userland/Libraries/LibSQL/Parser.cpp +++ b/Userland/Libraries/LibSQL/Parser.cpp @@ -86,19 +86,10 @@ NonnullRefPtr Parser::parse_create_table_statement() // FIXME: Parse "AS select-stmt". NonnullRefPtrVector column_definitions; - consume(TokenType::ParenOpen); - do { - column_definitions.append(parse_column_definition()); - - if (match(TokenType::ParenClose)) - break; - - consume(TokenType::Comma); - } while (!match(TokenType::Eof)); + parse_comma_separated_list(true, [&]() { column_definitions.append(parse_column_definition()); }); // FIXME: Parse "table-constraint". - consume(TokenType::ParenClose); consume(TokenType::SemiColon); return create_ast_node(move(schema_name), move(table_name), move(column_definitions), is_temporary, is_error_if_table_exists); @@ -161,23 +152,12 @@ NonnullRefPtr Parser::parse_select_statement(RefPtr group_by_list; - do { - group_by_list.append(parse_expression()); - if (!match(TokenType::Comma)) - break; - consume(TokenType::Comma); - } while (!match(TokenType::Eof)); + parse_comma_separated_list(false, [&]() { group_by_list.append(parse_expression()); }); - RefPtr having_clause; - if (consume_if(TokenType::Having)) - having_clause = parse_expression(); + if (!group_by_list.is_empty()) { + RefPtr having_clause; + if (consume_if(TokenType::Having)) + having_clause = parse_expression(); - group_by_clause = create_ast_node(move(group_by_list), move(having_clause)); + group_by_clause = create_ast_node(move(group_by_list), move(having_clause)); + } } // FIXME: Parse 'WINDOW window-name AS window-defn'. @@ -209,13 +186,7 @@ NonnullRefPtr