Skip to content

Commit

Permalink
Written first version of rascalSimilarNames
Browse files Browse the repository at this point in the history
rascalSimilarNames computes fixes for undefined names:
- unknown moduleId are inferred from the modules in srcs.
- other names are inferred by the default mechanism of TypePal.

Many extensions and refinements are possible here.
  • Loading branch information
PaulKlint committed Nov 25, 2024
1 parent 5841965 commit 2464dc1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
<dependency>
<groupId>org.rascalmpl</groupId>
<artifactId>typepal</artifactId>
<version>0.14.8</version>
<version>0.14.8-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.usethesource</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import lang::rascalcore::check::CheckerCommon;

import Location;
import util::Reflective;
import lang::rascalcore::compile::util::Names;

import IO;
import List;
Expand Down Expand Up @@ -459,6 +460,32 @@ loc rascalCreateLogicalLoc(Define def, str _modelName, PathConfig pcfg){
return def.defined;
}

list[str] rascalSimilarNames(Use u, TModel tm){
w = getOrgId(u);
nw = size(w);
idRoles = u.idRoles;
pcfg = tm.config.typepalPathConfig;
vocabulary = [];
longNames = {};
if(moduleId() in idRoles){
for(srcdir <- pcfg.srcs){
for(loc mloc <- find(srcdir, "rsc")){
try {
longName = getModuleName(mloc, pcfg);
shortName = asBaseModuleName(longName);
vocabulary += shortName;
longNames += <shortName, longName>;
} catch _: ;
}
}
} else {
vocabulary = [ d.orgId | d <- tm.defines, d.idRole in idRoles, isContainedIn(u.occ, d.scope) ];
}
//println("similarNames: <u>, <idRoles>, <vocabulary>");
similar = similarWords(w, vocabulary, tm.config.cutoffForNameSimilarity)[0..10];
return [ *(longNames[s]) | s <- similar ];
}

RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg,

str rascalTplVersion = getCurrentRascalTplVersion(),
Expand Down Expand Up @@ -523,5 +550,6 @@ RascalCompilerConfig rascalCompilerConfig(PathConfig pcfg,
preSolver = rascalPreSolver,
postSolver = rascalPostSolver,
reportUnused = rascalReportUnused,
createLogicalLoc = rascalCreateLogicalLoc
createLogicalLoc = rascalCreateLogicalLoc,
similarNames = rascalSimilarNames
);
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ str asBaseClassName(str qname){
return n >= 0 ? "$<qname[n+1 ..]>" : "$<qname>";
}

str asBaseModuleName(str qname){
n = findLast(qname, "::");
return n >= 0 ? qname[n+2 ..] : qname;
}

str asBaseInterfaceName(str qname){
qname = normalizeQName(qname);
n = findLast(qname, ".");
Expand Down

0 comments on commit 2464dc1

Please sign in to comment.