FC18: Fixed lexer missing error if first char and add NCR encoding

This commit is contained in:
Willem Cazander 2025-08-04 16:55:43 +02:00
parent 144d331f88
commit 6b8d281e40
6 changed files with 164 additions and 20 deletions

View file

@ -268,7 +268,9 @@ public class FourCornerUnicodeDisplay {
if (failPipeSmoke) {
throw new IllegalStateException(errBuf.toString());
} else {
output.append("[");
output.append(errBuf);
output.append("]");
}
}
}

View file

@ -168,6 +168,45 @@ public enum FourCornerUnicodeMapper {
return result;
}
// todo move...
public List<Integer> embedNCR1632Denominator(BigInteger value) {
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XD.getStart());
}
// todo move...
public List<Integer> embedNCR1632Numerator(BigInteger value) {
return embedNCR1632Value(value, FourCornerDotCake.FC_NCR1632_XN.getStart());
}
// todo move...
private List<Integer> embedNCR1632Value(BigInteger value, int bankStart) {
if (value.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("The value ZERO is not allowed.");
}
List<Integer> result = new ArrayList<>();
BigInteger valueZero = value.subtract(BigInteger.ONE);
if (valueZero.equals(BigInteger.ZERO)) {
result.add(bankStart);
return result;
}
BigInteger pageSize = BigInteger.valueOf(0x1FF);
BigInteger reminder = valueZero;
for (int i = 63; i >= 0; i--) {
int bankValue = valueZero.shiftRight(i * 9).and(pageSize).intValue();
if (bankValue == 0) {
continue;
}
int cakePoint = bankStart + bankValue + (i * 512);
result.add(cakePoint);
reminder = reminder.subtract(BigInteger.valueOf(bankValue).shiftLeft(i * 9));
}
if (!reminder.equals(BigInteger.ZERO)) {
throw new IllegalArgumentException("value is larger than 576 bit allowed: " + reminder + " of " + value);
}
return result;
}
public List<FourCornerX18CakePointDotIndex> toScriptSuper(int value) {
return toScript(Integer.toString(value), 0);
}

View file

@ -26,6 +26,7 @@ import java.math.BigInteger;
import java.util.List;
import java.util.Objects;
import org.x4o.fc18.FourCornerUnicodeMapper;
import org.x4o.fc18.cake2.zero33.dec1.FCDotDEC2701DashPX0;
import org.x4o.fc18.octal8.PrimordialOctal;
@ -63,6 +64,8 @@ public class FourCornerZionStenoGrapher {
@Override
public void strobeNCR1632(BigInteger denominator, BigInteger numerator) {
out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Denominator(denominator));
out.addAll(FourCornerUnicodeMapper.DICTIONARY.embedNCR1632Numerator(numerator));
}
@Override

View file

@ -59,7 +59,7 @@ public class FourCornerZionStenoLexer {
private final FourCornerZion7WaterCodex handlerCodex;
private final FourCornerZion7SalahSequence handlerSalahSequence;
private final FourCornerZion7TempleScrolls handlerTempleScrolls;
private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group
private final int denominatorBank[] = new int[64]; // <== is the terminator select per 9 bit group of 9 bit values
private final int numeratorBank[] = new int[denominatorBank.length];
private List<Integer> input;
private int inputIndex = 0;
@ -175,22 +175,15 @@ public class FourCornerZionStenoLexer {
decModeReset();
ncrBankResetSilent();
handlerDocument.strobeDocumentAlpha();
while (true) {
ScanResult run = ScanResult.DONE;
while (run.isDone()) {
run = readTokens(); // FIXME: remove triple looper to ones here
if (run.isEOF()) {
break;
}
break;
}
do {
ScanResult run = readTokens();
if (run.isEOF()) {
break;
}
if (!run.isDone()) {
smokeSignals.burnLexerReservedCakePoint(currLine, currCol, input.get(inputIndex));
}
}
} while (safeNext());
handlerDocument.strobeDocumentOmega();
}
@ -207,9 +200,6 @@ public class FourCornerZionStenoLexer {
return result;
}
}
if (!safeNext()) {
return ScanResult.EOF;
}
return result;
}
@ -288,6 +278,7 @@ public class FourCornerZionStenoLexer {
while (true) {
int cakePoint = lexer.input.get(lexer.inputIndex);
if (cakePoint < blockStart || cakePoint > blockStop) {
lexer.inputIndex--; // go back one, this is other steno segment
break;
}
idxLast = lexer.inputIndex;
@ -426,6 +417,8 @@ public class FourCornerZionStenoLexer {
static class StenoScannerNCR18 extends StenoScanner {
static private final int CAKEPOINT_BANK0_END = FourCornerDotCake.FC_NCR1632_XN.getStart() + 512;
public StenoScannerNCR18() {
super(FourCornerDotCake.FC_NCR1632_XD.getStart(), FourCornerDotCake.FC_NCR1632_XN.getStop());
}
@ -457,7 +450,7 @@ public class FourCornerZionStenoLexer {
} else {
requestBankReset = false;
}
if (cakePoint > FourCornerDotCake.FC_NCR1632_XN.getStart() + 512) {
if (cakePoint > CAKEPOINT_BANK0_END) {
magicSparkler = true;
continue; // Only fire fraction on lowest value select
}