ts-graphviz 1.5.5-dev.bdbba8a60 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/adapter/browser/index.cjs +0 -11
- package/lib/adapter/browser/index.js +0 -11
- package/lib/adapter/deno/mod.js +2 -2
- package/lib/adapter/node/index.cjs +1 -13
- package/lib/adapter/node/index.js +2 -14
- package/lib/adapter/types/index.d.ts +15 -0
- package/lib/adapter/utils/index.cjs +5 -4
- package/lib/adapter/utils/index.d.ts +8 -2
- package/lib/adapter/utils/index.js +5 -4
- package/lib/ast/index.cjs +0 -47
- package/lib/ast/index.d.ts +328 -17
- package/lib/ast/index.js +0 -47
- package/lib/common/index.cjs +0 -17
- package/lib/common/index.d.ts +13 -0
- package/lib/common/index.js +0 -17
- package/lib/core/index.cjs +0 -75
- package/lib/core/index.d.ts +35 -9
- package/lib/core/index.js +0 -75
- package/package.json +120 -120
package/lib/ast/index.d.ts
CHANGED
|
@@ -11,65 +11,121 @@ import {
|
|
|
11
11
|
} from '../common/index.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
+
* The FilePosition interface represents the position of a file in terms of its offset, line number, and column number.
|
|
15
|
+
*
|
|
14
16
|
* @group AST
|
|
15
17
|
*/
|
|
16
18
|
interface FilePosition$1 {
|
|
19
|
+
/**
|
|
20
|
+
* The offset of the file.
|
|
21
|
+
*/
|
|
17
22
|
offset: number;
|
|
23
|
+
/**
|
|
24
|
+
* The line number of the file.
|
|
25
|
+
*/
|
|
18
26
|
line: number;
|
|
27
|
+
/**
|
|
28
|
+
* The column number of the file.
|
|
29
|
+
*/
|
|
19
30
|
column: number;
|
|
20
31
|
}
|
|
21
32
|
/**
|
|
33
|
+
* FileRange interface represents a range of positions within a file.
|
|
22
34
|
* @group AST
|
|
23
35
|
*/
|
|
24
36
|
interface FileRange$1 {
|
|
37
|
+
/**
|
|
38
|
+
* The start position of the range.
|
|
39
|
+
*/
|
|
25
40
|
start: FilePosition$1;
|
|
41
|
+
/**
|
|
42
|
+
* The end position of the range.
|
|
43
|
+
*/
|
|
26
44
|
end: FilePosition$1;
|
|
27
45
|
}
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
47
|
+
* This interface provides common properties to be used across all abstract syntax tree (AST) objects.
|
|
48
|
+
*
|
|
30
49
|
* @group AST
|
|
31
50
|
*/
|
|
32
51
|
interface ASTCommonPropaties {
|
|
52
|
+
/**
|
|
53
|
+
* The start and end location of the AST object.
|
|
54
|
+
*/
|
|
33
55
|
location?: FileRange$1;
|
|
34
56
|
}
|
|
35
57
|
/**
|
|
58
|
+
* This interface represents the properties of a dot AST node.
|
|
36
59
|
* @group AST
|
|
37
60
|
*/
|
|
38
|
-
|
|
61
|
+
interface DotASTPropaties extends ASTCommonPropaties {}
|
|
39
62
|
/**
|
|
63
|
+
* This interface defines the properties of a Graph AST Node.
|
|
40
64
|
* @group AST
|
|
41
65
|
*/
|
|
42
66
|
interface GraphASTPropaties extends ASTCommonPropaties {
|
|
67
|
+
/**
|
|
68
|
+
* An optional identifier for the Graph AST Node.
|
|
69
|
+
*/
|
|
43
70
|
id?: LiteralASTNode;
|
|
71
|
+
/**
|
|
72
|
+
* A boolean indicating whether the graph is directed.
|
|
73
|
+
*/
|
|
44
74
|
directed: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* A boolean indicating whether the graph is strict.
|
|
77
|
+
*/
|
|
45
78
|
strict: boolean;
|
|
46
79
|
}
|
|
47
80
|
/**
|
|
81
|
+
* LiteralASTPropaties defines interface for literal AST nodes.
|
|
82
|
+
*
|
|
48
83
|
* @group AST
|
|
49
84
|
*/
|
|
50
85
|
interface LiteralASTPropaties<T extends string = string> extends ASTCommonPropaties {
|
|
86
|
+
/**
|
|
87
|
+
* The value of the literal.
|
|
88
|
+
*/
|
|
51
89
|
value: T;
|
|
90
|
+
/**
|
|
91
|
+
* A flag indicating whether the literal was quoted or not.
|
|
92
|
+
* If 'html' then the literal is an html like value.
|
|
93
|
+
*/
|
|
52
94
|
quoted: boolean | 'html';
|
|
53
95
|
}
|
|
54
96
|
/**
|
|
97
|
+
* SubgraphASTPropaties describes the properties of an AST node representing a subgraph.
|
|
55
98
|
* @group AST
|
|
56
99
|
*/
|
|
57
100
|
interface SubgraphASTPropaties extends ASTCommonPropaties {
|
|
101
|
+
/**
|
|
102
|
+
* id is an optional {@link LiteralASTNode} that represents the identifier of the subgraph.
|
|
103
|
+
*/
|
|
58
104
|
id?: LiteralASTNode;
|
|
59
105
|
}
|
|
60
106
|
/**
|
|
107
|
+
* SubgraphASTPropaties describes the properties of an AST node representing a node.
|
|
61
108
|
* @group AST
|
|
62
109
|
*/
|
|
63
110
|
interface NodeASTPropaties extends ASTCommonPropaties {
|
|
111
|
+
/**
|
|
112
|
+
* The unique identifier of the node.
|
|
113
|
+
*/
|
|
64
114
|
id: LiteralASTNode;
|
|
65
115
|
}
|
|
66
116
|
/**
|
|
117
|
+
* EdgeASTPropaties is an interface that defines the properties of an {@link EdgeASTNode}.
|
|
67
118
|
* @group AST
|
|
68
119
|
*/
|
|
69
120
|
interface EdgeASTPropaties extends ASTCommonPropaties {
|
|
121
|
+
/**
|
|
122
|
+
* An array of EdgeTargetASTNodes.
|
|
123
|
+
* The {@link EdgeTargetASTNode} represents a node that is the target of an edge.
|
|
124
|
+
*/
|
|
70
125
|
targets: [from: EdgeTargetASTNode, to: EdgeTargetASTNode, ...rest: EdgeTargetASTNode[]];
|
|
71
126
|
}
|
|
72
127
|
/**
|
|
128
|
+
* NodeRefASTPropaties is an interface that defines the properties of a {@link NodeRefASTNode}.
|
|
73
129
|
* @group AST
|
|
74
130
|
*/
|
|
75
131
|
interface NodeRefASTPropaties extends ASTCommonPropaties {
|
|
@@ -78,10 +134,12 @@ interface NodeRefASTPropaties extends ASTCommonPropaties {
|
|
|
78
134
|
compass?: LiteralASTNode<Compass>;
|
|
79
135
|
}
|
|
80
136
|
/**
|
|
137
|
+
* NodeRefGroupASTPropaties is an interface that defines the properties of a {@link NodeRefGroupASTNode}.
|
|
81
138
|
* @group AST
|
|
82
139
|
*/
|
|
83
|
-
|
|
140
|
+
interface NodeRefGroupASTPropaties extends ASTCommonPropaties {}
|
|
84
141
|
/**
|
|
142
|
+
* AttributeASTPropaties interface defines the properties of an {@link AttributeASTNode}.
|
|
85
143
|
* @group AST
|
|
86
144
|
*/
|
|
87
145
|
interface AttributeASTPropaties<T extends AttributeKey = AttributeKey> extends ASTCommonPropaties {
|
|
@@ -89,12 +147,15 @@ interface AttributeASTPropaties<T extends AttributeKey = AttributeKey> extends A
|
|
|
89
147
|
value: LiteralASTNode;
|
|
90
148
|
}
|
|
91
149
|
/**
|
|
150
|
+
* AttributeListASTPropaties interface defines the properties of an {@link AttributeListASTNode}.
|
|
92
151
|
* @group AST
|
|
93
152
|
*/
|
|
94
153
|
interface AttributeListASTPropaties extends ASTCommonPropaties {
|
|
95
154
|
kind: 'Graph' | 'Edge' | 'Node';
|
|
96
155
|
}
|
|
97
156
|
/**
|
|
157
|
+
* CommentKind is an enum type that describes a type of comment.
|
|
158
|
+
*
|
|
98
159
|
* @group AST
|
|
99
160
|
*/
|
|
100
161
|
type CommentKind = 'Block' | 'Slash' | 'Macro';
|
|
@@ -102,11 +163,20 @@ type CommentKind = 'Block' | 'Slash' | 'Macro';
|
|
|
102
163
|
* @group AST
|
|
103
164
|
*/
|
|
104
165
|
interface CommentASTPropaties extends ASTCommonPropaties {
|
|
166
|
+
/**
|
|
167
|
+
* A string that specifies the kind of comment.
|
|
168
|
+
*/
|
|
105
169
|
kind: CommentKind;
|
|
170
|
+
/**
|
|
171
|
+
* A string that contains the actual content of the comment.
|
|
172
|
+
*/
|
|
106
173
|
value: string;
|
|
107
174
|
}
|
|
108
175
|
/**
|
|
109
|
-
* AST
|
|
176
|
+
* ASTBaseNode is an interface that serves as the base for all AST nodes.
|
|
177
|
+
* It requires all leaf interfaces to specify a type property,
|
|
178
|
+
* which is of type {@link ASTType}.
|
|
179
|
+
*
|
|
110
180
|
* @group AST
|
|
111
181
|
*/
|
|
112
182
|
interface ASTBaseNode {
|
|
@@ -117,32 +187,40 @@ interface ASTBaseNode {
|
|
|
117
187
|
type: ASTType;
|
|
118
188
|
}
|
|
119
189
|
/**
|
|
190
|
+
* ASTBaseParentNode represents a parent node that has some child nodes.
|
|
191
|
+
*
|
|
192
|
+
* @template STMT The type of {@link ASTBaseNode} to be stored in the children array.
|
|
120
193
|
* @group AST
|
|
121
194
|
*/
|
|
122
195
|
interface ASTBaseParentNode<STMT extends ASTBaseNode = ASTBaseNode> extends ASTBaseNode {
|
|
123
196
|
children: STMT[];
|
|
124
197
|
}
|
|
125
198
|
/**
|
|
199
|
+
* LiteralASTNode is a type of AST node that represents a literal value.
|
|
200
|
+
*
|
|
126
201
|
* @group AST
|
|
127
202
|
*/
|
|
128
203
|
interface LiteralASTNode<T extends string = string> extends ASTBaseParentNode<never>, LiteralASTPropaties<T> {
|
|
129
204
|
type: 'Literal';
|
|
130
205
|
}
|
|
131
206
|
/**
|
|
207
|
+
* DotASTNode is a type of AST node that represents a dot in a graph.
|
|
208
|
+
*
|
|
132
209
|
* @group AST
|
|
133
210
|
*/
|
|
134
211
|
interface DotASTNode extends ASTBaseParentNode<StatementASTNode>, DotASTPropaties {
|
|
135
212
|
type: 'Dot';
|
|
136
213
|
}
|
|
137
214
|
/**
|
|
138
|
-
*
|
|
215
|
+
* GraphASTNode is a type of AST node that represents a graph.
|
|
216
|
+
*
|
|
139
217
|
* @group AST
|
|
140
218
|
*/
|
|
141
219
|
interface GraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, GraphASTPropaties {
|
|
142
220
|
type: 'Graph';
|
|
143
221
|
}
|
|
144
222
|
/**
|
|
145
|
-
*
|
|
223
|
+
* AttributeASTNode is a type of AST node that represents an attribute.
|
|
146
224
|
* @group AST
|
|
147
225
|
*/
|
|
148
226
|
interface AttributeASTNode<T extends AttributeKey = AttributeKey>
|
|
@@ -151,53 +229,55 @@ interface AttributeASTNode<T extends AttributeKey = AttributeKey>
|
|
|
151
229
|
type: 'Attribute';
|
|
152
230
|
}
|
|
153
231
|
/**
|
|
154
|
-
*
|
|
232
|
+
* CommentASTNode is a type of AST node that represents a comment.
|
|
155
233
|
* @group AST
|
|
156
234
|
*/
|
|
157
235
|
interface CommentASTNode extends ASTBaseParentNode<never>, CommentASTPropaties {
|
|
158
236
|
type: 'Comment';
|
|
159
237
|
}
|
|
160
238
|
/**
|
|
161
|
-
*
|
|
239
|
+
* AttributeListASTNode is a type of AST node that represents a list of attributes.
|
|
162
240
|
* @group AST
|
|
163
241
|
*/
|
|
164
242
|
interface AttributeListASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, AttributeListASTPropaties {
|
|
165
243
|
type: 'AttributeList';
|
|
166
244
|
}
|
|
167
245
|
/**
|
|
168
|
-
*
|
|
246
|
+
* NodeRefASTNode is a type of AST node that represents a reference to a node.
|
|
169
247
|
* @group AST
|
|
170
248
|
*/
|
|
171
249
|
interface NodeRefASTNode extends ASTBaseParentNode<never>, NodeRefASTPropaties {
|
|
172
250
|
type: 'NodeRef';
|
|
173
251
|
}
|
|
174
252
|
/**
|
|
175
|
-
*
|
|
253
|
+
* NodeRefGroupASTNode is a type of AST node that represents a group of nodes referenced together.
|
|
176
254
|
* @group AST
|
|
177
255
|
*/
|
|
178
256
|
interface NodeRefGroupASTNode extends ASTBaseParentNode<NodeRefASTNode>, NodeRefGroupASTPropaties {
|
|
179
257
|
type: 'NodeRefGroup';
|
|
180
258
|
}
|
|
181
259
|
/**
|
|
260
|
+
* This type is used to represent a target of an edge in an AST (Abstract Syntax Tree).
|
|
261
|
+
*
|
|
182
262
|
* @group AST
|
|
183
263
|
*/
|
|
184
264
|
type EdgeTargetASTNode = NodeRefASTNode | NodeRefGroupASTNode;
|
|
185
265
|
/**
|
|
186
|
-
*
|
|
266
|
+
* EdgeASTNode is a type of AST node that represents an edge in a graph.
|
|
187
267
|
* @group AST
|
|
188
268
|
*/
|
|
189
269
|
interface EdgeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, EdgeASTPropaties {
|
|
190
270
|
type: 'Edge';
|
|
191
271
|
}
|
|
192
272
|
/**
|
|
193
|
-
*
|
|
273
|
+
* NodeASTNode is a type of AST node that represents a node in a graph.
|
|
194
274
|
* @group AST
|
|
195
275
|
*/
|
|
196
276
|
interface NodeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, NodeASTPropaties {
|
|
197
277
|
type: 'Node';
|
|
198
278
|
}
|
|
199
279
|
/**
|
|
200
|
-
*
|
|
280
|
+
* SubgraphASTNode is a type of AST node that represents a subgraph.
|
|
201
281
|
* @group AST
|
|
202
282
|
*/
|
|
203
283
|
interface SubgraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, SubgraphASTPropaties {
|
|
@@ -208,6 +288,7 @@ interface SubgraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, Su
|
|
|
208
288
|
*/
|
|
209
289
|
type StatementASTNode = GraphASTNode | CommentASTNode;
|
|
210
290
|
/**
|
|
291
|
+
* ClusterStatementASTNode is a type used to represent a statement in a cluster graph.
|
|
211
292
|
* @group AST
|
|
212
293
|
*/
|
|
213
294
|
type ClusterStatementASTNode =
|
|
@@ -218,6 +299,8 @@ type ClusterStatementASTNode =
|
|
|
218
299
|
| SubgraphASTNode
|
|
219
300
|
| CommentASTNode;
|
|
220
301
|
/**
|
|
302
|
+
* ASTNode is a type used to define a set of different types of AST nodes that can be used in a graph.
|
|
303
|
+
*
|
|
221
304
|
* @group AST
|
|
222
305
|
*/
|
|
223
306
|
type ASTNode =
|
|
@@ -233,48 +316,153 @@ type ASTNode =
|
|
|
233
316
|
| NodeASTNode
|
|
234
317
|
| SubgraphASTNode;
|
|
235
318
|
/**
|
|
319
|
+
* ASTChildNode is a type alias used to represent the child nodes of a given {@link ASTBaseParentNode}.
|
|
236
320
|
* @group AST
|
|
237
321
|
*/
|
|
238
322
|
type ASTChildNode<T> = T extends ASTBaseParentNode<infer C> ? C : never;
|
|
239
323
|
|
|
240
324
|
/**
|
|
325
|
+
* This interface is used to define the options for the builder.
|
|
326
|
+
*
|
|
241
327
|
* @group Create AST
|
|
242
328
|
* @alpha
|
|
243
329
|
*/
|
|
244
330
|
interface BuilderOptions {
|
|
331
|
+
/**
|
|
332
|
+
* This is a function that returns a {@link FileRange} object.
|
|
333
|
+
* It is used to specify the location of the builder.
|
|
334
|
+
*/
|
|
245
335
|
locationFunction: () => FileRange$1;
|
|
246
336
|
}
|
|
247
337
|
/**
|
|
338
|
+
* This interface provides a method for creating an Abstract Syntax Tree (AST) for a given type.
|
|
248
339
|
* @group Create AST
|
|
249
340
|
* @alpha
|
|
250
341
|
*/
|
|
251
342
|
interface CreateElement {
|
|
343
|
+
/**
|
|
344
|
+
* Creates a LiteralASTNode with the given type, properties, and children.
|
|
345
|
+
*
|
|
346
|
+
* @param type The type of the AST node.
|
|
347
|
+
* @param props The properties of the AST node.
|
|
348
|
+
* @param children The children of the AST node.
|
|
349
|
+
* @returns A {@link LiteralASTNode} with the given type, properties, and children.
|
|
350
|
+
*/
|
|
252
351
|
<T extends string>(
|
|
253
352
|
type: 'Literal',
|
|
254
353
|
props: LiteralASTPropaties<T>,
|
|
255
354
|
children: ASTChildNode<LiteralASTNode>[],
|
|
256
355
|
): LiteralASTNode<T>;
|
|
356
|
+
/**
|
|
357
|
+
* Creates a LiteralASTNode with the given type, properties, and children.
|
|
358
|
+
*
|
|
359
|
+
* @param type The type of the AST node.
|
|
360
|
+
* @param props The properties of the AST node.
|
|
361
|
+
* @param children The children of the AST node.
|
|
362
|
+
* @returns A {@link LiteralASTNode} with the given type, properties, and children.
|
|
363
|
+
*/
|
|
257
364
|
(type: 'Literal', props: LiteralASTPropaties, children: ASTChildNode<LiteralASTNode>[]): LiteralASTNode;
|
|
365
|
+
/**
|
|
366
|
+
* Creates a {@link DotASTNode} with the given type, properties, and children.
|
|
367
|
+
*
|
|
368
|
+
* @param type The type of the AST node.
|
|
369
|
+
* @param props The properties of the AST node.
|
|
370
|
+
* @param children The children of the AST node.
|
|
371
|
+
* @returns A {@link DotASTNode} with the given type, properties, and children.
|
|
372
|
+
*/
|
|
258
373
|
(type: 'Dot', props: DotASTPropaties, children: ASTChildNode<DotASTNode>[]): DotASTNode;
|
|
374
|
+
/**
|
|
375
|
+
* Creates a {@link GraphASTNode} with the given type, properties, and children.
|
|
376
|
+
*
|
|
377
|
+
* @param type The type of the AST node.
|
|
378
|
+
* @param props The properties of the AST node.
|
|
379
|
+
* @param children The children of the AST node.
|
|
380
|
+
* @returns A {GraphASTNode} with the given type, properties, and children.
|
|
381
|
+
*/
|
|
259
382
|
(type: 'Graph', props: GraphASTPropaties, children: ASTChildNode<GraphASTNode>[]): GraphASTNode;
|
|
383
|
+
/**
|
|
384
|
+
* Creates an {@link AttributeASTNode} with the given type, properties, and children.
|
|
385
|
+
*
|
|
386
|
+
* @param type The type of the AST node.
|
|
387
|
+
* @param props The properties of the AST node.
|
|
388
|
+
* @param children The children of the AST node.
|
|
389
|
+
* @returns An {@link AttributeASTNode} with the given type, properties, and children.
|
|
390
|
+
*/
|
|
260
391
|
(type: 'Attribute', props: AttributeASTPropaties, children: ASTChildNode<AttributeASTNode>[]): AttributeASTNode;
|
|
392
|
+
/**
|
|
393
|
+
* Creates a {@link CommentASTNode} with the given type, properties, and children.
|
|
394
|
+
*
|
|
395
|
+
* @param type The type of the AST node.
|
|
396
|
+
* @param props The properties of the AST node.
|
|
397
|
+
* @param children The children of the AST node.
|
|
398
|
+
* @returns A {@link CommentASTNode} with the given type, properties, and children.
|
|
399
|
+
*/
|
|
261
400
|
(type: 'Comment', props: CommentASTPropaties, children: ASTChildNode<CommentASTNode>[]): CommentASTNode;
|
|
401
|
+
/**
|
|
402
|
+
* Creates an {@link AttributeListASTNode} with the given type, properties, and children.
|
|
403
|
+
*
|
|
404
|
+
* @param type The type of the AST node.
|
|
405
|
+
* @param props The properties of the AST node.
|
|
406
|
+
* @param children The children of the AST node.
|
|
407
|
+
* @returns An {@link AttributeListASTNode} with the given type, properties, and children.
|
|
408
|
+
*/
|
|
262
409
|
(
|
|
263
410
|
type: 'AttributeList',
|
|
264
411
|
props: AttributeListASTPropaties,
|
|
265
412
|
children: ASTChildNode<AttributeListASTNode>[],
|
|
266
413
|
): AttributeListASTNode;
|
|
414
|
+
/**
|
|
415
|
+
* Creates a {@link NodeRefASTNode} with the given type, properties, and children.
|
|
416
|
+
*
|
|
417
|
+
* @param type The type of the AST node.
|
|
418
|
+
* @param props The properties of the AST node.
|
|
419
|
+
* @param children The children of the AST node.
|
|
420
|
+
* @returns A {@link NodeRefASTNode} with the given type, properties, and children.
|
|
421
|
+
*/
|
|
267
422
|
(type: 'NodeRef', props: NodeRefASTPropaties, children: ASTChildNode<NodeRefASTNode>[]): NodeRefASTNode;
|
|
423
|
+
/**
|
|
424
|
+
* Creates a {@link NodeRefGroupASTNode} with the given type, properties, and children.
|
|
425
|
+
*
|
|
426
|
+
* @param type The type of the AST node.
|
|
427
|
+
* @param props The properties of the AST node.
|
|
428
|
+
* @param children The children of the AST node.
|
|
429
|
+
* @returns A {@link NodeRefGroupASTNode} with the given type, properties, and children.
|
|
430
|
+
*/
|
|
268
431
|
(
|
|
269
432
|
type: 'NodeRefGroup',
|
|
270
433
|
props: NodeRefGroupASTPropaties,
|
|
271
434
|
children: ASTChildNode<NodeRefGroupASTNode>[],
|
|
272
435
|
): NodeRefGroupASTNode;
|
|
436
|
+
/**
|
|
437
|
+
* Creates an {@link EdgeASTNode} with the given type, properties, and children.
|
|
438
|
+
*
|
|
439
|
+
* @param type The type of the AST node.
|
|
440
|
+
* @param props The properties of the AST node.
|
|
441
|
+
* @param children The children of the AST node.
|
|
442
|
+
* @returns An {@link EdgeASTNode} with the given type, properties, and children.
|
|
443
|
+
*/
|
|
273
444
|
(type: 'Edge', props: EdgeASTPropaties, children: ASTChildNode<EdgeASTNode>[]): EdgeASTNode;
|
|
445
|
+
/**
|
|
446
|
+
* Creates a {@link NodeASTNode} with the given type, properties, and children.
|
|
447
|
+
*
|
|
448
|
+
* @param type The type of the AST node.
|
|
449
|
+
* @param props The properties of the AST node.
|
|
450
|
+
* @param children The children of the AST node.
|
|
451
|
+
* @returns A {@link NodeASTNode} with the given type, properties, and children.
|
|
452
|
+
*/
|
|
274
453
|
(type: 'Node', props: NodeASTPropaties, children: ASTChildNode<NodeASTNode>[]): NodeASTNode;
|
|
454
|
+
/**
|
|
455
|
+
* Creates a {@link SubgraphASTNode} with the given type, properties, and children.
|
|
456
|
+
*
|
|
457
|
+
* @param type The type of the AST node.
|
|
458
|
+
* @param props The properties of the AST node.
|
|
459
|
+
* @param children The children of the AST node.
|
|
460
|
+
* @returns A {@link SubgraphASTNode} with the given type, properties, and children.
|
|
461
|
+
*/
|
|
275
462
|
(type: 'Subgraph', props: SubgraphASTPropaties, children: ASTChildNode<SubgraphASTNode>[]): SubgraphASTNode;
|
|
276
463
|
}
|
|
277
464
|
/**
|
|
465
|
+
* This interface provides an ASTBuilder object with a createElement function.
|
|
278
466
|
* @group Create AST
|
|
279
467
|
* @alpha
|
|
280
468
|
*/
|
|
@@ -283,70 +471,141 @@ interface ASTBuilder {
|
|
|
283
471
|
}
|
|
284
472
|
|
|
285
473
|
/**
|
|
474
|
+
* Builder is an ASTBuilder that provides a method to create an ASTNode.
|
|
475
|
+
*
|
|
286
476
|
* @group Create AST
|
|
287
477
|
*/
|
|
288
478
|
declare class Builder implements ASTBuilder {
|
|
289
479
|
private options?;
|
|
290
|
-
/**
|
|
480
|
+
/**
|
|
481
|
+
* Get the current file range or null
|
|
482
|
+
* @internal
|
|
483
|
+
*/
|
|
291
484
|
private getLocation;
|
|
485
|
+
/**
|
|
486
|
+
* Constructor of Builder
|
|
487
|
+
* @param options - Options to initialize Builder
|
|
488
|
+
*/
|
|
292
489
|
constructor(options?: Partial<BuilderOptions> | undefined);
|
|
490
|
+
/**
|
|
491
|
+
* Create an {@link ASTNode} of the specified type
|
|
492
|
+
*
|
|
493
|
+
* @param type - Type of the {@link ASTNode}
|
|
494
|
+
* @param props - Properties of the {@link ASTNode}
|
|
495
|
+
* @param children - Children of the {@link ASTNode}
|
|
496
|
+
* @returns An {@link ASTNode}
|
|
497
|
+
*/
|
|
293
498
|
createElement<T extends ASTNode>(type: T['type'], props: any, children: ASTChildNode<T>[]): T;
|
|
294
499
|
}
|
|
295
500
|
|
|
296
501
|
/**
|
|
502
|
+
* Create an {@link ASTNode} of the specified type
|
|
503
|
+
*
|
|
504
|
+
* @param type - Type of the {@link ASTNode}
|
|
505
|
+
* @param props - Properties of the {@link ASTNode}
|
|
506
|
+
* @param children - Children of the {@link ASTNode}
|
|
297
507
|
* @group Create AST
|
|
508
|
+
* @returns An {@link ASTNode}
|
|
298
509
|
*/
|
|
299
510
|
declare const createElement: CreateElement;
|
|
300
511
|
|
|
301
512
|
/**
|
|
513
|
+
* The IndentStyle type represents an indentation style for text. It can either be a `"space"` or a `"tab"`.
|
|
302
514
|
* @group Convert AST to DOT
|
|
303
515
|
*/
|
|
304
516
|
type IndentStyle = 'space' | 'tab';
|
|
305
517
|
/**
|
|
518
|
+
* This type represents the EndOfLine type which is used to determine the type of line ending to be used when writing to a file.
|
|
306
519
|
* @group Convert AST to DOT
|
|
307
520
|
*/
|
|
308
521
|
type EndOfLine = 'lf' | 'crlf';
|
|
309
522
|
/**
|
|
523
|
+
* This interface provides options for converting an abstract syntax tree (AST) to a DOT representation.
|
|
310
524
|
* @group Convert AST to DOT
|
|
311
525
|
* @alpha
|
|
312
526
|
*/
|
|
313
527
|
interface PrintOptions {
|
|
528
|
+
/**
|
|
529
|
+
* The style of indentation to use when printing the AST.
|
|
530
|
+
*
|
|
531
|
+
* @default "space"
|
|
532
|
+
*/
|
|
314
533
|
indentStyle?: IndentStyle;
|
|
534
|
+
/**
|
|
535
|
+
* The size of the indentation to use when printing the AST.
|
|
536
|
+
*
|
|
537
|
+
* @default 2
|
|
538
|
+
*/
|
|
315
539
|
indentSize?: number;
|
|
540
|
+
/**
|
|
541
|
+
* The type of line ending to use when printing the AST.
|
|
542
|
+
*
|
|
543
|
+
* @default lf
|
|
544
|
+
*/
|
|
316
545
|
endOfLine?: EndOfLine;
|
|
317
546
|
}
|
|
318
547
|
/**
|
|
548
|
+
* PrintContext interface provides an interface for printing an ASTNode with a set of options.
|
|
319
549
|
* @group Convert AST to DOT
|
|
320
550
|
* @alpha
|
|
321
551
|
*/
|
|
322
552
|
interface PrintContext extends Required<PrintOptions> {
|
|
553
|
+
/**
|
|
554
|
+
* Indicates if the AST should be printed in a directed graph.
|
|
555
|
+
*/
|
|
323
556
|
directed: boolean;
|
|
557
|
+
/**
|
|
558
|
+
* A function to print an ASTNode, taking in an ASTNode as an argument. Returns a string.
|
|
559
|
+
*/
|
|
324
560
|
print(ast: ASTNode): string;
|
|
325
561
|
}
|
|
326
562
|
/**
|
|
563
|
+
* PrintPlugin is an interface for plugins used for printing an {@link ASTNode}.
|
|
564
|
+
* @template T T extends {@link ASTNode}
|
|
327
565
|
* @group Convert AST to DOT
|
|
328
566
|
* @alpha
|
|
329
567
|
*/
|
|
330
568
|
interface PrintPlugin<T extends ASTNode = ASTNode> {
|
|
569
|
+
/**
|
|
570
|
+
* Checks if an ASTNode matches the plugin
|
|
571
|
+
* @returns {boolean} true if the ASTNode matches the plugin
|
|
572
|
+
*/
|
|
331
573
|
match(ast: ASTNode): boolean;
|
|
574
|
+
/**
|
|
575
|
+
* Prints an ASTNode
|
|
576
|
+
* @param context PrintContext object
|
|
577
|
+
* @param ast an ASTNode
|
|
578
|
+
* @returns printed string
|
|
579
|
+
* @memberof PrintPlugin
|
|
580
|
+
*/
|
|
332
581
|
print(context: PrintContext, ast: T): string;
|
|
333
582
|
}
|
|
334
583
|
|
|
335
584
|
/**
|
|
585
|
+
* Printer is a class responsible for converting an AST into a DOT string.
|
|
336
586
|
* @group Convert AST to DOT
|
|
337
587
|
*/
|
|
338
588
|
declare class Printer {
|
|
339
589
|
#private;
|
|
340
590
|
private options;
|
|
591
|
+
/**
|
|
592
|
+
* @param options Options to be used when generating the DOT string.
|
|
593
|
+
*/
|
|
341
594
|
constructor(options?: PrintOptions);
|
|
595
|
+
/**
|
|
596
|
+
* Generates a DOT string from an ASTNode.
|
|
597
|
+
* @param ast The ASTNode to be converted into a DOT string.
|
|
598
|
+
* @returns The DOT string generated from the ASTNode.
|
|
599
|
+
*/
|
|
342
600
|
print(ast: ASTNode): string;
|
|
343
601
|
}
|
|
344
602
|
|
|
345
603
|
/**
|
|
346
|
-
*
|
|
604
|
+
* stringify is a function that converts a Graphviz AST Node into a string in DOT language.
|
|
347
605
|
*
|
|
348
|
-
* @param ast Graphviz AST node.
|
|
349
|
-
* @
|
|
606
|
+
* @param ast Graphviz AST node that is to be converted.
|
|
607
|
+
* @param options PrintOptions object containing formatting options.
|
|
608
|
+
* @returns A string in DOT language.
|
|
350
609
|
* @group Convert AST to DOT
|
|
351
610
|
*/
|
|
352
611
|
declare function stringify(ast: ASTNode, options?: PrintOptions): string;
|
|
@@ -405,18 +664,40 @@ declare class DotSyntaxError$1 extends Error {
|
|
|
405
664
|
*/
|
|
406
665
|
type Rule = 'Dot' | 'Graph' | 'Node' | 'Edge' | 'AttributeList' | 'Attribute' | 'Subgraph' | 'ClusterStatements';
|
|
407
666
|
/**
|
|
667
|
+
* CommonParseOptions is an interface that defines the properties needed in order to parse a file.
|
|
408
668
|
* @group Convert DOT to AST
|
|
409
669
|
*/
|
|
410
670
|
interface CommonParseOptions {
|
|
671
|
+
/**
|
|
672
|
+
* filename (optional): A string value that is used to identify the file to be parsed.
|
|
673
|
+
*/
|
|
411
674
|
filename?: string;
|
|
412
675
|
}
|
|
413
676
|
/**
|
|
677
|
+
* ParseOptions interface is used to provide additional information to the parser while parsing a rule.
|
|
678
|
+
* @template T The type of the rule to be parsed.
|
|
414
679
|
* @group Convert DOT to AST
|
|
415
680
|
*/
|
|
416
681
|
interface ParseOptions<T extends Rule> extends CommonParseOptions {
|
|
417
682
|
startRule?: T;
|
|
418
683
|
}
|
|
419
684
|
/**
|
|
685
|
+
* parse is a function that takes a string input and optional parse options and
|
|
686
|
+
* returns an ASTNode or an array of ClusterStatementASTNodes.
|
|
687
|
+
*
|
|
688
|
+
* Depending on the type of parse option specified, the function will return different types of ASTNodes.
|
|
689
|
+
*
|
|
690
|
+
* The types of ASTNodes that can be returned are:
|
|
691
|
+
*
|
|
692
|
+
* - {@link DotASTNode}
|
|
693
|
+
* - {@link GraphASTNode}
|
|
694
|
+
* - {@link NodeASTNode}
|
|
695
|
+
* - {@link EdgeASTNode}
|
|
696
|
+
* - {@link AttributeListASTNode}
|
|
697
|
+
* - {@link AttributeASTNode}
|
|
698
|
+
* - {@link SubgraphASTNode}
|
|
699
|
+
* - {@link ClusterStatementASTNode}
|
|
700
|
+
*
|
|
420
701
|
* @throws {@link SyntaxError}
|
|
421
702
|
* @group Convert DOT to AST
|
|
422
703
|
*/
|
|
@@ -436,6 +717,18 @@ declare function parse(input: string, options?: ParseOptions<Rule>): ASTNode | C
|
|
|
436
717
|
declare const DotSyntaxError: typeof DotSyntaxError$1;
|
|
437
718
|
|
|
438
719
|
/**
|
|
720
|
+
* ModelToAST is a type alias used to map a generic type T to a specific AST node type.
|
|
721
|
+
*
|
|
722
|
+
* If T is a DotObjectModel, the type U is inferred and used to determine which AST node type to map to.
|
|
723
|
+
*
|
|
724
|
+
* If U is 'Graph', the type is mapped to either a {@link GraphASTNode} or a {@link DotASTNode}.
|
|
725
|
+
* If U is 'AttributeList', the type is mapped to an {@link AttributeListASTNode}.
|
|
726
|
+
* If U is 'Edge', the type is mapped to an {@link EdgeASTNode}.
|
|
727
|
+
* If U is 'Node', the type is mapped to a {@link NodeASTNode}.
|
|
728
|
+
* If U is 'Subgraph', the type is mapped to a {@link SubgraphASTNode}.
|
|
729
|
+
*
|
|
730
|
+
* If T is not a DotObjectModel, the type is mapped to never.
|
|
731
|
+
*
|
|
439
732
|
* @group AST
|
|
440
733
|
*/
|
|
441
734
|
type ModelToAST<T> = T extends DotObjectModel<infer U>
|
|
@@ -475,21 +768,36 @@ interface ConvertFromModelPlugin<T extends DotObjectModel> {
|
|
|
475
768
|
}
|
|
476
769
|
|
|
477
770
|
/**
|
|
771
|
+
* FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
|
|
772
|
+
*
|
|
478
773
|
* @group Convert Model to AST
|
|
479
774
|
*/
|
|
480
775
|
declare class FromModelConverter {
|
|
481
776
|
#private;
|
|
482
777
|
private options;
|
|
483
778
|
constructor(options?: ConvertFromModelOptions);
|
|
779
|
+
/**
|
|
780
|
+
* Converts a DotObjectModel into an AST.
|
|
781
|
+
*
|
|
782
|
+
* @param model The {@link DotObjectModel} to be converted.
|
|
783
|
+
* @returns The AST generated from the model.
|
|
784
|
+
*/
|
|
484
785
|
convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
|
|
485
786
|
}
|
|
486
787
|
|
|
487
788
|
/**
|
|
789
|
+
* A function used to convert a DotObjectModel into an AST.
|
|
790
|
+
*
|
|
791
|
+
* @param model - The {@link DotObjectModel} to be converted.
|
|
792
|
+
* @param options - An optional {@link ConvertFromModelOptions} object.
|
|
793
|
+
* @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
|
|
794
|
+
*
|
|
488
795
|
* @group Convert Model to AST
|
|
489
796
|
*/
|
|
490
797
|
declare function fromModel<T extends DotObjectModel>(model: T, options?: ConvertFromModelOptions): ModelToAST<T>;
|
|
491
798
|
|
|
492
799
|
/**
|
|
800
|
+
* ModelOf is a type that determines the type of model to use depending on the value of T.
|
|
493
801
|
* @group AST
|
|
494
802
|
*/
|
|
495
803
|
type ModelOf<T> = T extends 'Dot' | 'Graph'
|
|
@@ -502,6 +810,8 @@ type ModelOf<T> = T extends 'Dot' | 'Graph'
|
|
|
502
810
|
? SubgraphModel
|
|
503
811
|
: never;
|
|
504
812
|
/**
|
|
813
|
+
* ASTToModel is a type that determines a model type from an AST.
|
|
814
|
+
*
|
|
505
815
|
* @group AST
|
|
506
816
|
*/
|
|
507
817
|
type ASTToModel<T> = T extends {
|
|
@@ -510,6 +820,7 @@ type ASTToModel<T> = T extends {
|
|
|
510
820
|
? ModelOf<U>
|
|
511
821
|
: never;
|
|
512
822
|
/**
|
|
823
|
+
* This type is used to define what AST nodes can be converted to a model.
|
|
513
824
|
* @group Convert AST to Model
|
|
514
825
|
* @beta
|
|
515
826
|
*/
|