UNPKG

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