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/IndentDirective.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java
index 9226761..0898cc1 100644
--- a/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java
+++ b/clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java
@@ -13,6 +13,12 @@ import bjc.utils.ioutils.format.*;
public class IndentDirective implements Directive {
@Override
public void format(FormatParameters dirParams) throws IOException {
+ Edict edt = compile(dirParams.toCompileCTX());
+
+ edt.format(dirParams.toFormatCTX());
+ }
+
+ public void formatF(FormatParameters dirParams) throws IOException {
Tape<Object> itemTape = dirParams.tParams;
CLModifiers mods = dirParams.getMods();
@@ -47,4 +53,68 @@ public class IndentDirective implements Directive {
dirParams.rw.setLevel(nIndents);
}
}
+
+ @Override
+ public Edict compile(CompileContext compCTX) {
+ CLParameters params = compCTX.decr.parameters;
+ CLModifiers mods = compCTX.decr.modifiers;
+
+ if (mods.dollarMod) {
+ return new IndentConfigureEdict();
+ }
+
+ CLValue indentCount = CLValue.nil();
+ if(params.length() >= 1) {
+ params.mapIndices("count");
+
+ indentCount = params.resolveKey("count");
+ }
+
+ return new IndentEdict(indentCount, mods.colonMod);
+ }
+}
+
+class IndentEdict implements Edict {
+ private CLValue numIndentsVal;
+
+ private boolean isRelative;
+
+ public IndentEdict(CLValue numIndents, boolean isRelative) {
+ this.numIndentsVal = numIndents;
+
+ this.isRelative = isRelative;
+ }
+
+ @Override
+ public void format(FormatContext formCTX) {
+ int numIndents = numIndentsVal.asInt(formCTX.items, "indent count", "I", 1);
+
+ boolean dedent = false;
+ if (numIndents < 0) {
+ numIndents = -numIndents;
+
+ dedent = true;
+ }
+
+ if (isRelative) {
+ if (dedent) {
+ formCTX.writer.dedent(numIndents);
+ } else {
+ formCTX.writer.indent(numIndents);
+ }
+ } else {
+ if (dedent) {
+ throw new IllegalArgumentException("Cannot have negative indent level");
+ }
+
+ formCTX.writer.setLevel(numIndents);
+ }
+ }
+}
+
+class IndentConfigureEdict implements Edict {
+ @Override
+ public void format(FormatContext formCTX) {
+
+ }
}