diff --git a/src/org/rascalmpl/library/lang/box/util/Box2Text.rsc b/src/org/rascalmpl/library/lang/box/util/Box2Text.rsc index 1f663f9df61..4eac5aba5a8 100644 --- a/src/org/rascalmpl/library/lang/box/util/Box2Text.rsc +++ b/src/org/rascalmpl/library/lang/box/util/Box2Text.rsc @@ -120,67 +120,62 @@ 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]); +@synopsis{Check if a string already consists of only blanks.} +bool isBlank(str a) = (a == blank(a)); -bool isBlank(str a) {return a==blank(a);} - -text prepend(str a, text b) { - return [(a+c)|str c <- b]; -} +@synopsis{Prepend Every line in b with `a`} +text prepend(str a, text b) = ["" | line <- b]; +@synopsis{Implements horizontal concatenation, also for multiple lines} text hh([], text b) = b; text hh(text a, []) = a; text hh([a], text b) = bar(a, b); default text hh(text a, text b) = vv(a[0..-1], bar(a[-1], b)); - +@synsopsis{Horizontal concatenation, but if the left text is empty return nothing.} text lhh([], text _) = []; default text lhh(a, b) = hh(a, b); -text lvv(text a, text b) { - if (isEmpty(a)) return []; - return vv(a, b); -} - -text hh_(text a, text b) { - if (isEmpty(b)) return []; - return hh(a, b); -} - -text vv_(text a, text b) { - if (isEmpty(b)) return []; - return vv(a, b); -} +@synsopsis{Vertical concatenation, but if the left text is empty return nothing.} +text lvv([], text _) = []; +default text lvv(text a, text b) = vv(a,b); +@synsopsis{Horizontal concatenation, but if the right text is empty return nothing.} +text rhh(text _, []) = []; +text rhh(text a, text b) = hh(a, b); - -text LL(str s ) { - return [s]; - } - +@synsopsis{Vertical concatenation, but if the right text is empty return nothing.} +text rvv(text _, []) = []; +default text rvv(text a, text b) = vv(a,b); + +text LL(str s ) = [s]; + /* text HH(list[Box] b, Box c, options opts, int m) { if (isEmpty(b)) return []; int h = opts["h"]; text t = O(b[0], H([]), opts, m); int s = hwidth(t); - return hh(t, hh_(hskip(h), HH(tail(b), H([]), opts, m-s-h))); + return hh(t, rhh(hskip(h), HH(tail(b), H([]), opts, m-s-h))); } */ +text HH([], Box _, options opts, int m) = []; + text HH(list[Box] b, Box _, options opts, int m) { - if (isEmpty(b)) return []; int h = opts["h"]; text r = []; b = reverse(b); - for (a<-b) { - text t = O(a, H([]), opts, m); - int s = hwidth(t); - r = hh(t, hh_(hskip(h), r)); - m = m - s - h; - } - return r; - } + for (a <- b) { + text t = O(a, H([]), opts, m); + int s = hwidth(t); + r = hh(t, rhh(hskip(h), r)); + m = m - s - h; + } + + return r; +} text VV(list[Box] b, Box c, options opts, int m) { if (isEmpty(b)) return []; @@ -191,7 +186,7 @@ text VV(list[Box] b, Box c, options opts, int m) { if (V(_)!:=c || L("")!:=a) { text t = O(a, V([]), opts, m); - r = vv(t, vv_(vskip(v), r)); + r = vv(t, rvv(vskip(v), r)); } } return r; @@ -201,7 +196,7 @@ text VV(list[Box] b, Box c, options opts, int m) { text VV(list[Box] b, Box c, options opts, int m) { if (isEmpty(b)) return []; int v = opts["v"]; - return vv(O(b[0], c , opts, m), vv_(vskip(v), VV(tail(b), V([]), opts, m))); + return vv(O(b[0], c , opts, m), rvv(vskip(v), VV(tail(b), V([]), opts, m))); } */ @@ -216,7 +211,7 @@ text II(list[Box] b, Box c, options opts, int m) { int m1 = m-i; text t = O(b[0], c, opts, m1); int s = hwidth(t); - text r = hh_(hskip(i), hh(t, II(tail(b), c, opts, m1-s))); + text r = rhh(hskip(i), hh(t, II(tail(b), c, opts, m1-s))); return r; } } @@ -228,7 +223,7 @@ text WDWD(list[Box] b, Box c ,options opts, int m) { 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))); + return hh(t , rhh(hskip(h) , WDWD(tail(b), c, opts, m-s-h))); } @@ -256,7 +251,7 @@ text HVHV(text T, int s, text a, Box A, list[Box] B, options opts, int m) { int n = h + hwidth(a); if (size(a)>1) { // Multiple lines text T1 = O(A, V([]), opts, m-i); - return vv(T, vv_(vskip(v), HVHV(T1, m-hwidth(T1), B, opts, m, H([])))); + return vv(T, rvv(vskip(v), HVHV(T1, m-hwidth(T1), B, opts, m, H([])))); } if (n <= s) { // Box A fits in current line return HVHV(hh(lhh(T, hskip(h)), a), s-n, B, opts, m, H([])); @@ -265,11 +260,11 @@ text HVHV(text T, int s, text a, Box A, list[Box] B, options opts, int m) { n -= h; // n == width(a) if ((i+n)