Updated index naming and moved NCR bank reset to state level
This commit is contained in:
parent
4454a4d322
commit
3c4adb03df
|
@ -204,6 +204,25 @@ public class FourCornerZionStenoLexer {
|
|||
return true;
|
||||
}
|
||||
|
||||
private void ncrBankReset() {
|
||||
for (int i = 0; i < denominatorBank.length; i++) {
|
||||
denominatorBank[i] = 0;
|
||||
numeratorBank[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void ncrBankFire() {
|
||||
BigInteger denominator = BigInteger.ONE;
|
||||
for (int i = 0; i < denominatorBank.length; i++) {
|
||||
denominator = denominator.add(BigInteger.valueOf(denominatorBank[i]).shiftLeft(i * 9));
|
||||
}
|
||||
BigInteger numerator = BigInteger.ONE;
|
||||
for (int i = 0; i < numeratorBank.length; i++) {
|
||||
numerator = numerator.add(BigInteger.valueOf(numeratorBank[i]).shiftLeft(i * 9));
|
||||
}
|
||||
handler.strobeNCR1632(denominator, numerator);
|
||||
}
|
||||
|
||||
abstract static private class StenoScanner {
|
||||
|
||||
protected final int blockStart;
|
||||
|
@ -223,29 +242,29 @@ public class FourCornerZionStenoLexer {
|
|||
if (cakePoint < blockStart || cakePoint > blockStop) {
|
||||
return ScanResult.NEXT;
|
||||
}
|
||||
lexer.fireSignals.fireStateScanner(blockStart, blockStop, cakePoint); // TODO: move below and add idxStart/stop + next
|
||||
lexer.fireSignals.fireStateScanner(blockStart, blockStop, cakePoint); // TODO: move below and add idxFirst/stop + next
|
||||
ScanResult result = ScanResult.DONE;
|
||||
int idxStart = lexer.inputIndex;
|
||||
int idxStop = lexer.inputIndex;
|
||||
int idxFirst = lexer.inputIndex;
|
||||
int idxLast = lexer.inputIndex;
|
||||
|
||||
while (true) {
|
||||
cakePoint = lexer.input.get(lexer.inputIndex);
|
||||
if (cakePoint < blockStart || cakePoint > blockStop) {
|
||||
break;
|
||||
}
|
||||
idxStop = lexer.inputIndex;
|
||||
idxLast = lexer.inputIndex;
|
||||
if (lexer.safeNext() == false) {
|
||||
result = ScanResult.EOF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//System.out.println("PROCESS: " + lexer.input.size() + " start: " + idxStart + " stop: " + idxStop + " currenId: " + lexer.inputIndex);
|
||||
//System.out.println("PROCESS: " + lexer.input.size() + " start: " + idxFirst + " stop: " + idxLast + " currenId: " + lexer.inputIndex);
|
||||
|
||||
process(lexer, idxStart, idxStop);
|
||||
process(lexer, idxFirst, idxLast);
|
||||
return result;
|
||||
}
|
||||
|
||||
abstract void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop);
|
||||
abstract void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast);
|
||||
}
|
||||
|
||||
static class StenoScannerWordCakeSlice extends StenoScanner {
|
||||
|
@ -258,8 +277,8 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) {
|
||||
List<Integer> offsets = lexer.input.subList(idxStart, idxStop + 1);
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
List<Integer> offsets = lexer.input.subList(idxFirst, idxLast + 1); // List.subList is an exclusive "indexTo" argument
|
||||
for (int i = 0; i < offsets.size(); i++) {
|
||||
offsets.set(i, offsets.get(i) - blockStart);
|
||||
}
|
||||
|
@ -274,7 +293,7 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) {
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
}
|
||||
|
||||
private void handlePoints(FourCornerZionStenoLexer lexer, List<Integer> slicedPoints) {
|
||||
|
@ -290,11 +309,11 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) {
|
||||
bankReset(lexer);
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
lexer.ncrBankReset();
|
||||
boolean magicSparkler = true;
|
||||
boolean requestBankReset = false;
|
||||
for (int i = idxStart; i <= idxStop; i++) {
|
||||
for (int i = idxFirst; i <= idxLast; i++) {
|
||||
int cakePoint = lexer.input.get(i);
|
||||
if (cakePoint >= FourCornerDotCake.FC_NCR1632_XD.getStart() && cakePoint <= FourCornerDotCake.FC_NCR1632_XD.getStop()) {
|
||||
int denominatorX = cakePoint - FourCornerDotCake.FC_NCR1632_XD.getStart();
|
||||
|
@ -310,7 +329,7 @@ public class FourCornerZionStenoLexer {
|
|||
if (requestBankReset) {
|
||||
requestBankReset = false;
|
||||
lexer.fireSignals.fireStateNCR1632BankReset();
|
||||
bankReset(lexer);
|
||||
lexer.ncrBankReset();
|
||||
magicSparkler = false; // if block ends with bank reset, don't leak a sparkler
|
||||
continue;
|
||||
}
|
||||
|
@ -323,33 +342,14 @@ public class FourCornerZionStenoLexer {
|
|||
magicSparkler = true;
|
||||
continue; // Only fire fraction on lowest value select
|
||||
} else
|
||||
bankFire(lexer);
|
||||
lexer.ncrBankFire();
|
||||
magicSparkler = false;
|
||||
}
|
||||
if (magicSparkler) {
|
||||
lexer.fireSignals.fireStateNCR1632BankSparkler();
|
||||
bankFire(lexer);
|
||||
lexer.ncrBankFire();
|
||||
}
|
||||
}
|
||||
|
||||
private void bankReset(FourCornerZionStenoLexer lexer) {
|
||||
for (int i = 0; i < lexer.denominatorBank.length; i++) {
|
||||
lexer.denominatorBank[i] = 0;
|
||||
lexer.numeratorBank[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void bankFire(FourCornerZionStenoLexer lexer) {
|
||||
BigInteger denominator = BigInteger.ONE;
|
||||
for (int i = 0; i < lexer.denominatorBank.length; i++) {
|
||||
denominator = denominator.add(BigInteger.valueOf(lexer.denominatorBank[i]).shiftLeft(i * 9));
|
||||
}
|
||||
BigInteger numerator = BigInteger.ONE;
|
||||
for (int i = 0; i < lexer.numeratorBank.length; i++) {
|
||||
numerator = numerator.add(BigInteger.valueOf(lexer.numeratorBank[i]).shiftLeft(i * 9));
|
||||
}
|
||||
lexer.handler.strobeNCR1632(denominator, numerator);
|
||||
}
|
||||
}
|
||||
|
||||
static class StenoScannerUNI21 extends StenoScanner {
|
||||
|
@ -359,11 +359,11 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) {
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
boolean errorUnusedBigIndian = false; // are optional
|
||||
List<Integer> result = new ArrayList<>();
|
||||
int codePoint22 = 0;
|
||||
for (int i = idxStart; i <= idxStop; i++) {
|
||||
for (int i = idxFirst; i <= idxLast; i++) {
|
||||
int cakePoint = lexer.input.get(i);
|
||||
if (cakePoint >= FourCornerDotCake.FC_UNI2K_22.getStart() && cakePoint <= FourCornerDotCake.FC_UNI2K_22.getStop()) {
|
||||
codePoint22 = cakePoint - FourCornerDotCake.FC_UNI2K_22.getStart();
|
||||
|
@ -398,12 +398,12 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxStart, int idxStop) {
|
||||
public void process(FourCornerZionStenoLexer lexer, int idxFirst, int idxLast) {
|
||||
numberMode = null;
|
||||
numberPIE = true;
|
||||
scanIndex = idxStart;
|
||||
scanIndexEnd = idxStop;
|
||||
for (scanIndex = idxStart; scanIndex <= idxStop; scanIndex++) {
|
||||
scanIndex = idxFirst;
|
||||
scanIndexEnd = idxLast;
|
||||
for (scanIndex = idxFirst; scanIndex <= idxLast; scanIndex++) {
|
||||
int cdcDECPoint = lexer.input.get(scanIndex);
|
||||
// Log state changes
|
||||
if (FCDotCDC1604DashP6._NEWLINE.ordinal() == cdcDECPoint) {
|
||||
|
@ -422,7 +422,7 @@ public class FourCornerZionStenoLexer {
|
|||
continue;
|
||||
}
|
||||
|
||||
// Handle 6 bit CDC and DEC codes
|
||||
// Handle 6 bit CDC and 6/8/18 bit DEC codes
|
||||
handleCDCDEC(lexer, cdcDECPoint, null);
|
||||
}
|
||||
}
|
||||
|
@ -430,10 +430,9 @@ public class FourCornerZionStenoLexer {
|
|||
private FCDotDEC0127DashPX0 readEscape6(FourCornerZionStenoLexer lexer, int cdcPoint1) {
|
||||
// Read 8 or 18 bit Direct Escape Code
|
||||
if (FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint1)) {
|
||||
System.out.println("readEscape6 upper : " + cdcPoint1);
|
||||
return FCDotDEC0127DashPX0.valueOfCakePoint(cdcPoint1);
|
||||
}
|
||||
// Read 6 bit escape code
|
||||
// Read 6 bit escape sequence
|
||||
FCDotCDC1604DashP6 x1 = FCDotCDC1604DashP6.valueOf(cdcPoint1);
|
||||
FCDotCDC1604DashP6 x2 = null;
|
||||
FCDotCDC1604DashP6 x3 = null;
|
||||
|
@ -460,7 +459,6 @@ public class FourCornerZionStenoLexer {
|
|||
return FCDotDEC0127DashPX0.valueOf(x1, x2, x3);
|
||||
}
|
||||
|
||||
/// note; cdcPoint is always CDC or direct DEC escape code
|
||||
private void handleCDCDEC(FourCornerZionStenoLexer lexer, int cdcPoint, FCDotDEC0127DashPX0 startMode) {
|
||||
|
||||
// TODO: make simple
|
||||
|
@ -555,7 +553,6 @@ public class FourCornerZionStenoLexer {
|
|||
if (numberMode == null) {
|
||||
Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint);
|
||||
if (slice.isEmpty()) {
|
||||
System.out.println("No slice for point: " + Integer.toHexString(cdcPoint));
|
||||
lexer.smokeSignals.burnUnsupported(lexer.currLine, lexer.currCol, cdcPoint);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue