//
// use core {package, *}
//
- b32 also_import_package;
+ b32 import_package_itself;
+
+ // Set to be the symbol that the package will
+ // be imported as. If NULL, the last token of
+ // the package path is used. The following
+ // imports the core package as C.
+ //
+ // use core { C :: package }
+ //
+ OnyxToken *qualified_package_name;
};
import_node->flags |= Ast_Flag_Comptime;
import_node->token = token;
import_node->imported_package = package_node;
- import_node->also_import_package = 1;
+ import_node->import_package_itself = 1;
if (consume_token_if_next(parser, '{')) {
import_node->specified_imports = 1;
- import_node->also_import_package = 0;
+ import_node->import_package_itself = 0;
- if (consume_token_if_next(parser, Token_Type_Keyword_Package)) {
- import_node->also_import_package = 1;
+ if (next_tokens_are(parser, 4, Token_Type_Symbol, ':', ':', Token_Type_Keyword_Package)) {
+ import_node->qualified_package_name = expect_token(parser, Token_Type_Symbol);
+ consume_tokens(parser, 3);
+
+ import_node->import_package_itself = 1;
+ if (parser->curr->type != '}')
+ expect_token(parser, ',');
+ }
+
+ else if (consume_token_if_next(parser, Token_Type_Keyword_Package)) {
+ import_node->import_package_itself = 1;
if (parser->curr->type != '}')
expect_token(parser, ',');
}
AstPackage* package = import->imported_package;
SYMRES(package, package);
- if (import->also_import_package) {
+ if (import->import_package_itself) {
+ OnyxToken *name = bh_arr_last(package->path);
+ name = import->qualified_package_name ?: name; // Had to find somewhere to use the Elvis operator in the codebase :)
+
symbol_introduce(
current_entity->scope,
- bh_arr_last(package->path),
+ name,
(AstNode *) package);
}