118
return items;
119
}
121
>
// -- AST Node Types ----------------------------------------------------------
122
>
123
>
export interface YamlScalarNode {
124
>
readonly type: 'scalar';
125
>
readonly value: string;
126
>
readonly rawValue: string;
127
>
readonly startOffset: number;
128
>
readonly endOffset: number;
129
>
readonly format: 'single' | 'double' | 'none' | 'literal' | 'folded';
130
>
}
131
>
132
>
export interface YamlMapNode {
133
>
readonly type: 'map';
134
>
readonly properties: { key: YamlScalarNode; value: YamlNode }[];
135
>
readonly style: 'block' | 'flow';
136
>
readonly startOffset: number;
137
>
readonly endOffset: number;
138
>
}
139
>
140
>
export interface YamlSequenceNode {
141
>
readonly type: 'sequence';
142
>
readonly items: YamlNode[];
143
>
readonly style: 'block' | 'flow';
144
>
readonly startOffset: number;
145
>
readonly endOffset: number;
146
>
}
147
>
148
>
export type YamlNode = YamlSequenceNode | YamlMapNode | YamlScalarNode;
149
>
150
>
export interface YamlParseError {
151
>
readonly message: string;
152
>
readonly startOffset: number;
153
>
readonly endOffset: number;
154
>
readonly code: string;
155
>
}
156
>
157
>
export interface ParseOptions {
158
>
readonly allowDuplicateKeys?: boolean;
159
>
}
160
>
161
>
// -- Token Types -------------------------------------------------------------
162
>
163
>
const enum TokenType {
164
>
// Scalar values (unquoted, single-quoted, double-quoted)
165
>
Scalar,
166
>
// Structural tokens
167
>
Colon, // ':'
168
>
Dash, // '- '
169
>
Comma, // ','
170
>
FlowMapStart, // '{'
171
>
FlowMapEnd, // '}'
172
>
FlowSeqStart, // '['
173
>
FlowSeqEnd, // ']'
174
>
// Whitespace / structure
175
>
Newline,
176
>
Indent, // leading whitespace at start of line (carries the indent level)
177
>
Comment,
178
>
DocumentStart, // '---'
179
>
DocumentEnd, // '...'
180
>
EOF,
181
>
}
182
>
183
>
interface Token {
184
>
readonly type: TokenType;
185
>
readonly startOffset: number;
186
>
readonly endOffset: number;
187
>
/** For Scalar tokens: the raw text (including quotes). */
188
>
readonly rawValue: string;
189
>
/** For Scalar tokens: the interpreted string value. */
190
>
readonly value: string;
191
>
/** For Scalar tokens: quote style. */
192
>
readonly format: 'single' | 'double' | 'none' | 'literal' | 'folded';
193
>
/** For Indent tokens: the column (number of spaces). */
194
>
readonly indent: number;
195
>
}
196
>
197
function makeToken(
198
type: TokenType,