summaryrefslogtreecommitdiff
path: root/clformat/src/main/java/bjc/utils/ioutils
diff options
context:
space:
mode:
Diffstat (limited to 'clformat/src/main/java/bjc/utils/ioutils')
-rw-r--r--clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java106
1 files changed, 72 insertions, 34 deletions
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java
index af8bff0..1c1821c 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/TabulateDirective.java
@@ -3,77 +3,115 @@ package bjc.utils.ioutils.format.directives;
import java.io.*;
import bjc.utils.esodata.*;
+import bjc.utils.ioutils.*;
import bjc.utils.ioutils.format.*;
public class TabulateDirective implements Directive {
public void format(FormatParameters dirParams) throws IOException {
- Tape<Object> itemTape = dirParams.tParams;
- CLModifiers mods = dirParams.getMods();
+ Edict edt = compile(dirParams.toCompileCTX());
- // Support for a possible future feature
- char padchar = ' ';
+ edt.format(dirParams.toFormatCTX());
+ }
- int currCol = dirParams.rw.getLinePos();
- if (mods.colonMod) {
- currCol = dirParams.rw.getIndentPos();
- }
+ @Override
+ public Edict compile(CompileContext compCTX) {
+ CLValue colinc = CLValue.nil();
+ CLValue colid = CLValue.nil();
+ CLParameters params = compCTX.decr.parameters;
+ CLModifiers mods = compCTX.decr.modifiers;
- CLParameters params = dirParams.getParams();
- if (mods.atMod) {
- int colrel = 1, colinc = 1;
+ if (params.length() > 2) {
+ params.mapIndex("colinc", 1);
- if (params.length() > 2) {
- params.mapIndex("colinc", 1);
+ colinc = params.resolveKey("colinc");
+ }
- colinc = params.getInt(itemTape, "colinc", "column increment", "T", 1);
- }
+ boolean isRelative = mods.atMod;
+ boolean fromIndent = mods.colonMod;
+ if (isRelative) {
if (params.length() > 1) {
params.mapIndices("colrel");
- colrel = params.getInt(itemTape, "colrel", "relative column number", "T", 1);
+ colid = params.resolveKey("colrel");
}
+ } else {
+ if (params.length() > 1) {
+ params.mapIndices("colnum");
- for (int i = 0; i < colrel; i++) {
- dirParams.rw.write(padchar);
+ colid = params.resolveKey("colnum");
}
+ }
- int nSpaces = 0;
+ return new TabulateEdict(isRelative, colinc, fromIndent, colid);
+ }
+}
- while ((currCol + nSpaces) % colinc != 0) nSpaces++;
+class TabulateEdict implements Edict {
+ private boolean isRelative;
+ private boolean fromIndent;
- for (int i = 0; i < nSpaces; i++) {
- dirParams.rw.write(padchar);
- }
+ private CLValue colincVal;
+ private CLValue colidVal;
+
+ public TabulateEdict(boolean isRelative, CLValue colinc, boolean fromIndent, CLValue colid) {
+ this.isRelative = isRelative;
+ this.fromIndent = fromIndent;
+
+ this.colincVal = colinc;
+
+ this.colidVal = colid;
+ }
+
+ @Override
+ public void format(FormatContext formCTX) throws IOException {
+ ReportWriter rw = formCTX.writer;
+
+ Tape<Object> itms = formCTX.items;
+
+ char padchar = ' ';
+
+ int currCol;
+
+ if (fromIndent) {
+ currCol = rw.getIndentPos();
} else {
- int colnum = 1, colinc = 1;
+ currCol = rw.getLinePos();
+ }
- if (params.length() > 2) {
- params.mapIndex("colinc", 1);
+ if (isRelative) {
+ int colinc = colincVal.asInt(itms, "column increment", "T", 1);
+ int colrel = colidVal.asInt(itms, "relative column number", "T", 1);
- colinc = params.getInt(itemTape, "colinc", "column increment", "T", 1);
+ for (int i = 0; i < colrel; i++) {
+ rw.write(padchar);
}
- if (params.length() > 1) {
- params.mapIndices("colnum");
+ int nSpaces = 0;
+
+ while ((currCol + nSpaces) % colinc != 0) {
+ rw.write(padchar);
- colnum = params.getInt(itemTape, "colnum", "column number", "T", 1);
+ nSpaces++;
}
+ } else {
+ int colinc = colincVal.asInt(itms, "column increment", "T", 1);
+ int colnum = colidVal.asInt(itms, "column number", "T", 1);
if (currCol < colnum) {
for (int i = currCol; i < colnum; i++) {
- dirParams.rw.write(padchar);
+ rw.write(padchar);
}
} else {
if (colinc == 0) return;
int k = 0;
- while (colnum > (currCol + (k * colinc))) k++;
+ while (colnum > (currCol + (k * colinc))) {
+ rw.write(padchar);
- for (int i = currCol; i < colnum; i++) {
- dirParams.rw.write(padchar);
+ k++;
}
}
}