diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java index c76f41b..3e32e54 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerRecipe.java @@ -24,6 +24,7 @@ package org.x4o.fc18; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.PrimitiveIterator; @@ -38,6 +39,7 @@ import org.x4o.fc18.cake2.pie9c.FCDotPIE9CDash20; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0; import org.x4o.fc18.octal8.PrimordialOctal; +import org.x4o.fc18.zion7.FourCornerZion7SalahSequence; /// Holds different lookup and conversion maps towards four corner int18 cake points. /// @@ -52,11 +54,55 @@ final public class FourCornerRecipe { private FourCornerRecipe() { } - static public List embedSandWalker(List rhythm) { - return embedSandWalker(new ArrayList<>(), rhythm); + static public List embedSalahSequenceX06(FourCornerZion7SalahSequence type, List> arguments) { + return embedSalahSequence(new ArrayList<>(), type, arguments, true); } - static public List embedSandWalker(List out, List rhythm) { + static public List embedSalahSequenceX18(FourCornerZion7SalahSequence type, List> arguments) { + return embedSalahSequence(new ArrayList<>(), type, arguments, false); + } + + static public List embedSalahSequenceX06(List out, FourCornerZion7SalahSequence type, List> arguments) { + return embedSalahSequence(out, type, arguments, true); + } + + static public List embedSalahSequenceX18(List out, FourCornerZion7SalahSequence type, List> arguments) { + return embedSalahSequence(out, type, arguments, false); + } + + static private List embedSalahSequence(List out, FourCornerZion7SalahSequence type, List> arguments, boolean isSixBit) { + Objects.requireNonNull(type); + Objects.requireNonNull(arguments); + if (FourCornerZion7SalahSequence.ESC_VT06.equals(type)) { + if (isSixBit) { + out.addAll(FCDotDEC2701DashPX0.ESC_VT06.baklavaPointSequence()); + } else { + out.addAll(FCDotDEC2701DashPX0.ESC_VT06.cakePointSequence()); + } + } else { + if (isSixBit) { + out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).baklavaPointSequence()); + } else { + out.addAll(FCDotDEC2701DashPX0.valueOf(type.ordinal()).cakePointSequence()); + } + } + Iterator> argu = arguments.iterator(); + while (argu.hasNext()) { + List arguValue = argu.next(); + out.addAll(arguValue); // TODO: add range check + if (argu.hasNext()) { + out.add(FCDotCDC1604DashP6._RAKA_QUESTION.baklavaPointDotIndex()); + } + } + out.add(FCDotCDC1604DashP6._SALAH_EXCLAMATION.baklavaPointDotIndex()); + return out; + } + + static public List embedSandWalkerX06(List rhythm) { + return embedSandWalkerX06(new ArrayList<>(), rhythm); + } + + static public List embedSandWalkerX06(List out, List rhythm) { Objects.requireNonNull(rhythm); if (!FourCornerRecipe.SAND_WORM_SIGN.contains(rhythm.size())) { throw new IllegalArgumentException("Sand walker rhythm is not 72 bit aligned: " + rhythm.size()); @@ -73,13 +119,12 @@ final public class FourCornerRecipe { return out; } - static public List embedSandWorm(List spice) { - return embedSandWorm(new ArrayList<>(), spice); + static public List embedSandWormX06(List spice) { + return embedSandWormX06(new ArrayList<>(), spice); } - static public List embedSandWorm(List out, List spice) { + static public List embedSandWormX06(List out, List spice) { Objects.requireNonNull(spice); - // TODO: redo for 18 bit FC this is 6 bit out.add(FCDotDEC2701DashPX0.ESC68_SAND_WORM.cakePointDotIndex()); for (int i = spice.size(); i >= 0; i--) { PrimordialOctal octal = spice.get(i); @@ -89,6 +134,15 @@ final public class FourCornerRecipe { return out; } + static public List embedSandWormX18(List spice) { + return embedSandWormX18(new ArrayList<>(), spice); + } + + static public List embedSandWormX18(List out, List spice) { + Objects.requireNonNull(spice); + return embedSandWormX06(out, spice); // TODO: write 18 bit version + } + static public List embedNCR1632Denominator(BigInteger value) { return embedNCR1632Value(new ArrayList<>(), value, FourCornerDotCake.FC_NCR1632_DEN.getStart()); } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java index cc5c17c..5445082 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/FourCornerUnicodeDisplay.java @@ -24,7 +24,9 @@ package org.x4o.fc18; import java.math.BigInteger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; @@ -38,6 +40,7 @@ import org.x4o.fc18.cake2.pie9d.FCDotPIE9DDash09; import org.x4o.fc18.cake2.zero33.FCDotCDC1604DashP6; import org.x4o.fc18.octal8.PrimordialOctal; import org.x4o.fc18.zion7.FourCornerZion7Candlelier; +import org.x4o.fc18.zion7.FourCornerZion7SalahSequence; import org.x4o.fc18.zion7.FourCornerZionStenoLexer; import org.x4o.fc18.zion7.FourCornerZionStenoLexerSmoke; @@ -50,6 +53,7 @@ public class FourCornerUnicodeDisplay { private boolean failPipeSmoke = false; private boolean handleEscape = true; private String renderSeperator = null; + private final Map>>> escHandlers = new HashMap<>(); public FourCornerUnicodeDisplay(boolean failPipeSmoke, boolean handleEscape, String renderSeperator) { this.failPipeSmoke = failPipeSmoke; @@ -57,10 +61,15 @@ public class FourCornerUnicodeDisplay { this.renderSeperator = renderSeperator; } + public FourCornerUnicodeDisplay withEscapeHandler(FourCornerZion7SalahSequence type, Consumer>> handler) { + escHandlers.put(type, handler); + return this; + } + static public FourCornerUnicodeDisplay text() { return new FourCornerUnicodeDisplay(false, true, null); } - + static public FourCornerUnicodeDisplay raw() { return new FourCornerUnicodeDisplay(false, false, null); } @@ -257,5 +266,13 @@ public class FourCornerUnicodeDisplay { output.append("]"); } } + + @Override + public void strobeSalahSequence(FourCornerZion7SalahSequence type, List> arguments) { + Consumer>> handler = escHandlers.get(type); + if (handler != null) { + handler.accept(arguments); + } + } } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/zero33/dec1/FCDotDEC2701DashPX0.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/zero33/dec1/FCDotDEC2701DashPX0.java index 2b6615e..6f59bbe 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/zero33/dec1/FCDotDEC2701DashPX0.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/cake2/zero33/dec1/FCDotDEC2701DashPX0.java @@ -45,31 +45,31 @@ public enum FCDotDEC2701DashPX0 implements FourCornerX06BaklavaPointSequence, Fo // =========== External escape sequence, who MUST terminate with ! /// _ESC6_X1 _ESC6_X1 _ESC6_X1 = 1 - _ESC_USER_1, + ESC_USER_1, /// _ESC6_X1 _ESC6_X1 _ESC6_X2 = 2 - _ESC_USER_2, + ESC_USER_2, /// _ESC6_X1 _ESC6_X1 _ESC6_X3 = 3 - _ESC_USER_3, + ESC_USER_3, /// _ESC6_X1 _ESC6_X2 _ESC6_X1 = 4 - _ESC_USER_4, + ESC_USER_4, /// _ESC6_X1 _ESC6_X2 _ESC6_X2 = 5 - _ESC_USER_5, + ESC_USER_5, /// _ESC6_X1 _ESC6_X2 _ESC6_X3 = 6 - _ESC_USER_6, + ESC_USER_6, /// _ESC6_X1 _ESC6_X3 _ESC6_X1 = 7 - _ESC_USER_7, + __ESC_RESERVED_A7, /// _ESC6_X1 _ESC6_X3 _ESC6_X2 = 8 - _ESC_USER_8, + __ESC_RESERVED_A8, /// _ESC6_X1 _ESC6_X3 _ESC6_X3 = 9 - _ESC_USER_9, + __ESC_RESERVED_A9, // =========== Internal escape sequence, to embed symbols,fractions and adult texts. @@ -162,7 +162,7 @@ public enum FCDotDEC2701DashPX0 implements FourCornerX06BaklavaPointSequence, Fo } public boolean isExternal() { - if (ordinal() <= _ESC_USER_9.ordinal()) { + if (ordinal() <= ESC_USER_6.ordinal()) { return true; } return false; diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java index 34a2a9a..7d7606e 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7Candlelier.java @@ -48,6 +48,9 @@ public interface FourCornerZion7Candlelier { /// Octal sand worm spice void strobeSandWorm(List spice); + /// Handles the lexer salah sequence strobes + void strobeSalahSequence(FourCornerZion7SalahSequence type, List> arguments); + interface Adapter extends FourCornerZion7Candlelier { @Override @@ -69,5 +72,9 @@ public interface FourCornerZion7Candlelier { @Override default void strobeSandWorm(List spice) { } + + @Override + default void strobeSalahSequence(FourCornerZion7SalahSequence type, List> arguments) { + } } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7SalahSequence.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7SalahSequence.java index ce39764..cf5c969 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7SalahSequence.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZion7SalahSequence.java @@ -22,20 +22,18 @@ */ package org.x4o.fc18.zion7; -import java.util.List; - -/// Handles the lexer salah sequence strobes. +/// The salah sequence strobe supported external types. /// /// @author Willem Cazander /// @version 1.0 Jan 11, 2025 -public interface FourCornerZion7SalahSequence extends FourCornerZion7Candlelier { +public enum FourCornerZion7SalahSequence { - void strobeSalahSequence(int type, List> arguments); - - interface Adapter extends FourCornerZion7SalahSequence, FourCornerZion7Candlelier.Adapter { - - @Override - default void strobeSalahSequence(int type, List> arguments) { - } - } + ESC_USER_1, + ESC_USER_2, + ESC_USER_3, + ESC_USER_4, + ESC_USER_5, + ESC_USER_6, + ESC_VT06, + ; } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java index b59c0d9..f2932d1 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoGrapher.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Objects; import org.x4o.fc18.FourCornerRecipe; -import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0; import org.x4o.fc18.octal8.PrimordialOctal; /// Write steno for zion. @@ -44,7 +43,7 @@ public class FourCornerZionStenoGrapher { return new FourCornerWriter(out, false); } - static public final class FourCornerWriter implements FourCornerZion7AlphaOmega,FourCornerZion7SalahSequence,FourCornerZion7TempleScrolls { + static public final class FourCornerWriter implements FourCornerZion7AlphaOmega,FourCornerZion7TempleScrolls { private final List out; private final boolean isSixBit; @@ -71,8 +70,9 @@ public class FourCornerZionStenoGrapher { @Override public void strobeWords(List cakePoints) { - for (Integer cakePoint : cakePoints) { // todo: remove iterator - strobeWord(cakePoint); + int cakeSize = cakePoints.size(); + for (int i = 0; i < cakeSize; i++) { + strobeWord(cakePoints.get(i)); } } @@ -84,17 +84,25 @@ public class FourCornerZionStenoGrapher { @Override public void strobeSandWalker(List rhythm) { - FourCornerRecipe.embedSandWalker(out, rhythm); + FourCornerRecipe.embedSandWalkerX06(out, rhythm); } @Override public void strobeSandWorm(List spice) { - FourCornerRecipe.embedSandWorm(out, spice); + if (isSixBit) { + FourCornerRecipe.embedSandWormX06(out, spice); + } else { + FourCornerRecipe.embedSandWormX18(out, spice); + } } @Override - public void strobeSalahSequence(int type, List> arguments) { - FCDotDEC2701DashPX0 cdcDECMode = FCDotDEC2701DashPX0.valueOf(type); + public void strobeSalahSequence(FourCornerZion7SalahSequence type, List> arguments) { + if (isSixBit) { + FourCornerRecipe.embedSalahSequenceX06(out, type, arguments); + } else { + FourCornerRecipe.embedSalahSequenceX18(out, type, arguments); + } } } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java index e55d328..b866755 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexer.java @@ -51,12 +51,10 @@ public class FourCornerZionStenoLexer { private final static FourCornerZion7AlphaOmega CLEAN_BIBLE = new FourCornerZion7AlphaOmega.Adapter() {}; private final static FourCornerZionStenoLexerFire CLEAN_FIRE = new FourCornerZionStenoLexerFire.Adapter() {}; private final static FourCornerZionStenoLexerSmoke CLEAN_SMOKE = new FourCornerZionStenoLexerSmoke.Adapter() {}; - private final static FourCornerZion7SalahSequence CLEAN_PRAYER = new FourCornerZion7SalahSequence.Adapter() {}; private final static List CAKE_SLICE_EATERS = new ArrayList<>(); private final boolean handlerEscape; private final FourCornerZion7Candlelier handler; private final FourCornerZion7AlphaOmega handlerDocument; - private final FourCornerZion7SalahSequence handlerSalahSequence; private final FourCornerZion7TempleScrolls handlerTempleScrolls; private final int denominatorBank[] = new int[64]; // <== is the terminator select are 6 bit of banks with 9 bit of values. private final int numeratorBank[] = new int[denominatorBank.length]; @@ -115,11 +113,6 @@ public class FourCornerZionStenoLexer { } else { this.handlerDocument = CLEAN_BIBLE; } - if (handler instanceof FourCornerZion7SalahSequence) { - this.handlerSalahSequence = FourCornerZion7SalahSequence.class.cast(handler); - } else { - this.handlerSalahSequence = CLEAN_PRAYER; - } if (handler instanceof FourCornerZion7TempleScrolls) { this.handlerTempleScrolls = FourCornerZion7TempleScrolls.class.cast(handler); } else { @@ -501,7 +494,11 @@ public class FourCornerZionStenoLexer { if (readOK == false) { return true; // point is eaten } - lexer.handlerSalahSequence.strobeSalahSequence(cdcDECMode.ordinal(), args); + if (FCDotDEC2701DashPX0.ESC_VT06.equals(cdcDECMode)) { + lexer.handler.strobeSalahSequence(FourCornerZion7SalahSequence.ESC_VT06, args); + } else { + lexer.handler.strobeSalahSequence(FourCornerZion7SalahSequence.values()[cdcDECMode.ordinal()], args); // todo: use fast enum + } return true; } if (FCDotDEC2701DashPX0.ESC68_2PIE9C.equals(cdcDECMode)) { diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotDEC0127DashPX0Test.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotDEC0127DashPX0Test.java index b15f456..935b8e1 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotDEC0127DashPX0Test.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/cake2/zero33/FCDotDEC0127DashPX0Test.java @@ -44,7 +44,7 @@ public class FCDotDEC0127DashPX0Test { @Test public void testBaklavaSequence() throws Exception { List seq = null; - seq = FCDotDEC2701DashPX0._ESC_USER_1.baklavaPointSequence(); + seq = FCDotDEC2701DashPX0.ESC_USER_1.baklavaPointSequence(); Assertions.assertEquals(3, seq.size()); Assertions.assertEquals(FCDotCDC1604DashP6._ESC6_X1.ordinal(), seq.get(0)); Assertions.assertEquals(FCDotCDC1604DashP6._ESC6_X1.ordinal(), seq.get(1));