UNPKG

2.65 kBTypeScriptView Raw
1import { Directives } from '../doc/directives';
2import { Document } from '../doc/Document';
3import type { ErrorCode } from '../errors';
4import { YAMLParseError, YAMLWarning } from '../errors';
5import type { ParsedNode, Range } from '../nodes/Node';
6import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options';
7import type { Token } from '../parse/cst';
8type ErrorSource = number | [number, number] | Range | {
9 offset: number;
10 source?: string;
11};
12export type ComposeErrorHandler = (source: ErrorSource, code: ErrorCode, message: string, warning?: boolean) => void;
13/**
14 * Compose a stream of CST nodes into a stream of YAML Documents.
15 *
16 * ```ts
17 * import { Composer, Parser } from 'yaml'
18 *
19 * const src: string = ...
20 * const tokens = new Parser().parse(src)
21 * const docs = new Composer().compose(tokens)
22 * ```
23 */
24export declare class Composer<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> {
25 private directives;
26 private doc;
27 private options;
28 private atDirectives;
29 private prelude;
30 private errors;
31 private warnings;
32 constructor(options?: ParseOptions & DocumentOptions & SchemaOptions);
33 private onError;
34 private decorate;
35 /**
36 * Current stream status information.
37 *
38 * Mostly useful at the end of input for an empty stream.
39 */
40 streamInfo(): {
41 comment: string;
42 directives: Directives;
43 errors: YAMLParseError[];
44 warnings: YAMLWarning[];
45 };
46 /**
47 * Compose tokens into documents.
48 *
49 * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
50 * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
51 */
52 compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
53 /** Advance the composer by one CST token. */
54 next(token: Token): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
55 /**
56 * Call at end of input to yield any remaining document.
57 *
58 * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
59 * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
60 */
61 end(forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
62}
63export {};