Fix bad test

This commit is contained in:
2026-04-29 20:20:16 +02:00
parent f260e02efa
commit 1ab021561e
3 changed files with 54 additions and 13 deletions
+50 -10
View File
@@ -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++;
+1
View File
@@ -1 +1,2 @@
module mymodule;
import ;
+3 -3
View File
@@ -1,4 +1,4 @@
--- v0/tests/parser_bad_import_name.c2 ---
1| import ;
^^^^^^
expected keyword 'module'
2| import ;
^
expected module identifier