From 0d54b152dc7002738daeec1ceb6d0f5cfea8c0db Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 16 Jan 2025 23:33:01 +0100 Subject: [PATCH] Moved escaked point handling out of the lexer --- .../x4o/fc18/FourCornerUnicodeDisplay.java | 13 ++-- .../fc18/zion7/FourCornerZion7Candlelier.java | 6 ++ .../fc18/zion7/FourCornerZionStenoLexer.java | 68 ++++++++----------- .../zion7/FourCornerZionStenoLexerSmoke.java | 6 -- .../org/x4o/fc18/zion7/TestSmokeReader.java | 7 -- 5 files changed, 41 insertions(+), 59 deletions(-) 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 4856fa6..9ac2d9c 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 @@ -243,7 +243,13 @@ public class FourCornerUnicodeDisplay { public void strobeUnicode(List codePoints) { codePoints.forEach(v -> output.appendCodePoint(v)); } - + + @Override + public void strobeRecursiveCake(List cakePoints) { + FourCornerZionStenoLexer thisDisplayEscaked = new FourCornerZionStenoLexer(this, true); + thisDisplayEscaked.read(cakePoints); + } + @Override public void strobeNether(List key, List octals) { // TODO Auto-generated method stub @@ -260,10 +266,5 @@ public class FourCornerUnicodeDisplay { output.append(";"); } } - - @Override - public void burnRecursive(int line, int col) { - throw new IllegalStateException("loop"); - } } } 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 7eb6d86..dd839eb 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 @@ -41,6 +41,8 @@ public interface FourCornerZion7Candlelier { void strobeUnicode(List codePoints); + void strobeRecursiveCake(List cakePoints); + void strobeNether(List key, List octals); interface Adapter extends FourCornerZion7Candlelier { @@ -57,6 +59,10 @@ public interface FourCornerZion7Candlelier { default void strobeUnicode(List codePoints) { } + @Override + default void strobeRecursiveCake(List cakePoints) { + } + @Override default void strobeNether(List key, List octals) { } 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 880fc60..912e293 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,7 +51,6 @@ public class FourCornerZionStenoLexer { private final int numeratorBank[] = new int[denominatorBank.length]; private List input; private int inputIndex = 0; - private int readLevel = 0; private int currLine = 0; private int currCol = 0; private FourCornerZionStenoLexerSmoke smokeSignals = CLEAN_SMOKE; @@ -137,17 +136,10 @@ public class FourCornerZionStenoLexer { public void read(List points) { input = Objects.requireNonNull(points); - readLevel++; // first puts on one, we allow level deep - if (readLevel > 2) { - smokeSignals.burnRecursive(currLine, currCol); - return; - } - if (readLevel == 1) { - inputIndex = 0; - currLine = 0; - currCol = 0; // allow reuse of lexer - handlerDocument.strobeDocumentAlpha(); - } + inputIndex = 0; + currLine = 0; + currCol = 0; // allow reuse of lexer + handlerDocument.strobeDocumentAlpha(); while (true) { ScanResult run = ScanResult.DONE; while (run.isDone()) { @@ -164,10 +156,7 @@ public class FourCornerZionStenoLexer { smokeSignals.burnUnsupported(currLine, currCol, input.get(inputIndex)); } } - if (readLevel == 1) { - handlerDocument.strobeDocumentOmega(); - } - readLevel--; + handlerDocument.strobeDocumentOmega(); } private ScanResult readTokens() { @@ -247,7 +236,6 @@ public class FourCornerZionStenoLexer { ScanResult result = ScanResult.DONE; int idxFirst = lexer.inputIndex; int idxLast = lexer.inputIndex; - while (true) { int cakePoint = lexer.input.get(lexer.inputIndex); if (cakePoint < blockStart || cakePoint > blockStop) { @@ -590,32 +578,32 @@ public class FourCornerZionStenoLexer { if (FCDotDEC0127DashPX0.ESC68_FC18.equals(decMode)) { List> result = new ArrayList<>(); scanSalahRakaAt(lexer, result); - if (!result.isEmpty()) { - List renderCakePoints = new ArrayList<>(); - for (List argu : result) { - int cakePointArgu = 0; - int cakePointIdx = 6; - for (Integer octal : argu) { - if (octal < FCDotCDC1604DashP6.NX01_A.ordinal()) { - continue; - } - if (octal > FCDotCDC1604DashP6.NX08_H.ordinal()) { - continue; - } - int offset = octal - FCDotCDC1604DashP6.NX01_A.ordinal(); - cakePointArgu = cakePointArgu + (offset << (cakePointIdx*3)); - cakePointIdx--; - if (cakePointIdx < 0) { - renderCakePoints.add(cakePointArgu); - cakePointIdx = 6; - cakePointArgu = 0; - } + if (result.isEmpty()) { + return false; + } + List renderCakePoints = new ArrayList<>(); + for (List argu : result) { + int cakePointArgu = 0; + int cakePointIdx = 6; + for (Integer octal : argu) { + if (octal < FCDotCDC1604DashP6.NX01_A.ordinal()) { + continue; + } + if (octal > FCDotCDC1604DashP6.NX08_H.ordinal()) { + continue; + } + int offset = octal - FCDotCDC1604DashP6.NX01_A.ordinal(); + cakePointArgu = cakePointArgu + (offset << (cakePointIdx*3)); + cakePointIdx--; + if (cakePointIdx < 0) { + renderCakePoints.add(cakePointArgu); + cakePointIdx = 6; + cakePointArgu = 0; } } - FourCornerZionStenoLexer lexer2 = new FourCornerZionStenoLexer(lexer.handler); - lexer2.read(renderCakePoints); - return true; } + lexer.handler.strobeRecursiveCake(renderCakePoints); + return true; } return false; } diff --git a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java index 2847eaa..4e8115a 100644 --- a/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java +++ b/nx01-x4o-fc18/src/main/java/org/x4o/fc18/zion7/FourCornerZionStenoLexerSmoke.java @@ -32,8 +32,6 @@ public interface FourCornerZionStenoLexerSmoke { void burnUnsupported(int line, int col, int cakePoint); - void burnRecursive(int line, int col); - void burnInvalidEscape(int line, int col, int cakePoint); @@ -55,10 +53,6 @@ public interface FourCornerZionStenoLexerSmoke { default void burnUnsupported(int line, int col, int cakePoint) { } - @Override - default void burnRecursive(int line, int col) { - } - @Override default void burnSalahInvalidCakePoint(int line, int col, int cakePoint) { } diff --git a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/TestSmokeReader.java b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/TestSmokeReader.java index 6cba301..d79224d 100644 --- a/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/TestSmokeReader.java +++ b/nx01-x4o-fc18/src/test/java/org/x4o/fc18/zion7/TestSmokeReader.java @@ -32,7 +32,6 @@ public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter { int errorUNI21UnusedBigIndian; int errorUnsupport; - int errorRecursive; public TestSmokeReader() { reset(); @@ -41,7 +40,6 @@ public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter { public void reset() { errorUNI21UnusedBigIndian = -1; errorUnsupport = -1; - errorRecursive = -1; } @Override @@ -53,9 +51,4 @@ public class TestSmokeReader implements FourCornerZionStenoLexerSmoke.Adapter { public void burnUnsupported(int line, int col, int cakePoint) { errorUnsupport = line; } - - @Override - public void burnRecursive(int line, int col) { - errorRecursive = line; - } }