diff --git a/src/common/parser/DcsParser.ts b/src/common/parser/DcsParser.ts index 6b5ddd6e..b66524ba 100644 --- a/src/common/parser/DcsParser.ts +++ b/src/common/parser/DcsParser.ts @@ -4,7 +4,7 @@ */ import { IDisposable } from 'common/Types'; -import { IDcsHandler, IParams, IHandlerCollection, IDcsParser, DcsFallbackHandlerType } from 'common/parser/Types'; +import { IDcsHandler, IParams, IHandlerCollection, IDcsParser, DcsFallbackHandlerType, ISubParserStackState } from 'common/parser/Types'; import { utf32ToString } from 'common/input/TextDecoder'; import { Params } from 'common/parser/Params'; import { PAYLOAD_LIMIT } from 'common/parser/Constants'; @@ -16,6 +16,11 @@ export class DcsParser implements IDcsParser { private _active: IDcsHandler[] = EMPTY_HANDLERS; private _ident: number = 0; private _handlerFb: DcsFallbackHandlerType = () => { }; + private _stack: ISubParserStackState = { + paused: false, + loopPosition: 0, + fallThrough: false + }; public dispose(): void { this._handlers = Object.create(null); @@ -83,11 +88,6 @@ export class DcsParser implements IDcsParser { } } - private _stack = { - paused: false, - loopPosition: 0, - fallThrough: false - }; public unhook(success: boolean, promiseResult: boolean = true): void | Promise { if (!this._active.length) { this._handlerFb(this._ident, 'UNHOOK', success); diff --git a/src/common/parser/EscapeSequenceParser.ts b/src/common/parser/EscapeSequenceParser.ts index c1d80c5c..f20a7e91 100644 --- a/src/common/parser/EscapeSequenceParser.ts +++ b/src/common/parser/EscapeSequenceParser.ts @@ -253,6 +253,15 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP protected _escHandlerFb: EscFallbackHandlerType; protected _errorHandlerFb: (state: IParsingState) => IParsingState; + // parser stack save for async handler support + protected _parseStack: IParserStackState = { + state: ParserStackType.NONE, + handlers: [], + handlerPos: 0, + transition: 0, + chunkPos: 0 + }; + constructor( protected readonly _transitions: TransitionTable = VT500_TRANSITION_TABLE ) { @@ -456,13 +465,6 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP /** * Async parse support. */ - protected _parseStack: IParserStackState = { - state: ParserStackType.NONE, - handlers: [], - handlerPos: 0, - transition: 0, - chunkPos: 0 - }; protected _preserveStack( state: ParserStackType, handlers: ResumableHandlersType, diff --git a/src/common/parser/OscParser.ts b/src/common/parser/OscParser.ts index f043bd82..32710aed 100644 --- a/src/common/parser/OscParser.ts +++ b/src/common/parser/OscParser.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IOscHandler, IHandlerCollection, OscFallbackHandlerType, IOscParser } from 'common/parser/Types'; +import { IOscHandler, IHandlerCollection, OscFallbackHandlerType, IOscParser, ISubParserStackState } from 'common/parser/Types'; import { OscState, PAYLOAD_LIMIT } from 'common/parser/Constants'; import { utf32ToString } from 'common/input/TextDecoder'; import { IDisposable } from 'common/Types'; @@ -16,6 +16,11 @@ export class OscParser implements IOscParser { private _id = -1; private _handlers: IHandlerCollection = Object.create(null); private _handlerFb: OscFallbackHandlerType = () => { }; + private _stack: ISubParserStackState = { + paused: false, + loopPosition: 0, + fallThrough: false + }; public registerHandler(ident: number, handler: IOscHandler): IDisposable { if (this._handlers[ident] === undefined) { @@ -119,12 +124,6 @@ export class OscParser implements IOscParser { } } - private _stack = { - paused: false, - loopPosition: 0, - fallThrough: false - }; - /** * Indicates end of an OSC command. * Whether the OSC got aborted or finished normally diff --git a/src/common/parser/Types.d.ts b/src/common/parser/Types.d.ts index 26a02e83..3a621eab 100644 --- a/src/common/parser/Types.d.ts +++ b/src/common/parser/Types.d.ts @@ -242,6 +242,8 @@ export interface IHandlerCollection { /** * Types for async parser support. */ + +// type of saved stack state in parser export const enum ParserStackType { NONE = 0, FAIL, @@ -251,7 +253,11 @@ export const enum ParserStackType { OSC, DCS } + +// aggregate of resumable handler lists export type ResumableHandlersType = CsiHandlerType[] | EscHandlerType[]; + +// saved stack state of the parser export interface IParserStackState { state: ParserStackType; handlers: ResumableHandlersType; @@ -259,3 +265,10 @@ export interface IParserStackState { transition: number; chunkPos: number; } + +// saved stack state of subparser (OSC and DCS) +export interface ISubParserStackState { + paused: boolean; + loopPosition: number; + fallThrough: boolean; +}