Skip to content

Commit

Permalink
Merge pull request #3910 from alainmarcel/alainmarcel-patch-1
Browse files Browse the repository at this point in the history
module spec regexp
  • Loading branch information
alaindargelas authored Oct 17, 2023
2 parents 6b20406 + a418b11 commit ea57e33
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions src/SourceCompile/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,39 +211,41 @@ bool Compiler::ppinit_() {
fileSystem->collect(libFileId,
m_commandLineParser->getSymbolTable()->getSymbol(ext),
m_commandLineParser->getSymbolTable(), fileIds);
std::copy_if(
fileIds.begin(), fileIds.end(),
std::inserter(libFileIdSet, libFileIdSet.end()),
[&](const PathId& libFileId) {
if (sourceFiles.find(libFileId) == sourceFiles.end()) {
bool fileContainsModuleOfSameName = false;
std::filesystem::path dir_entry = fileSystem->toPath(libFileId);
std::ifstream ifs(dir_entry.string());
if (ifs.good()) {
std::stringstream buffer;
buffer << ifs.rdbuf();
std::string moduleName = dir_entry.stem().string();
const std::regex regexpMod{"(module)[ ]+(" + moduleName + ")"};
if (std::regex_search(buffer.str(), regexpMod)) {
fileContainsModuleOfSameName = true;
}
const std::regex regexpPrim{"(primitive)[ ]+(" + moduleName +
")"};
if (std::regex_search(buffer.str(), regexpPrim)) {
fileContainsModuleOfSameName = true;
}
const std::regex regexpPack{"(package)[ ]"};
if (std::regex_search(buffer.str(), regexpPack)) {
// Files containing packages cannot be imported with -y
fileContainsModuleOfSameName = false;
}
}
ifs.close();
return fileContainsModuleOfSameName;
} else {
return false;
}
});
std::copy_if(fileIds.begin(), fileIds.end(),
std::inserter(libFileIdSet, libFileIdSet.end()),
[&](const PathId& libFileId) {
if (sourceFiles.find(libFileId) == sourceFiles.end()) {
bool fileContainsModuleOfSameName = false;
std::filesystem::path dir_entry =
fileSystem->toPath(libFileId);
std::ifstream ifs(dir_entry.string());
if (ifs.good()) {
std::stringstream buffer;
buffer << ifs.rdbuf();
std::string moduleName = dir_entry.stem().string();
const std::regex regexpMod{"(module)[ \t]+(" +
moduleName + ")"};
if (std::regex_search(buffer.str(), regexpMod)) {
fileContainsModuleOfSameName = true;
}
const std::regex regexpPrim{"(primitive)[ \t]+(" +
moduleName + ")"};
if (std::regex_search(buffer.str(), regexpPrim)) {
fileContainsModuleOfSameName = true;
}
const std::regex regexpPack{"(package)[ \t]"};
if (std::regex_search(buffer.str(), regexpPack)) {
// Files containing packages cannot be imported with
// -y
fileContainsModuleOfSameName = false;
}
}
ifs.close();
return fileContainsModuleOfSameName;
} else {
return false;
}
});
}
}
for (const auto& libFileId : libFileIdSet) {
Expand Down

0 comments on commit ea57e33

Please sign in to comment.