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