UNPKG

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