diff options
| author | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-08-10 19:25:34 -0300 |
|---|---|---|
| committer | Benjamin J. Culkin <bjculkin@mix.wvu.edu> | 2019-08-10 19:25:34 -0300 |
| commit | dda20b14d927ed4aba765ddacf5f38e788427d95 (patch) | |
| tree | 4677ac3538b8fec40a24d0d313e796fb295cdcdb /clformat/src/main/java/bjc | |
| parent | 4848d0af21eabe206d6228b5996943c57fa9f68c (diff) | |
Implement compilation for IndentDirective
Diffstat (limited to 'clformat/src/main/java/bjc')
| -rw-r--r-- | clformat/src/main/java/bjc/utils/ioutils/format/directives/IndentDirective.java | 70 |
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) { + + } } |
