Skip to content

Commit

Permalink
replaced annotations by keyword parameters in Box implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Mar 14, 2024
1 parent cb707e2 commit 469c4ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 47 deletions.
30 changes: 12 additions & 18 deletions src/org/rascalmpl/library/lang/box/util/Box.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
@contributor{Bert Lisser - [email protected] (CWI)}
module lang::box::util::Box


data Box
= H (list[Box] h)
| V(list[Box] v)
| HOV (list[Box] hov)
| HV (list[Box] hv)
| I(list[Box] i)
| WD(list[Box] wd)
data Box(int hs=-1, int vs=-1, int is=-1, int ts=-1, int width=-1, int height=-1)
= H (list[Box] h)
| V(list[Box] v)
| HOV (list[Box] hov)
| HV (list[Box] hv)
| I(list[Box] i)
| WD(list[Box] wd)
| R(list[Box] r)
| A(list[Box] a)
| A(list[Box] a)
| SPACE(int space)
| L(str l)
| KW(Box kw)
| VAR(Box var)
| L(str l)
| KW(Box kw)
| VAR(Box var)
| NM(Box nm)
| STRING(Box string)
| COMM(Box comm)
Expand All @@ -34,10 +33,5 @@ data Box

alias text = list[str];

anno int Box@hs;
anno int Box@vs;
anno int Box@is;
anno int Box@ts;
anno int Box@width;
anno int Box@height;


56 changes: 27 additions & 29 deletions src/org/rascalmpl/library/lang/box/util/Box2Text.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ alias foptions = map[str, list[str]];

map[Box, text] box2textmap=();


anno list[str] Box@format;

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

text vv(text a, text b) {
// if (!isEmpty(a) && isEmpty(a[0])) return b;
Expand Down Expand Up @@ -258,7 +256,7 @@ text II(list[Box] b, Box c, options opts, int m) {

text WDWD(list[Box] b, Box c ,options opts, int m) {
if (isEmpty(b)) return [];
int h= b[0]@hs?opts["h"];
int h= b[0].hs?opts["h"];
text t = O(b[0], c, opts, m);
int s = hwidth(t);
return hh(t , hh_(hskip(h) , WDWD(tail(b), c, opts, m-s-h)));
Expand Down Expand Up @@ -366,12 +364,12 @@ text O(Box b, Box c, options opts, int m) {
int h = opts["h"];
int v = opts["v"];
int i = opts["i"];
// if ((b@vs)?) println("Start:<getName(b)> <b@vs>");
if ((b@hs)?) {opts["h"] = b@hs;}
if ((b@vs)?) {opts["v"] = b@vs;}
if ((b@is)?) {opts["i"] = b@is;}
// if ((b.vs)?) println("Start:<getName(b)> <b.vs>");
if ((b.hs)?) {opts["h"] = b.hs;}
if ((b.vs)?) {opts["v"] = b.vs;}
if ((b.is)?) {opts["i"] = b.is;}
foptions f =();
if ((b@format)?) {f["f"] = b@format;}
if ((b.format)?) {f["f"] = b.format;}
text t = QQ(b, c, opts, f, m);
opts["h"]=h;
opts["v"]=v;
Expand All @@ -384,8 +382,8 @@ text O(Box b, Box c, options opts, int m) {

Box boxSize(Box b, Box c, options opts, int m) {
text s = O(b, c, opts, m);
b@width = twidth(s);
b@height = size(s);
b.width = twidth(s);
b.height = size(s);
return b;
}

Expand All @@ -396,15 +394,15 @@ list[list[Box]] RR(list[Box] bl, Box c, options opts, int m) {
}

int getMaxWidth(list[Box] b) {
return max([c@width| Box c <- b]);
return max([c.width| Box c <- b]);
}

list[int] Awidth(list[list[Box]] a) {
if (isEmpty(a)) return [];
int m = size(head(a)); // Rows have the same length
list[int] r = [];
for (int k<-[0..m]) {
r+=[max([b[k]@width|b<-a])];
r+=[max([b[k].width|b<-a])];
}
return r;
}
Expand All @@ -420,20 +418,20 @@ text AA(list[Box] bl, Box c ,options opts, foptions f, int m) {
list[str] format =format0;
list[Box] hargs = [];
for (Box b<- bl2) {
int width = b@width;
int width = b.width;
str f_str = !isEmpty(format)?head(format):"l";
if (!isEmpty(format)) format = tail(format);
max_width = head(mw);
mw=tail(mw);
int h= opts["h"];
switch(f_str) {
case "l": {
// b@hs=max_width - width+h; /*left alignment */
// b.hs=max_width - width+h; /*left alignment */
hargs+=b;
hargs += SPACE(max_width - width);
}
case "r": {
// b@hs=max_width - width+h; /*left alignment */
// b.hs=max_width - width+h; /*left alignment */
hargs += SPACE(max_width - width);
hargs+=b;
}
Expand Down Expand Up @@ -461,13 +459,13 @@ bool changeHV2H(list[Box] hv) {
Box removeHV(Box b) {
return innermost visit(b) {
case t:HV(list[Box] hv) => {
int h = (t@hs)?(-1);
int i = (t@is)?(-1);
int v = (t@vs)?(-1);
int h = (t.hs)?(-1);
int i = (t.is)?(-1);
int v = (t.vs)?(-1);
Box r = H(hv);
if (h>=0) r@hs = h;
if (i>=0) r@is = i;
if (v>=0) r@vs = v;
if (h>=0) r.hs = h;
if (i>=0) r.is = i;
if (v>=0) r.vs = v;
r;
}
when changeHV2H(hv)
Expand All @@ -477,13 +475,13 @@ return innermost visit(b) {
Box removeHOV(Box b) {
return innermost visit(b) {
case t:HOV(list[Box] hov) => {
int h = (t@hs)?(-1);
int i = (t@is)?(-1);
int v = (t@vs)?(-1);
int h = (t.hs)?(-1);
int i = (t.is)?(-1);
int v = (t.vs)?(-1);
Box r = changeHV2H(hov)?H(hov):V(hov);
if (h>=0) r@hs = h;
if (i>=0) r@is = i;
if (v>=0) r@vs = v;
if (h>=0) r.hs = h;
if (i>=0) r.is = i;
if (v>=0) r.vs = v;
// println("changed2");
r;
}
Expand Down Expand Up @@ -620,7 +618,7 @@ void tst() {
Box b2 = R([L("def"), L("hg")]);
Box b3 = R([L("ijkl"), L("m")]);
Box b = A([b1, b2, b3]);
b@format=["c","c"];
b.format=["c","c"];
}

public str baseName(str input) {
Expand Down

0 comments on commit 469c4ca

Please sign in to comment.