Skip to content

Commit 68d5415

Browse files
committed
update to import parsing, efficient
1 parent 065b72e commit 68d5415

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

parser/statements/Import.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ ImportStatement* BasicParser::parseImportStmtAfterKw(ASTAllocator& allocator, bo
107107
stmt->setImportStmtKindDangerously(ImportStatementKind::LocalOrRemote);
108108
} else {
109109
// Handle 'from std' (identifier as source)
110-
std::vector<chem::string_view> pathParts;
111-
if (parseSymbolPath(*this, allocator, pathParts)) {
112-
// For simplicity, join parts back or store as string
113-
stmt->setSourcePath(pathParts[0]); // assuming single ID for native modules
110+
const auto path = consumeIdentifierOrKeyword();
111+
if(path) {
112+
stmt->setSourcePath(allocate_view(allocator, path->value));
113+
} else {
114+
unexpected_error("expected an identifier after the 'from'");
114115
}
115116
}
116117
}
@@ -125,18 +126,21 @@ ImportStatement* BasicParser::parseImportStmtAfterKw(ASTAllocator& allocator, bo
125126
if (parseSymbolPath(*this, allocator, primaryPath)) {
126127
// Check if this is "import symbol from source"
127128
if (consumeToken(TokenType::FromKw)) {
128-
ImportItem item;
129-
item.parts = std::move(primaryPath);
130-
stmt->addImportItem(std::move(item));
129+
stmt->addImportItem(ImportItem { .parts = std::move(primaryPath) });
131130

132131
auto source = parseString(allocator);
133132
if (source.has_value()) {
134133
stmt->setSourcePath(source.value());
135134
stmt->setImportStmtKindDangerously(ImportStatementKind::LocalOrRemote);
136135
}
137136
else {
138-
std::vector<chem::string_view> srcParts;
139-
if(parseSymbolPath(*this, allocator, srcParts)) stmt->setSourcePath(srcParts[0]);
137+
// Handle 'from std' (identifier as source)
138+
const auto path = consumeIdentifierOrKeyword();
139+
if(path) {
140+
stmt->setSourcePath(allocate_view(allocator, path->value));
141+
} else {
142+
unexpected_error("expected an identifier after the 'from'");
143+
}
140144
}
141145
} else {
142146
// It's just "import std" or "import std.sub"

0 commit comments

Comments
 (0)