@@ -13,66 +13,77 @@ namespace hk {
1313 }
1414 ++it;
1515
16- auto r = std::make_unique <ast::import_declaration_node>(first) ;
16+ auto r = std::unique_ptr <ast::import_declaration_node>{} ;
1717
1818 if (*it == " git" ) {
19- r->kind = ast::import_declaration_node::kind_type::git;
2019 ++it;
2120
21+ auto url = std::string{};
2222 if (*it == token::string_literal) {
23- r-> path = it->text ;
23+ url = it->text ;
2424 ++it;
2525 } else {
2626 return e.add <error::missing_import_git_declaration_url>(first, it->last );
2727 }
2828
29+ auto rev = std::string{};
2930 if (*it == token::string_literal) {
30- r-> branch = it->text ;
31+ rev = it->text ;
3132 ++it;
3233 } else {
3334 return e.add <error::missing_import_git_declaration_branch>(first, it->last );
3435 }
3536
37+ auto repository = repository_url{repository_type::git, std::move (url), std::move (rev)};
38+ r = std::make_unique<ast::import_repository_declaration_node>(first, it->last , std::move (repository));
39+
3640 } else if (*it == " zip" ) {
37- r->kind = ast::import_declaration_node::kind_type::zip;
3841 ++it;
3942
43+ auto url = std::string{};
4044 if (*it == token::string_literal) {
41- r-> path = it->text ;
45+ url = it->text ;
4246 ++it;
4347 } else {
4448 return e.add <error::missing_import_zip_declaration_path>(first, it->last );
4549 }
4650
51+ auto repository = repository_url{repository_type::zip, it->text };
52+ r = std::make_unique<ast::import_repository_declaration_node>(first, it->last , std::move (repository));
53+
4754 } else if (*it == " lib" ) {
48- r->kind = ast::import_declaration_node::kind_type::lib;
4955 ++it;
5056
57+ auto path = std::string{};
5158 if (*it == token::string_literal) {
52- r-> path = it->text ;
59+ path = it->text ;
5360 ++it;
5461 } else {
5562 return e.add <error::missing_import_lib_declaration_path>(first, it->last );
5663 }
5764
58- } else if ( auto fqname = parse_fqname (it, e)) {
59- r-> kind = ast::import_declaration_node::kind_type::mod;
60- r-> name = std::move (fqname). value ();
65+ r = std::make_unique<ast::import_library_declaration_node>(first, it-> last , path);
66+
67+ } else if ( auto name = parse_fqname (it, e)) {
6168 ++it;
6269
70+ auto as = hk::fqname{};
6371 if (*it == " as" ) {
6472 ++it;
6573
66- if (*it == token::string_literal ) {
67- r-> as = it-> text ;
74+ if (auto as = parse_fqname (it, e) ) {
75+ as = std::move (as). value () ;
6876
6977 } else {
7078 return e.add <error::missing_import_mod_declaration_as_name>(first, it->last );
7179 }
7280 }
7381
74- } else if (fqname.error ()) {
75- return std::unexpected{fqname.error ()};
82+ r = std::make_unique<ast::import_module_declaration_node>(first, it->last , std::move (name).value (), as);
83+
84+ } else if (name.error ()) {
85+ return std::unexpected{name.error ()};
86+
7687 } else {
7788 return e.add <error::missing_import_mod_declaration_name>(first, it->last );
7889 }
@@ -85,4 +96,4 @@ namespace hk {
8596 return e.add <error::missing_import_declaration_semicolon>(first, it->last );
8697}
8798
88- }
99+ } // namespace hk
0 commit comments