parse-cst.d.ts
4.41 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { Type, YAMLSyntaxError } from './util'
export default function parseCST(str: string): ParsedCST
export interface ParsedCST extends Array<CST.Document> {
setOrigRanges(): boolean
}
export namespace CST {
interface Range {
start: number
end: number
origStart?: number
origEnd?: number
isEmpty(): boolean
}
interface ParseContext {
/** Node starts at beginning of line */
atLineStart: boolean
/** true if currently in a collection context */
inCollection: boolean
/** true if currently in a flow context */
inFlow: boolean
/** Current level of indentation */
indent: number
/** Start of the current line */
lineStart: number
/** The parent of the node */
parent: Node
/** Source of the YAML document */
src: string
}
interface Node {
context: ParseContext | null
/** if not null, indicates a parser failure */
error: YAMLSyntaxError | null
/** span of context.src parsed into this node */
range: Range | null
valueRange: Range | null
/** anchors, tags and comments */
props: Range[]
/** specific node type */
type: Type
/** if non-null, overrides source value */
value: string | null
readonly anchor: string | null
readonly comment: string | null
readonly hasComment: boolean
readonly hasProps: boolean
readonly jsonLike: boolean
readonly rangeAsLinePos: null | {
start: { line: number; col: number }
end?: { line: number; col: number }
}
readonly rawValue: string | null
readonly tag:
| null
| { verbatim: string }
| { handle: string; suffix: string }
readonly valueRangeContainsNewline: boolean
}
interface Alias extends Node {
type: Type.ALIAS
/** contain the anchor without the * prefix */
readonly rawValue: string
}
type Scalar = BlockValue | PlainValue | QuoteValue
interface BlockValue extends Node {
type: Type.BLOCK_FOLDED | Type.BLOCK_LITERAL
chomping: 'CLIP' | 'KEEP' | 'STRIP'
blockIndent: number | null
header: Range
readonly strValue: string | null
}
interface BlockFolded extends BlockValue {
type: Type.BLOCK_FOLDED
}
interface BlockLiteral extends BlockValue {
type: Type.BLOCK_LITERAL
}
interface PlainValue extends Node {
type: Type.PLAIN
readonly strValue: string | null
}
interface QuoteValue extends Node {
type: Type.QUOTE_DOUBLE | Type.QUOTE_SINGLE
readonly strValue:
| null
| string
| { str: string; errors: YAMLSyntaxError[] }
}
interface QuoteDouble extends QuoteValue {
type: Type.QUOTE_DOUBLE
}
interface QuoteSingle extends QuoteValue {
type: Type.QUOTE_SINGLE
}
interface Comment extends Node {
type: Type.COMMENT
readonly anchor: null
readonly comment: string
readonly rawValue: null
readonly tag: null
}
interface BlankLine extends Node {
type: Type.BLANK_LINE
}
interface MapItem extends Node {
type: Type.MAP_KEY | Type.MAP_VALUE
node: ContentNode | null
}
interface MapKey extends MapItem {
type: Type.MAP_KEY
}
interface MapValue extends MapItem {
type: Type.MAP_VALUE
}
interface Map extends Node {
type: Type.MAP
/** implicit keys are not wrapped */
items: Array<BlankLine | Comment | Alias | Scalar | MapItem>
}
interface SeqItem extends Node {
type: Type.SEQ_ITEM
node: ContentNode | null
}
interface Seq extends Node {
type: Type.SEQ
items: Array<BlankLine | Comment | SeqItem>
}
interface FlowChar {
char: '{' | '}' | '[' | ']' | ',' | '?' | ':'
offset: number
origOffset?: number
}
interface FlowCollection extends Node {
type: Type.FLOW_MAP | Type.FLOW_SEQ
items: Array<
FlowChar | BlankLine | Comment | Alias | Scalar | FlowCollection
>
}
interface FlowMap extends FlowCollection {
type: Type.FLOW_MAP
}
interface FlowSeq extends FlowCollection {
type: Type.FLOW_SEQ
}
type ContentNode = Alias | Scalar | Map | Seq | FlowCollection
interface Directive extends Node {
type: Type.DIRECTIVE
name: string
readonly anchor: null
readonly parameters: string[]
readonly tag: null
}
interface Document extends Node {
type: Type.DOCUMENT
directives: Array<BlankLine | Comment | Directive>
contents: Array<BlankLine | Comment | ContentNode>
readonly anchor: null
readonly comment: null
readonly tag: null
}
}