Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit

Permalink
Misc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed May 23, 2024
1 parent 7c7e3a8 commit d000987
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
15 changes: 6 additions & 9 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources">
<classpathentry excluding="target/generated-test-sources/test-annotations/" including="**/*.java" kind="src" output="target/test-classes" path="target/generated-test-sources">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/rascal"/>
<classpathentry kind="src" output="target/test-classes" path="test">
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="test">
<attributes>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
Expand All @@ -27,6 +29,7 @@
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/typepal"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Expand All @@ -35,17 +38,11 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="target/generated-test-resources">
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import IO;
import String;
import List;

@synopsis{Split the file extension from a path}
tuple[str,str] splitFileExtension(str path){
int n = findLast(path, ".");
if(n < 0) return <path, "">;
return <path[0 .. n], path[n+1 .. ]>;
}

@synopsis{Determine length of common suffix of list of strings}
int commonSuffix(list[str] dir, list[str] m)
= commonPrefix(reverse(dir), reverse(m));

@synopsis{Determine length of common prefix of list of strings}
int commonPrefix(list[str] rdir, list[str] rm){
for(int i <- index(rm)){
if(i >= size(rdir)){
Expand All @@ -29,18 +32,7 @@ int commonPrefix(list[str] rdir, list[str] rm){
return size(rm);
}

test bool commonSuffixCommutative(list[str] a, list[str] b) = commonSuffix(a, b) == commonSuffix(b, a);
test bool cs1() = commonSuffix([], ["c"]) == 0;

test bool cs2() = commonSuffix(["c"], ["c"]) == 1;

test bool cs3() = commonSuffix(["a", "b", "c"], ["c"]) == 1;

test bool cs4() = commonSuffix(["a", "b", "c"], ["b", "c"]) == 2;
test bool cs5() = commonSuffix(["a", "b", "c"], ["a", "b", "c"]) == 3;
test bool cs6() = commonSuffix(["a", "b", "c"], ["z", "a", "b", "c"]) == 3;
test bool cs7() = commonSuffix(["a", "b", "c"], ["a", "b", "d"]) == 0;

@synopsis{Find the module name corresponding with a give module location and PathConfig}
str getModuleNameNew(loc moduleLoc, PathConfig pcfg){
modulePath = moduleLoc.path;

Expand Down Expand Up @@ -83,7 +75,19 @@ str getModuleNameNew(loc moduleLoc, PathConfig pcfg){
}
throw "No module name found for <moduleLoc>;\nsrcs=<pcfg.srcs>;\nlibs=<pcfg.libs>";
}


test bool commonSuffixCommutative(list[str] a, list[str] b) = commonSuffix(a, b) == commonSuffix(b, a);
test bool cs1() = commonSuffix([], ["c"]) == 0;

test bool cs2() = commonSuffix(["c"], ["c"]) == 1;

test bool cs3() = commonSuffix(["a", "b", "c"], ["c"]) == 1;

test bool cs4() = commonSuffix(["a", "b", "c"], ["b", "c"]) == 2;
test bool cs5() = commonSuffix(["a", "b", "c"], ["a", "b", "c"]) == 3;
test bool cs6() = commonSuffix(["a", "b", "c"], ["z", "a", "b", "c"]) == 3;
test bool cs7() = commonSuffix(["a", "b", "c"], ["a", "b", "d"]) == 0;

test bool moduleExceptionWithAsSrc() {
pcfg = pathConfig(srcs=[|project://rascal/src/org/rascalmpl/library/|]);
return getModuleNameNew(|project://rascal/src/org/rascalmpl/library/Exception.rsc|, pcfg)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
module lang::rascalcore::compile::Examples::Tst6

data Content
= content(str id, str title=id)
;


@synopsis{Check the AST node specification on a (large) set of ASTs and monitor the progress.}
//bool astNodeSpecification(set[node] toCheck, str language = "java", bool checkNameResolution=false, bool checkSourceLocation=true)
// = job("AST specification checker", bool (void (str, int) step) {
// for (node ast <- toCheck) {
// step(loc l := ast.src ? l.path : "AST without src location", 1);
// if (!astNodeSpecification(ast, language=language, checkNameResolution=checkNameResolution, checkSourceLocation=checkSourceLocation)) {
// return false;
// }
// }
//
// return true;
// }, totalWork=size(toCheck));


void f(int n) {}


void g(str s, void(int) p) {}

bool h(bool b = false){
g("abc", void(int n){
f(b ? 10 : 20);
});
return true;
}

0 comments on commit d000987

Please sign in to comment.