From 1ab021561e7de94c345ecd40c37a24ad132b4dbe Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Wed, 29 Apr 2026 20:20:16 +0200 Subject: [PATCH] Fix bad test --- v0/parser.c | 60 ++++++++++++++++++++++++----- v0/tests/parser_bad_import_name.c2 | 1 + v0/tests/parser_bad_import_name.log | 6 +-- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/v0/parser.c b/v0/parser.c index 63f4b80..76b1aa7 100644 --- a/v0/parser.c +++ b/v0/parser.c @@ -34,7 +34,12 @@ static bool parser_accept(Parser* p, TokenType token) { } /** - * @copilot todo + * Consumes the expected token if present, otherwise logs an error. + * + * @param p The parser state. + * @param token The token type to expect. + * @param msg The error message if the token is not found. + * @return true if the token was consumed, false otherwise. */ static bool parser_expect(Parser* p, TokenType token, const char* msg) { if (parser_accept(p, token)) { @@ -45,7 +50,11 @@ static bool parser_expect(Parser* p, TokenType token, const char* msg) { } /** - * @copilot todo add docs + * Checks if the current token matches the expected token type without consuming it. + * + * @param p The parser state. + * @param token The token type to check. + * @return true if the current token matches, false otherwise. */ static bool parser_peek(Parser* p, TokenType token) { if (p->token.token == token) { @@ -55,7 +64,11 @@ static bool parser_peek(Parser* p, TokenType token) { } /** - * @copilot todo add docs + * Checks if the current token matches the expected token type without consuming it. + * + * @param p The parser state. + * @param token The token type to check. + * @return true if the current token matches, false otherwise. */ static bool parser_require(Parser* p, TokenType token, const char* msg) { if (parser_peek(p, token)) { @@ -66,8 +79,10 @@ static bool parser_require(Parser* p, TokenType token, const char* msg) { } /** - * Converts the current token to a string. - * @copilot add proper docs + * Returns the text of the current token and advances the parser to the next token. + * + * @param p The parser state. + * @return A newly allocated string containing the current token's text. */ static char* parser_to_text(Parser* p) { char* str = string_copy(p->token.text); @@ -92,7 +107,12 @@ static bool parse_module_declaration(Parser* p, Module* module) { } /** - * @copilot add docs + * Parses an import declaration. + * + * @param p The parser state. + * @param module The module to add the import to. + * @param is_public Whether the import is public. + * @return true if successful, false otherwise. */ static bool parse_import_declaration(Parser* p, Module* module, bool is_public) { module->import_count++; @@ -116,7 +136,12 @@ static bool parse_import_declaration(Parser* p, Module* module, bool is_public) } /** - * @copilot add docs + * Parses an import declaration. + * + * @param p The parser state. + * @param module The module to add the import to. + * @param is_public Whether the import is public. + * @return true if successful, false otherwise. */ static bool parse_primitive_type_expression(Parser* p, TypeExpression* expr) { if (parser_accept(p, TOKEN_U8)) { @@ -166,7 +191,12 @@ static bool parse_primitive_type_expression(Parser* p, TypeExpression* expr) { } /** - * @copilot add docs + * Parses an import declaration. + * + * @param p The parser state. + * @param module The module to add the import to. + * @param is_public Whether the import is public. + * @return true if successful, false otherwise. */ static bool parse_array_type_expression(Parser* p, TypeExpression* expr) { TypeExpression elementType; @@ -190,14 +220,24 @@ static bool parse_array_type_expression(Parser* p, TypeExpression* expr) { } /** - * @copilot add docs + * Parses an import declaration. + * + * @param p The parser state. + * @param module The module to add the import to. + * @param is_public Whether the import is public. + * @return true if successful, false otherwise. */ static bool parse_type_expression(Parser* p, TypeExpression* expr) { return parse_array_type_expression(p, expr); } /** - * @copilot add docs + * Parses an import declaration. + * + * @param p The parser state. + * @param module The module to add the import to. + * @param is_public Whether the import is public. + * @return true if successful, false otherwise. */ static bool parse_alias_declaration(Parser* p, Module* module, bool is_public) { module->alias_count++; diff --git a/v0/tests/parser_bad_import_name.c2 b/v0/tests/parser_bad_import_name.c2 index a260cbc..99b0adf 100644 --- a/v0/tests/parser_bad_import_name.c2 +++ b/v0/tests/parser_bad_import_name.c2 @@ -1 +1,2 @@ +module mymodule; import ; diff --git a/v0/tests/parser_bad_import_name.log b/v0/tests/parser_bad_import_name.log index da31571..4e0ef14 100644 --- a/v0/tests/parser_bad_import_name.log +++ b/v0/tests/parser_bad_import_name.log @@ -1,4 +1,4 @@ --- v0/tests/parser_bad_import_name.c2 --- -1| import ; - ^^^^^^ - expected keyword 'module' +2| import ; + ^ + expected module identifier