mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improved error messages on incorrect module name. Issue #209
This commit is contained in:
@@ -241,6 +241,16 @@ static inline Path *parse_module_path(Context *context)
|
||||
const char *string = TOKSTR(context->tok);
|
||||
if (!try_consume(context, TOKEN_IDENT))
|
||||
{
|
||||
if (token_is_keyword(context->tok.type))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "The module path cannot contain a reserved keyword, try another name.");
|
||||
return false;
|
||||
}
|
||||
if (token_is_some_ident(context->tok.type))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "The elements of a module path must consist of only lower case letters, 0-9 and '_'.");
|
||||
return false;
|
||||
}
|
||||
SEMA_TOKEN_ERROR(context->tok, "Each '::' must be followed by a regular lower case sub module name.");
|
||||
return NULL;
|
||||
}
|
||||
@@ -338,7 +348,17 @@ bool parse_module(Context *context)
|
||||
|
||||
if (!TOKEN_IS(TOKEN_IDENT))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "Module statement should be followed by the name of the module.");
|
||||
if (token_is_keyword(context->tok.type))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "The module name cannot contain a reserved keyword, try another name.");
|
||||
return false;
|
||||
}
|
||||
if (token_is_some_ident(context->tok.type))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "The module name must consist of only lower case letters, 0-9 and '_'.");
|
||||
return false;
|
||||
}
|
||||
SEMA_TOKEN_ERROR(context->tok, "'module' should be followed by a module name.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#define CHECK_EXPR(_expr) do { if (!expr_ok(_expr)) return _expr; } while(0)
|
||||
|
||||
|
||||
#define COMMA_RPAREN_OR(_res) \
|
||||
do { if (!try_consume(context, TOKEN_COMMA) && !TOKEN_IS(TOKEN_RPAREN)) { \
|
||||
SEMA_TOKEN_ERROR(context->tok, "Expected ',' or ')'"); return _res; } } while(0)
|
||||
@@ -80,6 +79,26 @@ static inline bool expect(Context *context, TokenType token_type)
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool token_is_some_ident(TokenType token_type)
|
||||
{
|
||||
switch (token_type)
|
||||
{
|
||||
case TOKEN_TYPE_IDENT:
|
||||
case TOKEN_IDENT:
|
||||
case TOKEN_CONST_IDENT:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool token_is_keyword(TokenType token_type)
|
||||
{
|
||||
if (token_type >= TOKEN_VOID && token_type <= TOKEN_TYPEID) return true;
|
||||
if (token_type >= TOKEN_ALIAS && token_type <= TOKEN_WHILE) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool expect_ident(Context *context, const char* name)
|
||||
{
|
||||
switch (context->tok.type)
|
||||
|
||||
1
test/test_suite/module/module_bad_path_ident.c3
Normal file
1
test/test_suite/module/module_bad_path_ident.c3
Normal file
@@ -0,0 +1 @@
|
||||
module big::MONEY; // #error: The elements of a module path must consist of only lower
|
||||
1
test/test_suite/module/module_bad_path_invalid.c3
Normal file
1
test/test_suite/module/module_bad_path_invalid.c3
Normal file
@@ -0,0 +1 @@
|
||||
module abc::&&; // #error: Each '::' must be followed by a regular lower case sub module name
|
||||
1
test/test_suite/module/module_bad_path_keyword.c3
Normal file
1
test/test_suite/module/module_bad_path_keyword.c3
Normal file
@@ -0,0 +1 @@
|
||||
module abc::if::while; // #error: The module path cannot contain a reserved keyword, try another name
|
||||
1
test/test_suite/module/module_start_bad_ident.c3
Normal file
1
test/test_suite/module/module_start_bad_ident.c3
Normal file
@@ -0,0 +1 @@
|
||||
module BIG::MONEY; // #error: The module name must consist of only lower case letters
|
||||
1
test/test_suite/module/module_start_invalid.c3
Normal file
1
test/test_suite/module/module_start_invalid.c3
Normal file
@@ -0,0 +1 @@
|
||||
module &&; // #error: 'module' should be followed by a module name
|
||||
1
test/test_suite/module/module_start_keyword.c3
Normal file
1
test/test_suite/module/module_start_keyword.c3
Normal file
@@ -0,0 +1 @@
|
||||
module if::hello; // #error: The module name cannot contain a reserved keyword
|
||||
Reference in New Issue
Block a user