Skip to content

Commit

Permalink
fixed typecheck errors in Box2Text and also some minor refactorigs
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Mar 27, 2024
1 parent e972eb3 commit b5cb5b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 72 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<exec.mainClass>org.rascalmpl.shell.RascalShell</exec.mainClass>
<rascal.test.memory>2</rascal.test.memory>
<maven.compiler.release>11</maven.compiler.release>
<rascal-maven.version>0.25.4-BOOT1</rascal-maven.version>
<rascal-maven.version>0.25.5-BOOT1</rascal-maven.version>
</properties>


Expand Down Expand Up @@ -118,7 +118,7 @@
<artifactId>rascal-maven-plugin</artifactId>
<version>${rascal-maven.version}</version>
<configuration>
<errorsAsWarnings>true</errorsAsWarnings> <!-- only allowed during intermediate bootstrap cycles -->
<errorsAsWarnings>false</errorsAsWarnings> <!-- only allowed during intermediate bootstrap cycles -->
<bin>${project.build.outputDirectory}</bin>
<srcs>
<src>${project.basedir}/src/org/rascalmpl/library</src>
Expand Down
107 changes: 38 additions & 69 deletions src/org/rascalmpl/library/lang/box/util/Box2Text.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -91,61 +91,34 @@ map[Box, text] box2textmap=();

data Box(list[str] format=[]);

text vv(text a, text b) {
// if (!isEmpty(a) && isEmpty(a[0])) return b;
// if (!isEmpty(b) && isEmpty(b[0])) return a;
return a+b;}

str blank(str a) {
return right("", width(a));
}

/* Computes a white line with the length of the last line of a */
text wd(text a) {
if (isEmpty(a)) return [];
if (size(a)==1) return [blank(a[0])];
return wd(tail(a));
}

/* Computes the length of unescaped string s */
int width(str s) {
s = replaceAll(s,"\r...","");
int b = size(s);
return b;
}


/* Computes the maximum width of text t */
int twidth(text t) {
if (isEmpty(t)) return 0;
return max([width(r)|str r <-t]);
}

/* Computes the length of the last line of t */
int hwidth(text t) {
if (isEmpty(t)) return 0;
return width(t[size(t)-1]);
}

/* Prepends str a before text b, all lines of b will be shifted */
text bar(str a, text b) {
if (isEmpty(b)) return [a];
return vv ([a+b[0]], prepend(blank(a), tail(b)));
}

/* produce text consisting of a white line of length n */
text hskip(int n) {
return [right("", n)];
}

/* produces a text consisting of n white lines at length 0 */
text vskip(int n) {
text r = [];
// println("OK<n>");
for (int _ <-[0, 1..n]) r=vv(r,[""]);
// println(size(r));
return r;
}
@synopsis{simple vertical concatenation (every list element is a line)}
text vv(text a, text b) = [*a, *b];

str blank(str a) = right("", width(a));

@synopsis{Computes a white line with the length of the last line of a}
text wd([]) = [];
text wd([*_, str x]) = wd([x]);

@synopsis{Computes the length of unescaped string s}
int width(str s) = size(s); // replaceAll(s,"\r...",""); ??

@synopsis{Computes the maximum width of text t}
int twidth(text t) = max([width(line) | line <- t]);

@synopsis{Computes the length of the last line of t}
int hwidth([]) = 0;
int hwidth([*_, str last]) = width(last);

@synopsis{Prepends str a before text b, all lines of b will be shifted}
text bar(str a, []) = [a];
text bar(str a, [str bh, *str bt]) = vv([a+bh], prepend(blank(a), bt));

@synopsis{Produce text consisting of a white line of length n}
text hskip(int n) = [right("", n)];

@synopsis{Produces text consisting of n white lines at length 0}
text vskip(int n) = ([] | vv(it, [""]) | _ <- [0..n]);


bool isBlank(str a) {return a==blank(a);}
Expand All @@ -154,21 +127,17 @@ text prepend(str a, text b) {
return [(a+c)|str c <- b];
}

text hh(text a, text b) {
if (isEmpty(a)) return b;
if (isEmpty(b)) return a;
if (size(a)==1) return bar(a[0], b);
str last = a[size(a)-1];
list[str] first = slice(a, 0, size(a)-1);
return vv(first, bar(last, b));
}
text hh([], text b) = b;
text hh(text a, []) = a;
text hh([a], text b) = bar(a, b);

text _hh(text a, text b) {
if (isEmpty(a)) return [];
return hh(a, b);
}
default text hh(text a, text b) = vv(a[0..-1], bar(a[-1], b));


text lhh([], text _) = [];
default text lhh(a, b) = hh(a, b);

text _vv(text a, text b) {
text lvv(text a, text b) {
if (isEmpty(a)) return [];
return vv(a, b);
}
Expand Down Expand Up @@ -290,7 +259,7 @@ text HVHV(text T, int s, text a, Box A, list[Box] B, options opts, int m) {
return vv(T, vv_(vskip(v), HVHV(T1, m-hwidth(T1), B, opts, m, H([]))));
}
if (n <= s) { // Box A fits in current line
return HVHV(hh(_hh(T, hskip(h)), a), s-n, B, opts, m, H([]));
return HVHV(hh(lhh(T, hskip(h)), a), s-n, B, opts, m, H([]));
}
else {
n -= h; // n == width(a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private Symbol denormalize(Symbol s) = visit (s) {
};

private Symbol removeConditionals(Symbol sym) = visit(sym) {
case conditional(s, _) => s
case conditional(Symbol s, _) => s
};

@synopsis{This is needed such that list variables can be repeatedly used as elements of the same list}
Expand Down

0 comments on commit b5cb5b9

Please sign in to comment.