UNPKG

docutils-ts

Version:

Port of the Python Docutils library to TypeScript

74 lines (73 loc) 3.51 kB
import State from './state.js'; import StateMachineWS from "../stateMachineWS.js"; import { StatemachineInterface, StateMachineFactoryFunction, RegexpResult, ContextArray, StateInterface, ParseMethodReturnType } from "../types.js"; /** * State superclass specialized for whitespace (blank lines & indents). * * Use this class with `StateMachineWS`. The transitions 'blank' (for blank * lines) and 'indent' (for indented text blocks) are added automatically, * before any other transitions. The transition method `blank()` handles * blank lines and `indent()` handles nested indented blocks. Indented * blocks trigger a new state machine to be created by `indent()` and run. * The class of the state machine to be created is in `indent_sm`, and the * constructor keyword arguments are in the dictionary `indent_sm_kwargs`. * * The methods `known_indent()` and `firstknown_indent()` are provided for * indented blocks where the indent (all lines' and first line's only, * respectively) is known to the transition method, along with the attributes * `known_indent_sm` and `known_indent_sm_kwargs`. Neither transition method * is triggered automatically. * */ declare class StateWS extends State { /** * The `StateMachine` class handling indented text blocks. * * If left as ``None``, `indent_sm` defaults to the value of * `State.nested_sm`. Override it in subclasses to avoid the default. */ /** * Keyword arguments dictionary, passed to the `indent_sm` constructor. * * If left as ``None``, `indent_sm_kwargs` defaults to the value of * `State.nested_sm_kwargs`. Override it in subclasses to avoid the default. **/ /** * The `StateMachine` class handling known-indented text blocks. * * If left as ``None``, `known_indent_sm` defaults to the value of * `indent_sm`. Override it in subclasses to avoid the default. */ /** * Keyword arguments dictionary, passed to the `known_indent_sm` constructor. * * If left as ``None``, `known_indent_sm_kwargs` defaults to the value of * `indent_sm_kwargs`. Override it in subclasses to avoid the default. */ /** Patterns for default whitespace transitions. May be overridden in subclasses. */ private wsPatterns; /** * Default initial whitespace transitions, added before those listed in * `State.initial_transitions`. May be overridden in subclasses. */ private wsInitialTransitions; private wsStateMachine; private debugFn; createIndentedStateMachine: StateMachineFactoryFunction<StatemachineInterface> | undefined; constructor(stateMachine: StateMachineWS, debug?: boolean); addInitialTransitions(): void; blank(match: RegexpResult, context: ContextArray, nextState: StateInterface): any; indent(match: RegexpResult, context: ContextArray, nextState: StateInterface): ParseMethodReturnType; knownIndent(match: RegexpResult, context: ContextArray, nextState: StateInterface): ParseMethodReturnType; /** * Handle an indented text block (first line's indent known). * * Extend or override in subclasses. * * Recursively run the registered state machine for known-indent indented * blocks (`self.known_indent_sm`). The indent is the length of the * match, ``match.end()``. */ firstKnownIndent(match: RegexpResult, context: ContextArray, nextState: StateInterface): ParseMethodReturnType; } export default StateWS;