Change ordering in escapeSequnceParser.ts

This commit is contained in:
Anthony Kim
2026-01-21 11:29:04 -08:00
parent 5ecd980a83
commit 42d408a9a7
3 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ export const enum ParserState {
CSI_PARAM = 4,
CSI_INTERMEDIATE = 5,
CSI_IGNORE = 6,
SOS_PM_APC_STRING = 7,
SOS_PM_STRING = 7,
OSC_STRING = 8,
DCS_ENTRY = 9,
DCS_PARAM = 10,
@@ -156,7 +156,7 @@ const states: number[] = [
ParserState.CSI_PARAM,
ParserState.CSI_INTERMEDIATE,
ParserState.CSI_IGNORE,
ParserState.SOS_PM_APC_STRING,
ParserState.SOS_PM_STRING,
ParserState.OSC_STRING,
ParserState.DCS_ENTRY,
ParserState.DCS_PARAM,
@@ -703,13 +703,13 @@ describe('EscapeSequenceParser', () => {
testTerminal.clear();
}
});
it('trans ANYWHERE/ESCAPE --> SOS_PM_APC_STRING', () => {
it('trans ANYWHERE/ESCAPE --> SOS_PM_STRING', () => {
parser.reset();
// C0 (only SOS and PM, APC has separate handling)
let initializers = ['\x58', '\x5e'];
for (let i = 0; i < initializers.length; ++i) {
parse(parser, '\x1b' + initializers[i]);
assert.equal(parser.currentState, ParserState.SOS_PM_APC_STRING);
assert.equal(parser.currentState, ParserState.SOS_PM_STRING);
parser.reset();
}
// C1 (only SOS and PM, APC has separate handling)
@@ -718,7 +718,7 @@ describe('EscapeSequenceParser', () => {
initializers = ['\x98', '\x9e'];
for (let i = 0; i < initializers.length; ++i) {
parse(parser, initializers[i]);
assert.equal(parser.currentState, ParserState.SOS_PM_APC_STRING);
assert.equal(parser.currentState, ParserState.SOS_PM_STRING);
parser.reset();
}
}
@@ -737,16 +737,16 @@ describe('EscapeSequenceParser', () => {
parser.reset();
}
});
it('state SOS_PM_APC_STRING ignore rules', () => {
it('state SOS_PM_STRING ignore rules', () => {
parser.reset();
let ignored = r(0x00, 0x18);
ignored = ignored.concat(['\x19']);
ignored = ignored.concat(r(0x1c, 0x20));
ignored = ignored.concat(r(0x20, 0x80));
for (let i = 0; i < ignored.length; ++i) {
parser.currentState = ParserState.SOS_PM_APC_STRING;
parser.currentState = ParserState.SOS_PM_STRING;
parse(parser, ignored[i]);
assert.equal(parser.currentState, ParserState.SOS_PM_APC_STRING);
assert.equal(parser.currentState, ParserState.SOS_PM_STRING);
parser.reset();
}
});
+13 -13
View File
@@ -105,7 +105,7 @@ export const VT500_TRANSITION_TABLE = (function(): TransitionTable {
table.add(0x9c, state, ParserAction.IGNORE, ParserState.GROUND); // ST as terminator
table.add(0x1b, state, ParserAction.CLEAR, ParserState.ESCAPE); // ESC
table.add(0x9d, state, ParserAction.OSC_START, ParserState.OSC_STRING); // OSC
table.addMany([0x98, 0x9e], state, ParserAction.IGNORE, ParserState.SOS_PM_APC_STRING); // SOS, PM
table.addMany([0x98, 0x9e], state, ParserAction.IGNORE, ParserState.SOS_PM_STRING); // SOS, PM
table.add(0x9f, state, ParserAction.APC_START, ParserState.APC_STRING); // APC
table.add(0x9b, state, ParserAction.CLEAR, ParserState.CSI_ENTRY); // CSI
table.add(0x90, state, ParserAction.CLEAR, ParserState.DCS_ENTRY); // DCS
@@ -130,13 +130,18 @@ export const VT500_TRANSITION_TABLE = (function(): TransitionTable {
table.add(0x7f, ParserState.OSC_STRING, ParserAction.OSC_PUT, ParserState.OSC_STRING);
table.addMany([0x9c, 0x1b, 0x18, 0x1a, 0x07], ParserState.OSC_STRING, ParserAction.OSC_END, ParserState.GROUND);
table.addMany(r(0x1c, 0x20), ParserState.OSC_STRING, ParserAction.IGNORE, ParserState.OSC_STRING);
// sos/pm/apc - sos/pm does nothing, apc gets separate handling
table.addMany([0x58, 0x5e], ParserState.ESCAPE, ParserAction.IGNORE, ParserState.SOS_PM_APC_STRING); // SOS, PM
table.add(0x5f, ParserState.ESCAPE, ParserAction.APC_START, ParserState.APC_STRING); // APC ('_')
table.addMany(PRINTABLES, ParserState.SOS_PM_APC_STRING, ParserAction.IGNORE, ParserState.SOS_PM_APC_STRING);
table.addMany(EXECUTABLES, ParserState.SOS_PM_APC_STRING, ParserAction.IGNORE, ParserState.SOS_PM_APC_STRING);
table.add(0x9c, ParserState.SOS_PM_APC_STRING, ParserAction.IGNORE, ParserState.GROUND);
table.add(0x7f, ParserState.SOS_PM_APC_STRING, ParserAction.IGNORE, ParserState.SOS_PM_APC_STRING);
// sos/pm
table.addMany([0x58, 0x5e], ParserState.ESCAPE, ParserAction.IGNORE, ParserState.SOS_PM_STRING);
table.addMany(PRINTABLES, ParserState.SOS_PM_STRING, ParserAction.IGNORE, ParserState.SOS_PM_STRING);
table.addMany(EXECUTABLES, ParserState.SOS_PM_STRING, ParserAction.IGNORE, ParserState.SOS_PM_STRING);
table.add(0x9c, ParserState.SOS_PM_STRING, ParserAction.IGNORE, ParserState.GROUND);
table.add(0x7f, ParserState.SOS_PM_STRING, ParserAction.IGNORE, ParserState.SOS_PM_STRING);
// apc
table.add(0x5f, ParserState.ESCAPE, ParserAction.APC_START, ParserState.APC_STRING);
table.addMany(PRINTABLES, ParserState.APC_STRING, ParserAction.APC_PUT, ParserState.APC_STRING);
table.addMany(EXECUTABLES, ParserState.APC_STRING, ParserAction.IGNORE, ParserState.APC_STRING);
table.add(0x7f, ParserState.APC_STRING, ParserAction.IGNORE, ParserState.APC_STRING);
table.addMany([0x1b, 0x9c, 0x18, 0x1a], ParserState.APC_STRING, ParserAction.APC_END, ParserState.GROUND);
// csi entries
table.add(0x5b, ParserState.ESCAPE, ParserAction.CLEAR, ParserState.CSI_ENTRY);
table.addMany(r(0x40, 0x7f), ParserState.CSI_ENTRY, ParserAction.CSI_DISPATCH, ParserState.GROUND);
@@ -190,11 +195,6 @@ export const VT500_TRANSITION_TABLE = (function(): TransitionTable {
table.addMany(PRINTABLES, ParserState.DCS_PASSTHROUGH, ParserAction.DCS_PUT, ParserState.DCS_PASSTHROUGH);
table.add(0x7f, ParserState.DCS_PASSTHROUGH, ParserAction.IGNORE, ParserState.DCS_PASSTHROUGH);
table.addMany([0x1b, 0x9c, 0x18, 0x1a], ParserState.DCS_PASSTHROUGH, ParserAction.DCS_UNHOOK, ParserState.GROUND);
// apc passthrough - similar to DCS passthrough
table.addMany(PRINTABLES, ParserState.APC_STRING, ParserAction.APC_PUT, ParserState.APC_STRING);
table.addMany(EXECUTABLES, ParserState.APC_STRING, ParserAction.IGNORE, ParserState.APC_STRING);
table.add(0x7f, ParserState.APC_STRING, ParserAction.IGNORE, ParserState.APC_STRING);
table.addMany([0x1b, 0x9c, 0x18, 0x1a], ParserState.APC_STRING, ParserAction.APC_END, ParserState.GROUND);
// special handling of unicode chars
table.add(NON_ASCII_PRINTABLE, ParserState.GROUND, ParserAction.PRINT, ParserState.GROUND);
table.add(NON_ASCII_PRINTABLE, ParserState.OSC_STRING, ParserAction.OSC_PUT, ParserState.OSC_STRING);