From a418b11cbe5326d5500eb966246d8480680dd53b Mon Sep 17 00:00:00 2001 From: Alain Dargelas Date: Tue, 17 Oct 2023 14:32:52 -0700 Subject: [PATCH] module spec regexp --- src/SourceCompile/Compiler.cpp | 68 +++++++++++++++++----------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/SourceCompile/Compiler.cpp b/src/SourceCompile/Compiler.cpp index d49a734c0e..6d5dc04faf 100644 --- a/src/SourceCompile/Compiler.cpp +++ b/src/SourceCompile/Compiler.cpp @@ -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) {