docutils-ts
Version:
Port of the Python Docutils library to TypeScript
45 lines (44 loc) • 1.56 kB
JavaScript
import StateMachineWS from "../../stateMachineWS.js";
import { InvalidStateError } from "../../exceptions.js";
class NestedStateMachine extends StateMachineWS {
run(inputLines, inputOffset, runContext, inputSource, initialState, node, matchTitles = true, memo, ...rest) {
this.logger.debug('run');
if (initialState !== undefined) {
this.initialState = initialState;
}
/* istanbul ignore if */
if (matchTitles === undefined) {
this.matchTitles = true;
}
else {
this.matchTitles = matchTitles;
}
this.memo = memo;
if (memo === undefined) {
throw new InvalidStateError('need memo');
}
this.document = memo.document;
/* istanbul ignore if */
if (!this.document) {
throw new Error('need document');
}
this.attachObserver(this.document.noteSource.bind(this.document));
this.reporter = memo.reporter;
this.rstLanguage = memo.language;
this.node = node;
const results = super.run(inputLines, inputOffset);
/* istanbul ignore if */
if (results === undefined) {
throw new Error();
}
return results;
}
static createStateMachine(stateMachine, initialState = 'Body', stateFactory = stateMachine.stateFactory) {
return new NestedStateMachine({
stateFactory,
logger: stateMachine.logger,
initialState,
});
}
}
export default NestedStateMachine;