Remove state from test and added more adapters
This commit is contained in:
parent
95eeb90ccd
commit
0c4040b9d3
|
@ -31,4 +31,15 @@ public interface FourCornerZion7AlphaOmega extends FourCornerZion7Candlelier {
|
||||||
void strobeDocumentAlpha();
|
void strobeDocumentAlpha();
|
||||||
|
|
||||||
void strobeDocumentOmega();
|
void strobeDocumentOmega();
|
||||||
|
|
||||||
|
interface Adapter extends FourCornerZion7AlphaOmega, FourCornerZion7Candlelier.Adapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void strobeDocumentAlpha() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void strobeDocumentOmega() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
||||||
/// @version 1.0 Jan 09, 2025
|
/// @version 1.0 Jan 09, 2025
|
||||||
public class FourCornerZionStenoLexer {
|
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 boolean handlerEscape;
|
private final boolean handlerEscape;
|
||||||
private final FourCornerZion7Candlelier handler;
|
private final FourCornerZion7Candlelier handler;
|
||||||
private final FourCornerZion7AlphaOmega handlerDocument;
|
private final FourCornerZion7AlphaOmega handlerDocument;
|
||||||
|
@ -49,8 +52,8 @@ public class FourCornerZionStenoLexer {
|
||||||
private Integer cakePoint = null;
|
private Integer cakePoint = null;
|
||||||
private int currLine = 0;
|
private int currLine = 0;
|
||||||
private int currCol = 0;
|
private int currCol = 0;
|
||||||
private FourCornerZionStenoLexerSmoke smokeSignals;
|
private FourCornerZionStenoLexerSmoke smokeSignals = CLEAN_SMOKE;
|
||||||
private FourCornerZionStenoLexerFire fireSignals;
|
private FourCornerZionStenoLexerFire fireSignals = CLEAN_FIRE;
|
||||||
|
|
||||||
public FourCornerZionStenoLexer(FourCornerZion7Candlelier handler) {
|
public FourCornerZionStenoLexer(FourCornerZion7Candlelier handler) {
|
||||||
this(handler, true);
|
this(handler, true);
|
||||||
|
@ -62,7 +65,7 @@ public class FourCornerZionStenoLexer {
|
||||||
if (handler instanceof FourCornerZion7AlphaOmega) {
|
if (handler instanceof FourCornerZion7AlphaOmega) {
|
||||||
this.handlerDocument = FourCornerZion7AlphaOmega.class.cast(handler);
|
this.handlerDocument = FourCornerZion7AlphaOmega.class.cast(handler);
|
||||||
} else {
|
} else {
|
||||||
this.handlerDocument = null;
|
this.handlerDocument = CLEAN_BIBLE;
|
||||||
}
|
}
|
||||||
if (handler instanceof FourCornerZion7SalahSequence) {
|
if (handler instanceof FourCornerZion7SalahSequence) {
|
||||||
this.handlerSalahSequence = FourCornerZion7SalahSequence.class.cast(handler);
|
this.handlerSalahSequence = FourCornerZion7SalahSequence.class.cast(handler);
|
||||||
|
@ -105,12 +108,12 @@ public class FourCornerZionStenoLexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FourCornerZionStenoLexer withSmokeSignals(FourCornerZionStenoLexerSmoke smokeSignals) {
|
public FourCornerZionStenoLexer withSmokeSignals(FourCornerZionStenoLexerSmoke smokeSignals) {
|
||||||
this.smokeSignals = smokeSignals;
|
this.smokeSignals = Objects.requireNonNull(smokeSignals);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FourCornerZionStenoLexer withFireSignals(FourCornerZionStenoLexerFire fireSignals) {
|
public FourCornerZionStenoLexer withFireSignals(FourCornerZionStenoLexerFire fireSignals) {
|
||||||
this.fireSignals = fireSignals;
|
this.fireSignals = Objects.requireNonNull(fireSignals);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,18 +142,14 @@ public class FourCornerZionStenoLexer {
|
||||||
Iterator<Integer> input = Objects.requireNonNull(points);
|
Iterator<Integer> input = Objects.requireNonNull(points);
|
||||||
readLevel++; // first puts on one, we allow level deep
|
readLevel++; // first puts on one, we allow level deep
|
||||||
if (readLevel > 2) {
|
if (readLevel > 2) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnRecursive(currLine, currCol);
|
||||||
smokeSignals.burnRecursive(currLine, currCol);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (readLevel == 1) {
|
if (readLevel == 1) {
|
||||||
this.cakePoint = null; // allow reuse of lexer
|
cakePoint = null; // allow reuse of lexer
|
||||||
this.currLine = 0;
|
currLine = 0;
|
||||||
this.currCol = 0;
|
currCol = 0;
|
||||||
if (handlerDocument != null) {
|
handlerDocument.strobeDocumentAlpha();
|
||||||
handlerDocument.strobeDocumentAlpha();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (input.hasNext()) {
|
while (input.hasNext()) {
|
||||||
if (safeNext(input).isEOF()) {
|
if (safeNext(input).isEOF()) {
|
||||||
|
@ -163,11 +162,9 @@ public class FourCornerZionStenoLexer {
|
||||||
if (run.isEOF()) {
|
if (run.isEOF()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
||||||
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (handlerDocument != null && readLevel == 1) {
|
if (readLevel == 1) {
|
||||||
handlerDocument.strobeDocumentOmega();
|
handlerDocument.strobeDocumentOmega();
|
||||||
}
|
}
|
||||||
readLevel--;
|
readLevel--;
|
||||||
|
@ -193,9 +190,7 @@ public class FourCornerZionStenoLexer {
|
||||||
}
|
}
|
||||||
cakePoint = input.next();
|
cakePoint = input.next();
|
||||||
currCol++;
|
currCol++;
|
||||||
if (fireSignals != null) {
|
fireSignals.fireStateColumn(currCol);
|
||||||
fireSignals.fireStateColumn(currCol);
|
|
||||||
}
|
|
||||||
return ScanResult.DONE;
|
return ScanResult.DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,12 +305,10 @@ public class FourCornerZionStenoLexer {
|
||||||
errorZeroSparks = false;
|
errorZeroSparks = false;
|
||||||
errorUnusedSparks = false;
|
errorUnusedSparks = false;
|
||||||
}
|
}
|
||||||
if (smokeSignals != null) {
|
if (errorZeroSparks) {
|
||||||
if (errorZeroSparks) {
|
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol);
|
||||||
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol);
|
} else if (errorUnusedSparks) {
|
||||||
} else if (errorUnusedSparks) {
|
smokeSignals.burnNCR1632UnusedSparks(currLine, currCol);
|
||||||
smokeSignals.burnNCR1632UnusedSparks(currLine, currCol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -350,7 +343,7 @@ public class FourCornerZionStenoLexer {
|
||||||
result.add(codePoint);
|
result.add(codePoint);
|
||||||
errorUnusedBigIndian = false;
|
errorUnusedBigIndian = false;
|
||||||
}
|
}
|
||||||
if (smokeSignals != null && errorUnusedBigIndian) {
|
if (errorUnusedBigIndian) {
|
||||||
smokeSignals.burnUNI21UnusedBigIndian(currLine, currCol);
|
smokeSignals.burnUNI21UnusedBigIndian(currLine, currCol);
|
||||||
}
|
}
|
||||||
handler.strobeUnicode(result);
|
handler.strobeUnicode(result);
|
||||||
|
@ -386,10 +379,8 @@ public class FourCornerZionStenoLexer {
|
||||||
if (FCDotCDC1604DashP6._NEWLINE.ordinal() == muffinPoint) {
|
if (FCDotCDC1604DashP6._NEWLINE.ordinal() == muffinPoint) {
|
||||||
currLine++;
|
currLine++;
|
||||||
currCol = 0;
|
currCol = 0;
|
||||||
if (fireSignals != null) {
|
fireSignals.fireStateLine(currLine);
|
||||||
fireSignals.fireStateLine(currLine);
|
fireSignals.fireStateColumn(currCol);
|
||||||
fireSignals.fireStateColumn(currCol);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Handle 8 and 18 bit direct cake points
|
// Handle 8 and 18 bit direct cake points
|
||||||
if (FourCornerDotCake.FC_APL0127_P7A.contains(muffinPoint)) {
|
if (FourCornerDotCake.FC_APL0127_P7A.contains(muffinPoint)) {
|
||||||
|
@ -417,9 +408,7 @@ public class FourCornerZionStenoLexer {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (FourCornerDotCake.__MIND_THE_GAP.contains(muffinPoint)) {
|
if (FourCornerDotCake.__MIND_THE_GAP.contains(muffinPoint)) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
||||||
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,9 +467,7 @@ public class FourCornerZionStenoLexer {
|
||||||
numberMode = null; // out of range, thus stop
|
numberMode = null; // out of range, thus stop
|
||||||
decMode = readEscape6(cdc, cdcPoint);
|
decMode = readEscape6(cdc, cdcPoint);
|
||||||
if (decMode == null) {
|
if (decMode == null) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (decMode == FCDotDEC0127DashPX0.ESC68_PIE || decMode == FCDotDEC0127DashPX0.ESC68_NCR) {
|
if (decMode == FCDotDEC0127DashPX0.ESC68_PIE || decMode == FCDotDEC0127DashPX0.ESC68_NCR) {
|
||||||
|
@ -555,9 +542,7 @@ public class FourCornerZionStenoLexer {
|
||||||
if (numberMode == null) {
|
if (numberMode == null) {
|
||||||
Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint);
|
Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint);
|
||||||
if (slice.isEmpty()) {
|
if (slice.isEmpty()) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnUnsupported(currLine, currCol, cdcPoint);
|
||||||
smokeSignals.burnUnsupported(currLine, currCol, cdcPoint);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
handler.strobeWords(slice.get(), List.of(cdcPoint));
|
handler.strobeWords(slice.get(), List.of(cdcPoint));
|
||||||
|
@ -584,9 +569,7 @@ public class FourCornerZionStenoLexer {
|
||||||
}
|
}
|
||||||
if (salahMode.equals(decMode)) {
|
if (salahMode.equals(decMode)) {
|
||||||
if (salahMode.name().startsWith("__")) {
|
if (salahMode.name().startsWith("__")) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<List<Integer>> args = new ArrayList<>();
|
List<List<Integer>> args = new ArrayList<>();
|
||||||
|
@ -634,18 +617,14 @@ public class FourCornerZionStenoLexer {
|
||||||
while (input.hasNext()) {
|
while (input.hasNext()) {
|
||||||
int cdcPoint = input.next();
|
int cdcPoint = input.next();
|
||||||
if (cdcPoint == FCDotCDC1604DashP6._NUL.ordinal()) {
|
if (cdcPoint == FCDotCDC1604DashP6._NUL.ordinal()) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
|
||||||
}
|
|
||||||
result.clear();
|
result.clear();
|
||||||
return ScanResult.NEXT; // _NUL not allowed salah
|
return ScanResult.NEXT; // _NUL not allowed salah
|
||||||
}
|
}
|
||||||
if (FCDotCDC1604DashP6.isEscape6(cdcPoint) || FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint)) {
|
if (FCDotCDC1604DashP6.isEscape6(cdcPoint) || FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint)) {
|
||||||
FCDotDEC0127DashPX0 embedESC = readEscape6(input, cdcPoint);
|
FCDotDEC0127DashPX0 embedESC = readEscape6(input, cdcPoint);
|
||||||
if (embedESC == null) {
|
if (embedESC == null) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
|
||||||
}
|
|
||||||
result.clear();
|
result.clear();
|
||||||
return ScanResult.NEXT;
|
return ScanResult.NEXT;
|
||||||
}
|
}
|
||||||
|
@ -662,9 +641,7 @@ public class FourCornerZionStenoLexer {
|
||||||
continue; // Next argument
|
continue; // Next argument
|
||||||
}
|
}
|
||||||
if (!embedESC.isEmbeddable()) {
|
if (!embedESC.isEmbeddable()) {
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
|
||||||
}
|
|
||||||
result.clear();
|
result.clear();
|
||||||
return ScanResult.NEXT;
|
return ScanResult.NEXT;
|
||||||
}
|
}
|
||||||
|
@ -674,9 +651,7 @@ public class FourCornerZionStenoLexer {
|
||||||
}
|
}
|
||||||
argu.add(cdcPoint);
|
argu.add(cdcPoint);
|
||||||
}
|
}
|
||||||
if (smokeSignals != null) {
|
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
|
||||||
}
|
|
||||||
result.clear();
|
result.clear();
|
||||||
return ScanResult.NEXT;
|
return ScanResult.NEXT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,18 @@ package org.x4o.o2o.fc18.zion7;
|
||||||
/// @version 1.0 Jan 13, 2025
|
/// @version 1.0 Jan 13, 2025
|
||||||
public interface FourCornerZionStenoLexerFire {
|
public interface FourCornerZionStenoLexerFire {
|
||||||
|
|
||||||
default void fireStateLine(int line) {
|
void fireStateLine(int line);
|
||||||
}
|
|
||||||
|
|
||||||
default void fireStateColumn(int column) {
|
void fireStateColumn(int column);
|
||||||
|
|
||||||
|
interface Adapter extends FourCornerZionStenoLexerFire {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void fireStateLine(int line) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void fireStateColumn(int column) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,27 +41,25 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
||||||
*/
|
*/
|
||||||
public class LexerNCRTest {
|
public class LexerNCRTest {
|
||||||
|
|
||||||
final TestSmokeReader SMOKE_READER = new TestSmokeReader();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNCRInvalid() throws Exception {
|
public void testNCRInvalid() throws Exception {
|
||||||
|
TestSmokeReader smokeReader = new TestSmokeReader();
|
||||||
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
||||||
lexer.withSmokeSignals(SMOKE_READER);
|
lexer.withSmokeSignals(smokeReader);
|
||||||
List<Integer> cdc = new ArrayList<>();
|
List<Integer> cdc = new ArrayList<>();
|
||||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1);
|
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1);
|
||||||
|
|
||||||
SMOKE_READER.reset();
|
|
||||||
lexer.read(cdc);
|
lexer.read(cdc);
|
||||||
Assertions.assertEquals(-1, SMOKE_READER.errorNCRUnusedSparks);
|
Assertions.assertEquals(-1, smokeReader.errorNCRUnusedSparks);
|
||||||
Assertions.assertEquals(0, SMOKE_READER.errorNCRZeroSparks);
|
Assertions.assertEquals(0, smokeReader.errorNCRZeroSparks);
|
||||||
|
|
||||||
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
|
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
|
||||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2);
|
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2);
|
||||||
|
|
||||||
SMOKE_READER.reset();
|
smokeReader.reset();
|
||||||
lexer.read(cdc);
|
lexer.read(cdc);
|
||||||
Assertions.assertEquals(0, SMOKE_READER.errorNCRUnusedSparks);
|
Assertions.assertEquals(0, smokeReader.errorNCRUnusedSparks);
|
||||||
Assertions.assertEquals(-1, SMOKE_READER.errorNCRZeroSparks);
|
Assertions.assertEquals(-1, smokeReader.errorNCRZeroSparks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -28,10 +28,6 @@ import java.util.List;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.x4o.o2o.fc18.FourCornerDotCake;
|
import org.x4o.o2o.fc18.FourCornerDotCake;
|
||||||
import org.x4o.o2o.fc18.FourCornerUnicodeDisplay;
|
|
||||||
import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints;
|
|
||||||
import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6;
|
|
||||||
import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests four corner lexer parts.
|
* Tests four corner lexer parts.
|
||||||
|
@ -41,18 +37,17 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
||||||
*/
|
*/
|
||||||
public class LexerUNI21Test {
|
public class LexerUNI21Test {
|
||||||
|
|
||||||
final TestSmokeReader SMOKE_READER = new TestSmokeReader();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUNI21Invalid() throws Exception {
|
public void testUNI21Invalid() throws Exception {
|
||||||
|
TestSmokeReader smokeReader = new TestSmokeReader();
|
||||||
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
||||||
lexer.withSmokeSignals(SMOKE_READER);
|
lexer.withSmokeSignals(smokeReader);
|
||||||
List<Integer> cdc = new ArrayList<>();
|
List<Integer> cdc = new ArrayList<>();
|
||||||
cdc.add(FourCornerDotCake.FC_UNI2K_22.getStart() + 123);
|
cdc.add(FourCornerDotCake.FC_UNI2K_22.getStart() + 123);
|
||||||
|
|
||||||
SMOKE_READER.reset();
|
smokeReader.reset();
|
||||||
Assertions.assertEquals(-1, SMOKE_READER.errorUNI21UnusedBigIndian);
|
Assertions.assertEquals(-1, smokeReader.errorUNI21UnusedBigIndian);
|
||||||
lexer.read(cdc);
|
lexer.read(cdc);
|
||||||
Assertions.assertEquals(0, SMOKE_READER.errorUNI21UnusedBigIndian);
|
Assertions.assertEquals(0, smokeReader.errorUNI21UnusedBigIndian);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue