Skip to content

Commit

Permalink
Refined treatment of "char" when qualifier is present
Browse files Browse the repository at this point in the history
Closes #2003
  • Loading branch information
PaulKlint committed Oct 10, 2024
1 parent 301abcc commit cb5c81c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,21 @@ void collect(current: (Expression) `<Expression expression> ( <{Expression ","}*
}
return aloc();
}
if(isConstructorAType(texp) && getConstructorResultType(texp).adtName == "Tree" && "<expression>" == "char"){
nactuals = size(actuals);
if(nactuals != 1){
s.report(error(current, "`char` requires 1 argument, found %v", nactuals));
if(isConstructorAType(texp) && getConstructorResultType(texp).adtName == "Tree" && expression is qualifiedName){
<qualifier, base> = splitQualifiedName(expression.qualifiedName);
if (base == "char" && (isEmpty(qualifier) || qualifier == "Tree")){
nactuals = size(actuals);
if(nactuals != 1){
s.report(error(current, "`char` requires 1 argument, found %v", nactuals));
}
s.requireEqual(actuals[0], aint(), error(actuals[0], "Argument should be of type `int`, found %t", actuals[0]));
if(actuals[0] is literal){
chr = toInt("<actuals[0]>");
return \achar-class([arange(chr, chr)]);
} else
return anyCharType;
}
s.requireEqual(actuals[0], aint(), error(actuals[0], "Argument should be of type `int`, found %t", actuals[0]));
if(actuals[0] is literal){
chr = toInt("<actuals[0]>");
return \achar-class([arange(chr, chr)]);
} else
return anyCharType;
}
if(overloadedAType(rel[loc, IdRole, AType] overloads) := texp){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,69 +1,19 @@
module lang::rascalcore::compile::Examples::Tst4

import lang::rascalcore::check::Checker;
import lang::rascalcore::check::BasicRascalConfig;
import lang::rascalcore::check::RascalConfig;
import IO;
import Message;
import Map;
import util::FileSystem;
import util::Reflective;

tuple[PathConfig, RascalCompilerConfig] testConfigs(loc projectPath) {
pcfg = pathConfig(
bin=projectPath + "bin",
libs=[|home:///.m2/repository/org/rascalmpl/rascal/0.40.10/rascal-0.40.10.jar|],
srcs=[projectPath + "src"],
resources=projectPath + "resources",
generatedSources=projectPath + "generated-sources"
);

RascalCompilerConfig ccfg = rascalCompilerConfig(pcfg)
[forceCompilationTopModule = true]
[verbose = true];

return <pcfg, ccfg>;
}

ModuleStatus checkModule(loc projectPath, str moduleName, str moduleBody, RascalCompilerConfig ccfg) {
modulePath = projectPath + "src" + "<moduleName>.rsc";
writeFile(modulePath, moduleBody);
return rascalTModelForLocs([modulePath], ccfg, dummy_compile1);
}

void noTmodel(loc projectPath = |memory:///NoTModelTest|) {
remove(projectPath);
<pcfg, ccfg> = testConfigs(projectPath);

moduleName = "M";
moduleStr = "
'module <moduleName>
'
'void main() {
' int foo = x + y;
'}
";

if(ms := checkModule(projectPath, moduleName, moduleStr, ccfg)) {
if (size(ms.tmodels) > 0) { // This branch is expected to be taken
println("Success!");
} else { // This branch is taken instead
println("Failure...");
println("TModels: <ms.tmodels>");
}
} else {
println("checkModule failed");
}
}

// import ParseTree;
// import String;
import ParseTree;
import String;

// public str squeeze(str src, type[&CharClass <: ![]] _) = visit(src) {
// case /<c:.><c>+/ => c
// when &CharClass _ := Tree::char(charAt(c, 0))
// when &CharClass _ := char(charAt(c, 0))
// };

value main(){
![] x = Tree:: /* xxxx */ char(charAt("a", 0));
return x;
}

// void f(int n){
// [x | x <- [0..n], [x] := [x], x > 0];
// }
Expand Down

0 comments on commit cb5c81c

Please sign in to comment.