From b8139ebda0cca000b55f36ca8bac4642aed62f64 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 14 Jan 2025 12:39:26 +0100 Subject: [PATCH] Added invalid NCR smoke signal support --- .../o2o/fc18/FourCornerUnicodeDisplay.java | 2 +- .../fc18/zion7/FourCornerZion7Candlelier.java | 19 +++ .../fc18/zion7/FourCornerZionStenoLexer.java | 17 ++- .../zion7/FourCornerZionStenoLexerSmoke.java | 35 ++++-- .../fc18/FourCornerUnicodeDisplayTest.java | 49 -------- .../org/x4o/o2o/fc18/zion7/LexerNCRTest.java | 113 ++++++++++++++++++ 6 files changed, 172 insertions(+), 63 deletions(-) create mode 100644 nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java index 1d66d39..f845d59 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java @@ -137,7 +137,7 @@ public class FourCornerUnicodeDisplay { lexer.withSmokeSignals(printer).read(chars); } - private final class StenoUnicodePrinter implements FourCornerZion7Candlelier, FourCornerZionStenoLexerSmoke { + private final class StenoUnicodePrinter implements FourCornerZion7Candlelier, FourCornerZionStenoLexerSmoke.Adapter { private final StringBuilder output; diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7Candlelier.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7Candlelier.java index e947e36..751539e 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7Candlelier.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZion7Candlelier.java @@ -42,4 +42,23 @@ public interface FourCornerZion7Candlelier { void strobeUnicode(List codePoints); void strobeNether(List key, List octals); + + interface Adapter extends FourCornerZion7Candlelier { + + @Override + default void strobeWords(FourCornerDotCake slice, List offsets) { + } + + @Override + default void strobeNCR1632(BigInteger denominator, BigInteger numerator) { + } + + @Override + default void strobeUnicode(List codePoints) { + } + + @Override + default void strobeNether(List key, List octals) { + } + } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java index 0bf4345..d20e4ef 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexer.java @@ -79,22 +79,22 @@ public class FourCornerZionStenoLexer { continue; // can't handle reserved, we be reported as } if (cakeSlice.getStop() <= 0xFF) { - continue; // handle CDC and DEC and muffins manual + continue; // handle CDC and DEC and muffins manually } if (FourCornerDotCake.FC_UNI2K_11.equals(cakeSlice)) { - continue; // parse blocks manual + continue; // parse block manually } if (FourCornerDotCake.FC_UNI2K_22.equals(cakeSlice)) { - continue; // parse blocks manual + continue; // parse block manually } if (FourCornerDotCake.FC_NETHER.equals(cakeSlice)) { - continue; // merge the nether data to octals manual + continue; // merge the nether data to octals manually } if (FourCornerDotCake.FC_NCR1632_XD.equals(cakeSlice)) { - continue; // merge the nether data to octals manual + continue; // parse block manually } if (FourCornerDotCake.FC_NCR1632_XN.equals(cakeSlice)) { - continue; // merge the nether data to octals manual + continue; // parse block manually } this.scanners.add(new StenoScannerWordCakeSlice(cakeSlice)); } @@ -282,6 +282,7 @@ public class FourCornerZionStenoLexer { private void handlePoints(List slicedPoints) { int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group int numeratorBank[] = new int[64]; + boolean fired = false; for (Integer cakePoint : slicedPoints) { if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) { int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart(); @@ -303,6 +304,10 @@ public class FourCornerZionStenoLexer { numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i*9)); } handler.strobeNCR1632(denominator, numerator); + fired = true; + } + if (fired == false && smokeSignals != null) { + smokeSignals.burnInvalidNCR1632(currLine, currCol); } } } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerSmoke.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerSmoke.java index a056d6c..dd0409c 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerSmoke.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zion7/FourCornerZionStenoLexerSmoke.java @@ -28,15 +28,36 @@ package org.x4o.o2o.fc18.zion7; /// @version 1.0 Jan 12, 2025 public interface FourCornerZionStenoLexerSmoke { - default void burnUnsupported(int line, int col, int cakePoint) { - } + void burnUnsupported(int line, int col, int cakePoint); - default void burnRecursive(int line, int col) { - } + void burnRecursive(int line, int col); - default void burnInvalidSalah(int line, int col) { - } + void burnInvalidSalah(int line, int col); - default void burnInvalidEscape(int line, int col, int cakePoint) { + void burnInvalidEscape(int line, int col, int cakePoint); + + void burnInvalidNCR1632(int line, int col); + + interface Adapter extends FourCornerZionStenoLexerSmoke { + + @Override + default void burnUnsupported(int line, int col, int cakePoint) { + } + + @Override + default void burnRecursive(int line, int col) { + } + + @Override + default void burnInvalidSalah(int line, int col) { + } + + @Override + default void burnInvalidEscape(int line, int col, int cakePoint) { + } + + @Override + default void burnInvalidNCR1632(int line, int col) { + } } } diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java index d65a7e8..ca1fb72 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java @@ -40,55 +40,6 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; */ public class FourCornerUnicodeDisplayTest { - @Test - public void testNCRSimpleX06() throws Exception { - List cdc = new ArrayList<>(); - cdc.add(FCDotCDC1604DashP6.NX24_X); // = X - cdc.add(FCDotCDC1604DashP6.EQUALS); - cdc.addAll(FCDotDEC0127DashPX0.ESC68_NCR.toX06BaklavaPoints()); - cdc.add(FCDotCDC1604DashP6.NX15_O); // T015 - cdc.add(FCDotCDC1604DashP6.NX14_N); // NXX_014 - cdc.add(FCDotCDC1604DashP6.NX05_E); // NXX_005 - cdc.add(FCDotCDC1604DashP6.NX07_G); // NXX_007 - cdc.add(FCDotCDC1604DashP6.NX15_O); // NXX_015 - cdc.add(FCDotCDC1604DashP6.NX04_D); // NXX_004 - cdc.add(FCDotCDC1604DashP6.SEMICOLON); - cdc.add(FCDotCDC1604DashP6._NEWLINE); - - Assertions.assertEquals("X=¹⁴/₁₅⁵/₁₅⁷/₁₅¹⁵/₁₅⁴/₁₅;\n", FourCornerUnicodeDisplay.text().renderFromX06(cdc)); - Assertions.assertEquals("X=␃␃␂ONEGOD;\n", FourCornerUnicodeDisplay.raw().renderFromX06(cdc)); - } - - @Test - public void testNCRLargeF9() throws Exception { - List cdc = new ArrayList<>(); - cdc.add(FCDotCDC1604DashP6.NX24_X.ordinal()); // = X - cdc.add(FCDotCDC1604DashP6.EQUALS.ordinal()); - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 11); // NXX_011 - cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart()); // T001 - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart()); // NXX_001 - cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() - 1 + 15); // T015 - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 14); // NXX_014 - cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() - 1 + 1); // one - cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + 512 + 2); // T1024 + one - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 4); // NXX_004 - cdc.add(FCDotCDC1604DashP6.SEMICOLON.ordinal()); - cdc.add(FCDotCDC1604DashP6._NEWLINE.ordinal()); - - Assertions.assertEquals("X=¹¹/₁¹/₁¹⁴/₁₅¹²³/₁₀₂₅⁴/₁₀₂₅;\n", FourCornerUnicodeDisplay.text().renderFromInt18(cdc)); - } - - @Test - public void testNCRLargestF576() throws Exception { - List cdc = new ArrayList<>(); - cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1); - cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 - - String res = "¹²³/₄₈₃₀₆₇₁₉₀₃₇₇₁₅₇₂₉₃₀₈₆₉₁₈₉₈₆₃₆₆₄₉₈₄₁₈₀₃₇₃₆₅₉₁₆₂₁₃₃₀₄₃₇₄₈₃₂₁₅₄₄₀₆₄₃₁₄₃₉₈₉₂₇₈₆₁₉₅₀₅₃₀₆₇₀₂₄₂₂₀₈₂₂₇₄₀₃₂₂₂₄₅₃₀₇₉₅₂₀₀₃₉₃₇₇₇₂₁₄₇₁₇₀₆₃₄₈₃₂₆₃₀₃₇₃₄₅₆₉₆₇₈₆₃₅₈₄₁₈₃₃₈₅₀₉₃₅₈₇₁₂₂₆₀₁₈₅₂₉₂₉"; - Assertions.assertEquals(res, FourCornerUnicodeDisplay.text().renderFromInt18(cdc)); - } - @Test public void testMixedCasing() throws Exception { List cdc = new ArrayList<>(); diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java new file mode 100644 index 0000000..f15ebd3 --- /dev/null +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/zion7/LexerNCRTest.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2004-2014, Willem Cazander + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.x4o.o2o.fc18.zion7; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.x4o.o2o.fc18.FourCornerDotCake; +import org.x4o.o2o.fc18.FourCornerUnicodeDisplay; +import org.x4o.o2o.fc18.FourCornerUnicodeImport; +import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints; +import org.x4o.o2o.fc18.pie9c.FCDotPIE9CDash26; +import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; +import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0; + +/** + * Tests four corner lexer parts. + * + * @author Willem Cazander + * @version 1.0 Jan 14, 2025 + */ +public class LexerNCRTest { + + int errorLine = -1; + + @Test + public void testNCRInvalid() throws Exception { + List cdc = new ArrayList<>(); + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1); + //cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 + + FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true); + lexer.withSmokeSignals(new FourCornerZionStenoLexerSmoke.Adapter() { + @Override + public void burnInvalidNCR1632(int line, int col) { + errorLine = line; + } + }).read(cdc); + Assertions.assertEquals(0, errorLine); + } + + @Test + public void testNCRSimpleX06() throws Exception { + List cdc = new ArrayList<>(); + cdc.add(FCDotCDC1604DashP6.NX24_X); // = X + cdc.add(FCDotCDC1604DashP6.EQUALS); + cdc.addAll(FCDotDEC0127DashPX0.ESC68_NCR.toX06BaklavaPoints()); + cdc.add(FCDotCDC1604DashP6.NX15_O); // T015 + cdc.add(FCDotCDC1604DashP6.NX14_N); // NXX_014 + cdc.add(FCDotCDC1604DashP6.NX05_E); // NXX_005 + cdc.add(FCDotCDC1604DashP6.NX07_G); // NXX_007 + cdc.add(FCDotCDC1604DashP6.NX15_O); // NXX_015 + cdc.add(FCDotCDC1604DashP6.NX04_D); // NXX_004 + cdc.add(FCDotCDC1604DashP6.SEMICOLON); + cdc.add(FCDotCDC1604DashP6._NEWLINE); + + Assertions.assertEquals("X=¹⁴/₁₅⁵/₁₅⁷/₁₅¹⁵/₁₅⁴/₁₅;\n", FourCornerUnicodeDisplay.text().renderFromX06(cdc)); + Assertions.assertEquals("X=␃␃␂ONEGOD;\n", FourCornerUnicodeDisplay.raw().renderFromX06(cdc)); + } + + @Test + public void testNCRLargeF9() throws Exception { + List cdc = new ArrayList<>(); + cdc.add(FCDotCDC1604DashP6.NX24_X.ordinal()); // = X + cdc.add(FCDotCDC1604DashP6.EQUALS.ordinal()); + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 11); // NXX_011 + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart()); // T001 + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart()); // NXX_001 + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() - 1 + 15); // T015 + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 14); // NXX_014 + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() - 1 + 1); // one + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + 512 + 2); // T1024 + one + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 4); // NXX_004 + cdc.add(FCDotCDC1604DashP6.SEMICOLON.ordinal()); + cdc.add(FCDotCDC1604DashP6._NEWLINE.ordinal()); + + Assertions.assertEquals("X=¹¹/₁¹/₁¹⁴/₁₅¹²³/₁₀₂₅⁴/₁₀₂₅;\n", FourCornerUnicodeDisplay.text().renderFromInt18(cdc)); + } + + @Test + public void testNCRLargestF576() throws Exception { + List cdc = new ArrayList<>(); + cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1); + cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123 + + String res = "¹²³/₄₈₃₀₆₇₁₉₀₃₇₇₁₅₇₂₉₃₀₈₆₉₁₈₉₈₆₃₆₆₄₉₈₄₁₈₀₃₇₃₆₅₉₁₆₂₁₃₃₀₄₃₇₄₈₃₂₁₅₄₄₀₆₄₃₁₄₃₉₈₉₂₇₈₆₁₉₅₀₅₃₀₆₇₀₂₄₂₂₀₈₂₂₇₄₀₃₂₂₂₄₅₃₀₇₉₅₂₀₀₃₉₃₇₇₇₂₁₄₇₁₇₀₆₃₄₈₃₂₆₃₀₃₇₃₄₅₆₉₆₇₈₆₃₅₈₄₁₈₃₃₈₅₀₉₃₅₈₇₁₂₂₆₀₁₈₅₂₉₂₉"; + Assertions.assertEquals(res, FourCornerUnicodeDisplay.text().renderFromInt18(cdc)); + } +}