Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fallback-resolver-logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rodinaarssen committed Dec 16, 2024
2 parents 810c841 + 043b663 commit 65e6400
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/org/rascalmpl/library/util/Reflective.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,26 @@ int commonPrefix(list[str] rdir, list[str] rm){
@synopsis{Find the module name corresponding to a given module location via its (src or tpl) location}
str getModuleName(loc moduleLoc, PathConfig pcfg){
modulePath = moduleLoc.path;

rscFile = endsWith(modulePath, "rsc");
tplFile = endsWith(modulePath, "tpl");

if(!(endsWith(modulePath, "rsc") || endsWith(modulePath, "tpl"))){
if(!( rscFile || tplFile )){
throw "Not a Rascal .src or .tpl file: <moduleLoc>";
}

// Find matching .rsc file in source directories

for(loc dir <- pcfg.srcs){
if(moduleLoc.authority == dir.authority && startsWith(modulePath, dir.path)) {
moduleName = replaceFirst(modulePath, dir.path, "");
<moduleName, ext> = splitFileExtension(moduleName);
if(moduleName[0] == "/"){
moduleName = moduleName[1..];
}
moduleName = replaceAll(moduleName, "/", "::");
return moduleName;
if(rscFile){
for(loc dir <- pcfg.srcs){
if(moduleLoc.authority == dir.authority && startsWith(modulePath, dir.path)) {
moduleName = replaceFirst(modulePath, dir.path, "");
<moduleName, ext> = splitFileExtension(moduleName);
if(moduleName[0] == "/"){
moduleName = moduleName[1..];
}
moduleName = replaceAll(moduleName, "/", "::");
return moduleName;
}
}
}

Expand All @@ -204,6 +208,12 @@ str getModuleName(loc moduleLoc, PathConfig pcfg){
}

modulePathAsList = split("/", modulePathNoExt);
if(tplFile){
lastName = modulePathAsList[-1];
if(lastName[0] == "$"){
modulePathAsList = [*modulePathAsList[..-1],lastName[1..]];
}
}
if(modulePathAsList[0] == "rascal"){
modulePathAsList = modulePathAsList[1..];
}
Expand All @@ -226,6 +236,10 @@ str getModuleName(loc moduleLoc, PathConfig pcfg){
}

candidateAsList = split("/", candidate);
lastName = candidateAsList[-1];
if(lastName[0] == "$"){
candidateAsList = [*candidateAsList[..-1],lastName[1..]];
}
// println("cand: <candidateAsList>, modpath: <modulePathAsList>");
n = commonPrefix(reverse(candidateAsList), modulePathReversed);

Expand Down

0 comments on commit 65e6400

Please sign in to comment.