cst.d.ts
3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
export { createScalarToken, resolveAsScalar, setScalarValue } from './cst-scalar.js';
export { stringify } from './cst-stringify.js';
export { visit, Visitor, VisitPath } from './cst-visit.js';
export interface SourceToken {
type: 'byte-order-mark' | 'doc-mode' | 'doc-start' | 'space' | 'comment' | 'newline' | 'directive-line' | 'anchor' | 'tag' | 'seq-item-ind' | 'explicit-key-ind' | 'map-value-ind' | 'flow-map-start' | 'flow-map-end' | 'flow-seq-start' | 'flow-seq-end' | 'flow-error-end' | 'comma' | 'block-scalar-header';
offset: number;
indent: number;
source: string;
}
export interface ErrorToken {
type: 'error';
offset: number;
source: string;
message: string;
}
export interface Directive {
type: 'directive';
offset: number;
source: string;
}
export interface Document {
type: 'document';
offset: number;
start: SourceToken[];
value?: Token;
end?: SourceToken[];
}
export interface DocumentEnd {
type: 'doc-end';
offset: number;
source: string;
end?: SourceToken[];
}
export interface FlowScalar {
type: 'alias' | 'scalar' | 'single-quoted-scalar' | 'double-quoted-scalar';
offset: number;
indent: number;
source: string;
end?: SourceToken[];
}
export interface BlockScalar {
type: 'block-scalar';
offset: number;
indent: number;
props: Token[];
source: string;
}
export interface BlockMap {
type: 'block-map';
offset: number;
indent: number;
items: Array<{
start: SourceToken[];
key?: never;
sep?: never;
value?: never;
} | {
start: SourceToken[];
key: Token | null;
sep: SourceToken[];
value?: Token;
}>;
}
export interface BlockSequence {
type: 'block-seq';
offset: number;
indent: number;
items: Array<{
start: SourceToken[];
key?: never;
sep?: never;
value?: Token;
}>;
}
export declare type CollectionItem = {
start: SourceToken[];
key?: Token | null;
sep?: SourceToken[];
value?: Token;
};
export interface FlowCollection {
type: 'flow-collection';
offset: number;
indent: number;
start: SourceToken;
items: CollectionItem[];
end: SourceToken[];
}
export declare type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
export declare type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
/** The byte order mark */
export declare const BOM = "\uFEFF";
/** Start of doc-mode */
export declare const DOCUMENT = "\u0002";
/** Unexpected end of flow-mode */
export declare const FLOW_END = "\u0018";
/** Next token is a scalar value */
export declare const SCALAR = "\u001F";
/** @returns `true` if `token` is a flow or block collection */
export declare const isCollection: (token: Token | null | undefined) => token is BlockMap | BlockSequence | FlowCollection;
/** @returns `true` if `token` is a flow or block scalar; not an alias */
export declare const isScalar: (token: Token | null | undefined) => token is BlockScalar | FlowScalar;
/** Get a printable representation of a lexer token */
export declare function prettyToken(token: string): string;
/** Identify the type of a lexer token. May return `null` for unknown tokens. */
export declare function tokenType(source: string): TokenType | null;