@ts-graphviz/ast 0.0.0-pr956-20240225073457

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +22 -0
  3. package/README.md +42 -0
  4. package/lib/ast.cjs +3952 -0
  5. package/lib/ast.d.ts +881 -0
  6. package/lib/ast.js +3952 -0
  7. package/package.json +52 -0
  8. package/src/ast.ts +8 -0
  9. package/src/builder/__snapshots__/create-element.test.ts.snap +166 -0
  10. package/src/builder/builder.test.ts +36 -0
  11. package/src/builder/builder.ts +44 -0
  12. package/src/builder/create-element.test.ts +110 -0
  13. package/src/builder/create-element.ts +13 -0
  14. package/src/builder/index.ts +3 -0
  15. package/src/builder/types.ts +226 -0
  16. package/src/dot-shim/index.ts +2 -0
  17. package/src/dot-shim/parser/__snapshots__/parse.test.ts.snap +2613 -0
  18. package/src/dot-shim/parser/dot.peggy +396 -0
  19. package/src/dot-shim/parser/index.ts +1 -0
  20. package/src/dot-shim/parser/parse.test.ts +263 -0
  21. package/src/dot-shim/parser/parse.ts +121 -0
  22. package/src/dot-shim/parser/peggy.options.json +15 -0
  23. package/src/dot-shim/printer/index.ts +6 -0
  24. package/src/dot-shim/printer/plugins/AttributeListPrintPlugin.ts +22 -0
  25. package/src/dot-shim/printer/plugins/AttributePrintPlugin.ts +11 -0
  26. package/src/dot-shim/printer/plugins/CommentPrintPlugin.ts +40 -0
  27. package/src/dot-shim/printer/plugins/DotPrintPlugin.ts +12 -0
  28. package/src/dot-shim/printer/plugins/EdgePrintPlugin.ts +27 -0
  29. package/src/dot-shim/printer/plugins/GraphPrintPlugin.ts +32 -0
  30. package/src/dot-shim/printer/plugins/LiteralPrintPlugin.ts +24 -0
  31. package/src/dot-shim/printer/plugins/NodePrintPlugin.ts +24 -0
  32. package/src/dot-shim/printer/plugins/NodeRefGroupPrintPlugin.ts +17 -0
  33. package/src/dot-shim/printer/plugins/NodeRefPrintPlugin.ts +18 -0
  34. package/src/dot-shim/printer/plugins/SubgraphPrintPlugin.ts +27 -0
  35. package/src/dot-shim/printer/plugins/index.ts +26 -0
  36. package/src/dot-shim/printer/plugins/utils/index.ts +1 -0
  37. package/src/dot-shim/printer/plugins/utils/tokens.ts +51 -0
  38. package/src/dot-shim/printer/printer.ts +46 -0
  39. package/src/dot-shim/printer/stringify.test.ts +823 -0
  40. package/src/dot-shim/printer/stringify.ts +19 -0
  41. package/src/dot-shim/printer/types.ts +74 -0
  42. package/src/model-shim/from-model/converter.ts +43 -0
  43. package/src/model-shim/from-model/from-model.ts +19 -0
  44. package/src/model-shim/from-model/index.ts +3 -0
  45. package/src/model-shim/from-model/plugins/AttributeListPlugin.ts +19 -0
  46. package/src/model-shim/from-model/plugins/EdgePlugin.ts +140 -0
  47. package/src/model-shim/from-model/plugins/GraphPlugin.ts +36 -0
  48. package/src/model-shim/from-model/plugins/NodePlugin.ts +33 -0
  49. package/src/model-shim/from-model/plugins/SubraphPlugin.ts +28 -0
  50. package/src/model-shim/from-model/plugins/index.ts +13 -0
  51. package/src/model-shim/from-model/plugins/utils/convert-attribute.ts +47 -0
  52. package/src/model-shim/from-model/plugins/utils/convert-cluster-children.ts +44 -0
  53. package/src/model-shim/from-model/plugins/utils/convert-comment.ts +16 -0
  54. package/src/model-shim/from-model/plugins/utils/index.ts +3 -0
  55. package/src/model-shim/from-model/types.ts +62 -0
  56. package/src/model-shim/index.ts +2 -0
  57. package/src/model-shim/to-model/converter.ts +42 -0
  58. package/src/model-shim/to-model/index.ts +3 -0
  59. package/src/model-shim/to-model/plugins/DotPlugin.ts +25 -0
  60. package/src/model-shim/to-model/plugins/EdgePlugin.ts +26 -0
  61. package/src/model-shim/to-model/plugins/GraphPlugin.ts +15 -0
  62. package/src/model-shim/to-model/plugins/NodePlugin.ts +25 -0
  63. package/src/model-shim/to-model/plugins/SubgraphPlugin.ts +14 -0
  64. package/src/model-shim/to-model/plugins/index.ts +13 -0
  65. package/src/model-shim/to-model/plugins/utils/apply-statments.ts +96 -0
  66. package/src/model-shim/to-model/plugins/utils/comment-holder.ts +31 -0
  67. package/src/model-shim/to-model/plugins/utils/convert-to-edge-target-tuple.ts +21 -0
  68. package/src/model-shim/to-model/to-model.test.ts +34 -0
  69. package/src/model-shim/to-model/to-model.ts +16 -0
  70. package/src/model-shim/to-model/types.ts +71 -0
  71. package/src/types.ts +370 -0
  72. package/tsconfig.json +8 -0
  73. package/typedoc.json +4 -0
  74. package/vite.config.ts +22 -0
package/lib/ast.d.ts ADDED
@@ -0,0 +1,881 @@
1
+ import type { ASTType } from '@ts-graphviz/common';
2
+ import { AttributeKey } from '@ts-graphviz/common';
3
+ import type { Compass } from '@ts-graphviz/common';
4
+ import { DotObjectModel } from '@ts-graphviz/common';
5
+ import { EdgeModel } from '@ts-graphviz/common';
6
+ import { ModelsContext } from '@ts-graphviz/common';
7
+ import { NodeModel } from '@ts-graphviz/common';
8
+ import { RootGraphModel } from '@ts-graphviz/common';
9
+ import { SubgraphModel } from '@ts-graphviz/common';
10
+
11
+ declare interface AnyExpectation {
12
+ type: "any";
13
+ }
14
+
15
+ /**
16
+ * ASTBaseNode is an interface that serves as the base for all AST nodes.
17
+ * It requires all leaf interfaces to specify a type property,
18
+ * which is of type {@link ASTType}.
19
+ *
20
+ * @group AST
21
+ */
22
+ export declare interface ASTBaseNode {
23
+ /**
24
+ * Every leaf interface that extends ASTBaseNode
25
+ * must specify a type property.
26
+ */
27
+ type: ASTType;
28
+ }
29
+
30
+ /**
31
+ * ASTBaseParentNode represents a parent node that has some child nodes.
32
+ *
33
+ * @template STMT The type of {@link ASTBaseNode} to be stored in the children array.
34
+ * @group AST
35
+ */
36
+ export declare interface ASTBaseParentNode<STMT extends ASTBaseNode = ASTBaseNode> extends ASTBaseNode {
37
+ children: STMT[];
38
+ }
39
+
40
+ /**
41
+ * This interface provides an ASTBuilder object with a createElement function.
42
+ * @group Create AST
43
+ */
44
+ export declare interface ASTBuilder {
45
+ createElement: CreateElement;
46
+ }
47
+
48
+ /**
49
+ * ASTChildNode is a type alias used to represent the child nodes of a given {@link ASTBaseParentNode}.
50
+ * @group AST
51
+ */
52
+ export declare type ASTChildNode<T> = T extends ASTBaseParentNode<infer C> ? C : never;
53
+
54
+ /**
55
+ * This interface provides common properties to be used across all abstract syntax tree (AST) objects.
56
+ *
57
+ * @group AST
58
+ */
59
+ export declare interface ASTCommonPropaties {
60
+ /**
61
+ * The start and end location of the AST object.
62
+ */
63
+ location?: FileRange;
64
+ }
65
+
66
+ /**
67
+ * ASTNode is a type used to define a set of different types of AST nodes that can be used in a graph.
68
+ *
69
+ * @group AST
70
+ */
71
+ export declare type ASTNode = LiteralASTNode | DotASTNode | GraphASTNode | AttributeASTNode | CommentASTNode | AttributeListASTNode | NodeRefASTNode | NodeRefGroupASTNode | EdgeASTNode | NodeASTNode | SubgraphASTNode;
72
+
73
+ /**
74
+ * ASTToModel is a type that determines a model type from an AST.
75
+ *
76
+ * @group AST
77
+ */
78
+ export declare type ASTToModel<T> = T extends {
79
+ type: infer U;
80
+ } ? ModelOf<U> : never;
81
+
82
+ /**
83
+ * AttributeASTNode is a type of AST node that represents an attribute.
84
+ * @group AST
85
+ */
86
+ export declare interface AttributeASTNode<T extends AttributeKey = AttributeKey> extends ASTBaseParentNode<never>, AttributeASTPropaties<T> {
87
+ type: 'Attribute';
88
+ }
89
+
90
+ /**
91
+ * AttributeASTPropaties interface defines the properties of an {@link AttributeASTNode}.
92
+ * @group AST
93
+ */
94
+ export declare interface AttributeASTPropaties<T extends AttributeKey = AttributeKey> extends ASTCommonPropaties {
95
+ key: LiteralASTNode<T>;
96
+ value: LiteralASTNode;
97
+ }
98
+
99
+ /**
100
+ * AttributeListASTNode is a type of AST node that represents a list of attributes.
101
+ * @group AST
102
+ */
103
+ export declare interface AttributeListASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, AttributeListASTPropaties {
104
+ type: 'AttributeList';
105
+ }
106
+
107
+ /**
108
+ * AttributeListASTPropaties interface defines the properties of an {@link AttributeListASTNode}.
109
+ * @group AST
110
+ */
111
+ export declare interface AttributeListASTPropaties extends ASTCommonPropaties {
112
+ kind: 'Graph' | 'Edge' | 'Node';
113
+ }
114
+
115
+ /**
116
+ * Builder is an ASTBuilder that provides a method to create an ASTNode.
117
+ *
118
+ * @group Create AST
119
+ */
120
+ export declare class Builder implements ASTBuilder {
121
+ private options?;
122
+ /* Excluded from this release type: getLocation */
123
+ /**
124
+ * Constructor of Builder
125
+ * @param options - Options to initialize Builder
126
+ */
127
+ constructor(options?: Partial<BuilderOptions> | undefined);
128
+ /**
129
+ * Create an {@link ASTNode} of the specified type
130
+ *
131
+ * @param type - Type of the {@link ASTNode}
132
+ * @param props - Properties of the {@link ASTNode}
133
+ * @param children - Children of the {@link ASTNode}
134
+ * @returns An {@link ASTNode}
135
+ */
136
+ createElement<T extends ASTNode>(type: T['type'], props: any, children?: ASTChildNode<T>[]): T;
137
+ }
138
+
139
+ /**
140
+ * This interface is used to define the options for the builder.
141
+ *
142
+ * @group Create AST
143
+ */
144
+ export declare interface BuilderOptions {
145
+ /**
146
+ * This is a function that returns a {@link FileRange} object.
147
+ * It is used to specify the location of the builder.
148
+ */
149
+ locationFunction: () => FileRange;
150
+ }
151
+
152
+ declare interface ClassExpectation {
153
+ type: "class";
154
+ parts: ClassParts;
155
+ inverted: boolean;
156
+ ignoreCase: boolean;
157
+ }
158
+
159
+ declare interface ClassParts extends Array<string | ClassParts> {
160
+ }
161
+
162
+ /**
163
+ * ClusterStatementASTNode is a type used to represent a statement in a cluster graph.
164
+ * @group AST
165
+ */
166
+ export declare type ClusterStatementASTNode = AttributeASTNode | AttributeListASTNode | EdgeASTNode | NodeASTNode | SubgraphASTNode | CommentASTNode;
167
+
168
+ /**
169
+ * CommentASTNode is a type of AST node that represents a comment.
170
+ * @group AST
171
+ */
172
+ export declare interface CommentASTNode extends ASTBaseParentNode<never>, CommentASTPropaties {
173
+ type: 'Comment';
174
+ }
175
+
176
+ /**
177
+ * @group AST
178
+ */
179
+ export declare interface CommentASTPropaties extends ASTCommonPropaties {
180
+ /**
181
+ * A string that specifies the kind of comment.
182
+ */
183
+ kind: CommentKind;
184
+ /**
185
+ * A string that contains the actual content of the comment.
186
+ */
187
+ value: string;
188
+ }
189
+
190
+ /**
191
+ * CommentKind is an enum type that describes a type of comment.
192
+ *
193
+ * @group AST
194
+ */
195
+ export declare type CommentKind = 'Block' | 'Slash' | 'Macro';
196
+
197
+ /**
198
+ * CommonParseOptions is an interface that defines the properties needed in order to parse a file.
199
+ * @group Convert DOT to AST
200
+ */
201
+ export declare interface CommonParseOptions {
202
+ /**
203
+ * filename (optional): A string value that is used to identify the file to be parsed.
204
+ */
205
+ filename?: string;
206
+ }
207
+
208
+ /**
209
+ * @group Convert Model to AST
210
+ */
211
+ export declare interface ConvertFromModelContext extends Required<ConvertFromModelOptions> {
212
+ convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
213
+ }
214
+
215
+ /**
216
+ * @group Convert Model to AST
217
+ */
218
+ export declare interface ConvertFromModelOptions {
219
+ commentKind?: CommentKind;
220
+ }
221
+
222
+ /**
223
+ * @group Convert Model to AST
224
+ */
225
+ export declare interface ConvertFromModelPlugin<T extends DotObjectModel> {
226
+ match(model: T): boolean;
227
+ convert(context: ConvertFromModelContext, model: T): ModelToAST<T>;
228
+ }
229
+
230
+ /**
231
+ * @group Convert AST to Model
232
+ */
233
+ export declare interface ConvertToModelContext {
234
+ models: ModelsContext;
235
+ convert<T extends ToModelConvertableASTNode>(ast: T): ASTToModel<T>;
236
+ }
237
+
238
+ /**
239
+ * @group Convert AST to Model
240
+ */
241
+ export declare interface ConvertToModelOptions {
242
+ models?: Partial<ModelsContext>;
243
+ }
244
+
245
+ /**
246
+ * @group Convert AST to Model
247
+ */
248
+ export declare interface ConvertToModelPlugin<T extends ToModelConvertableASTNode = ToModelConvertableASTNode> {
249
+ match(ast: T): boolean;
250
+ convert(context: ConvertToModelContext, ast: T): ASTToModel<T>;
251
+ }
252
+
253
+ /**
254
+ * This interface provides a method for creating an Abstract Syntax Tree (AST) for a given type.
255
+ * @group Create AST
256
+ */
257
+ export declare interface CreateElement {
258
+ /**
259
+ * Creates a LiteralASTNode with the given type, properties, and children.
260
+ *
261
+ * @param type The type of the AST node.
262
+ * @param props The properties of the AST node.
263
+ * @param children The children of the AST node.
264
+ * @returns A {@link LiteralASTNode} with the given type, properties, and children.
265
+ */
266
+ <T extends string>(type: 'Literal', props: LiteralASTPropaties<T>, children?: ASTChildNode<LiteralASTNode>[]): LiteralASTNode<T>;
267
+ /**
268
+ * Creates a LiteralASTNode with the given type, properties, and children.
269
+ *
270
+ * @param type The type of the AST node.
271
+ * @param props The properties of the AST node.
272
+ * @param children The children of the AST node.
273
+ * @returns A {@link LiteralASTNode} with the given type, properties, and children.
274
+ */
275
+ (type: 'Literal', props: LiteralASTPropaties, children?: ASTChildNode<LiteralASTNode>[]): LiteralASTNode;
276
+ /**
277
+ * Creates a {@link DotASTNode} with the given type, properties, and children.
278
+ *
279
+ * @param type The type of the AST node.
280
+ * @param props The properties of the AST node.
281
+ * @param children The children of the AST node.
282
+ * @returns A {@link DotASTNode} with the given type, properties, and children.
283
+ */
284
+ (type: 'Dot', props: DotASTPropaties, children?: ASTChildNode<DotASTNode>[]): DotASTNode;
285
+ /**
286
+ * Creates a {@link GraphASTNode} with the given type, properties, and children.
287
+ *
288
+ * @param type The type of the AST node.
289
+ * @param props The properties of the AST node.
290
+ * @param children The children of the AST node.
291
+ * @returns A {GraphASTNode} with the given type, properties, and children.
292
+ */
293
+ (type: 'Graph', props: GraphASTPropaties, children?: ASTChildNode<GraphASTNode>[]): GraphASTNode;
294
+ /**
295
+ * Creates an {@link AttributeASTNode} with the given type, properties, and children.
296
+ *
297
+ * @param type The type of the AST node.
298
+ * @param props The properties of the AST node.
299
+ * @param children The children of the AST node.
300
+ * @returns An {@link AttributeASTNode} with the given type, properties, and children.
301
+ */
302
+ <K extends AttributeKey>(type: 'Attribute', props: AttributeASTPropaties<K>, children?: ASTChildNode<AttributeASTNode>[]): AttributeASTNode<K>;
303
+ (type: 'Attribute', props: AttributeASTPropaties, children?: ASTChildNode<AttributeASTNode>[]): AttributeASTNode;
304
+ /**
305
+ * Creates a {@link CommentASTNode} with the given type, properties, and children.
306
+ *
307
+ * @param type The type of the AST node.
308
+ * @param props The properties of the AST node.
309
+ * @param children The children of the AST node.
310
+ * @returns A {@link CommentASTNode} with the given type, properties, and children.
311
+ */
312
+ (type: 'Comment', props: CommentASTPropaties, children?: ASTChildNode<CommentASTNode>[]): CommentASTNode;
313
+ /**
314
+ * Creates an {@link AttributeListASTNode} with the given type, properties, and children.
315
+ *
316
+ * @param type The type of the AST node.
317
+ * @param props The properties of the AST node.
318
+ * @param children The children of the AST node.
319
+ * @returns An {@link AttributeListASTNode} with the given type, properties, and children.
320
+ */
321
+ (type: 'AttributeList', props: AttributeListASTPropaties, children?: ASTChildNode<AttributeListASTNode>[]): AttributeListASTNode;
322
+ /**
323
+ * Creates a {@link NodeRefASTNode} with the given type, properties, and children.
324
+ *
325
+ * @param type The type of the AST node.
326
+ * @param props The properties of the AST node.
327
+ * @param children The children of the AST node.
328
+ * @returns A {@link NodeRefASTNode} with the given type, properties, and children.
329
+ */
330
+ (type: 'NodeRef', props: NodeRefASTPropaties, children?: ASTChildNode<NodeRefASTNode>[]): NodeRefASTNode;
331
+ /**
332
+ * Creates a {@link NodeRefGroupASTNode} with the given type, properties, and children.
333
+ *
334
+ * @param type The type of the AST node.
335
+ * @param props The properties of the AST node.
336
+ * @param children The children of the AST node.
337
+ * @returns A {@link NodeRefGroupASTNode} with the given type, properties, and children.
338
+ */
339
+ (type: 'NodeRefGroup', props: NodeRefGroupASTPropaties, children?: ASTChildNode<NodeRefGroupASTNode>[]): NodeRefGroupASTNode;
340
+ /**
341
+ * Creates an {@link EdgeASTNode} with the given type, properties, and children.
342
+ *
343
+ * @param type The type of the AST node.
344
+ * @param props The properties of the AST node.
345
+ * @param children The children of the AST node.
346
+ * @returns An {@link EdgeASTNode} with the given type, properties, and children.
347
+ */
348
+ (type: 'Edge', props: EdgeASTPropaties, children?: ASTChildNode<EdgeASTNode>[]): EdgeASTNode;
349
+ /**
350
+ * Creates a {@link NodeASTNode} with the given type, properties, and children.
351
+ *
352
+ * @param type The type of the AST node.
353
+ * @param props The properties of the AST node.
354
+ * @param children The children of the AST node.
355
+ * @returns A {@link NodeASTNode} with the given type, properties, and children.
356
+ */
357
+ (type: 'Node', props: NodeASTPropaties, children?: ASTChildNode<NodeASTNode>[]): NodeASTNode;
358
+ /**
359
+ * Creates a {@link SubgraphASTNode} with the given type, properties, and children.
360
+ *
361
+ * @param type The type of the AST node.
362
+ * @param props The properties of the AST node.
363
+ * @param children The children of the AST node.
364
+ * @returns A {@link SubgraphASTNode} with the given type, properties, and children.
365
+ */
366
+ (type: 'Subgraph', props: SubgraphASTPropaties, children?: ASTChildNode<SubgraphASTNode>[]): SubgraphASTNode;
367
+ }
368
+
369
+ /**
370
+ * Create an {@link ASTNode} of the specified type
371
+ *
372
+ * @param type - Type of the {@link ASTNode}
373
+ * @param props - Properties of the {@link ASTNode}
374
+ * @param children - Children of the {@link ASTNode}
375
+ * @group Create AST
376
+ * @returns An {@link ASTNode}
377
+ */
378
+ export declare const createElement: CreateElement;
379
+
380
+ /**
381
+ * DotASTNode is a type of AST node that represents a dot in a graph.
382
+ *
383
+ * @group AST
384
+ */
385
+ export declare interface DotASTNode extends ASTBaseParentNode<StatementASTNode>, DotASTPropaties {
386
+ type: 'Dot';
387
+ }
388
+
389
+ /**
390
+ * This interface represents the properties of a dot AST node.
391
+ * @group AST
392
+ */
393
+ export declare interface DotASTPropaties extends ASTCommonPropaties {
394
+ }
395
+
396
+ /**
397
+ * @group Convert DOT to AST
398
+ */
399
+ export declare class DotSyntaxError extends PeggySyntaxError {
400
+ constructor(...args: ConstructorParameters<typeof PeggySyntaxError>);
401
+ }
402
+
403
+ /**
404
+ * EdgeASTNode is a type of AST node that represents an edge in a graph.
405
+ * @group AST
406
+ */
407
+ export declare interface EdgeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, EdgeASTPropaties {
408
+ type: 'Edge';
409
+ }
410
+
411
+ /**
412
+ * EdgeASTPropaties is an interface that defines the properties of an {@link EdgeASTNode}.
413
+ * @group AST
414
+ */
415
+ export declare interface EdgeASTPropaties extends ASTCommonPropaties {
416
+ /**
417
+ * An array of EdgeTargetASTNodes.
418
+ * The {@link EdgeTargetASTNode} represents a node that is the target of an edge.
419
+ */
420
+ targets: [
421
+ from: EdgeTargetASTNode,
422
+ to: EdgeTargetASTNode,
423
+ ...rest: EdgeTargetASTNode[]
424
+ ];
425
+ }
426
+
427
+ /**
428
+ * This type is used to represent a target of an edge in an AST (Abstract Syntax Tree).
429
+ *
430
+ * @group AST
431
+ */
432
+ export declare type EdgeTargetASTNode = NodeRefASTNode | NodeRefGroupASTNode;
433
+
434
+ declare interface EndExpectation {
435
+ type: "end";
436
+ }
437
+
438
+ /**
439
+ * This type represents the EndOfLine type which is used to determine the type of line ending to be used when writing to a file.
440
+ * @group Convert AST to DOT
441
+ */
442
+ export declare type EndOfLine = 'lf' | 'crlf';
443
+
444
+ declare type Expectation = LiteralExpectation | ClassExpectation | AnyExpectation | EndExpectation | OtherExpectation;
445
+
446
+ /**
447
+ * The FilePosition interface represents the position of a file in terms of its offset, line number, and column number.
448
+ *
449
+ * @group AST
450
+ */
451
+ export declare interface FilePosition {
452
+ /**
453
+ * The offset of the file.
454
+ */
455
+ offset: number;
456
+ /**
457
+ * The line number of the file.
458
+ */
459
+ line: number;
460
+ /**
461
+ * The column number of the file.
462
+ */
463
+ column: number;
464
+ }
465
+
466
+ declare interface FilePosition_2 {
467
+ offset: number;
468
+ line: number;
469
+ column: number;
470
+ }
471
+
472
+ /**
473
+ * FileRange interface represents a range of positions within a file.
474
+ * @group AST
475
+ */
476
+ export declare interface FileRange {
477
+ /**
478
+ * The start position of the range.
479
+ */
480
+ start: FilePosition;
481
+ /**
482
+ * The end position of the range.
483
+ */
484
+ end: FilePosition;
485
+ }
486
+
487
+ declare interface FileRange_2 {
488
+ start: FilePosition_2;
489
+ end: FilePosition_2;
490
+ source: string;
491
+ }
492
+
493
+ /**
494
+ * A function used to convert a DotObjectModel into an AST.
495
+ *
496
+ * @param model - The {@link DotObjectModel} to be converted.
497
+ * @param options - An optional {@link ConvertFromModelOptions} object.
498
+ * @returns ModelToAST - The AST representation of the {@link DotObjectModel}.
499
+ *
500
+ * @group Convert Model to AST
501
+ */
502
+ export declare function fromModel<T extends DotObjectModel>(model: T, options?: ConvertFromModelOptions): ModelToAST<T>;
503
+
504
+ /**
505
+ * FromModelConverter is a class used to convert a {@link DotObjectModel} into an ASTNode.
506
+ *
507
+ * @group Convert Model to AST
508
+ */
509
+ export declare class FromModelConverter {
510
+ #private;
511
+ private options;
512
+ constructor(options?: ConvertFromModelOptions);
513
+ /**
514
+ * Converts a DotObjectModel into an AST.
515
+ *
516
+ * @param model The {@link DotObjectModel} to be converted.
517
+ * @returns The AST generated from the model.
518
+ */
519
+ convert<T extends DotObjectModel>(model: T): ModelToAST<T>;
520
+ }
521
+
522
+ /**
523
+ * GraphASTNode is a type of AST node that represents a graph.
524
+ *
525
+ * @group AST
526
+ */
527
+ export declare interface GraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, GraphASTPropaties {
528
+ type: 'Graph';
529
+ }
530
+
531
+ /**
532
+ * This interface defines the properties of a Graph AST Node.
533
+ * @group AST
534
+ */
535
+ export declare interface GraphASTPropaties extends ASTCommonPropaties {
536
+ /**
537
+ * An optional identifier for the Graph AST Node.
538
+ */
539
+ id?: LiteralASTNode;
540
+ /**
541
+ * A boolean indicating whether the graph is directed.
542
+ */
543
+ directed: boolean;
544
+ /**
545
+ * A boolean indicating whether the graph is strict.
546
+ */
547
+ strict: boolean;
548
+ }
549
+
550
+ /**
551
+ * The IndentStyle type represents an indentation style for text. It can either be a `"space"` or a `"tab"`.
552
+ * @group Convert AST to DOT
553
+ */
554
+ export declare type IndentStyle = 'space' | 'tab';
555
+
556
+ /**
557
+ * LiteralASTNode is a type of AST node that represents a literal value.
558
+ *
559
+ * @group AST
560
+ */
561
+ export declare interface LiteralASTNode<T extends string = string> extends ASTBaseParentNode<never>, LiteralASTPropaties<T> {
562
+ type: 'Literal';
563
+ }
564
+
565
+ /**
566
+ * LiteralASTPropaties defines interface for literal AST nodes.
567
+ *
568
+ * @group AST
569
+ */
570
+ export declare interface LiteralASTPropaties<T extends string = string> extends ASTCommonPropaties {
571
+ /**
572
+ * The value of the literal.
573
+ */
574
+ value: T;
575
+ /**
576
+ * A flag indicating whether the literal was quoted or not.
577
+ * If 'html' then the literal is an html like value.
578
+ */
579
+ quoted: boolean | 'html';
580
+ }
581
+
582
+ declare interface LiteralExpectation {
583
+ type: "literal";
584
+ text: string;
585
+ ignoreCase: boolean;
586
+ }
587
+
588
+ /**
589
+ * ModelOf is a type that determines the type of model to use depending on the value of T.
590
+ * @group AST
591
+ */
592
+ export declare type ModelOf<T> = T extends 'Dot' | 'Graph' ? RootGraphModel : T extends 'Edge' ? EdgeModel : T extends 'Node' ? NodeModel : T extends 'Subgraph' ? SubgraphModel : never;
593
+
594
+ /**
595
+ * ModelToAST is a type alias used to map a generic type T to a specific AST node type.
596
+ *
597
+ * If T is a DotObjectModel, the type U is inferred and used to determine which AST node type to map to.
598
+ *
599
+ * If U is 'Graph', the type is mapped to either a {@link GraphASTNode} or a {@link DotASTNode}.
600
+ * If U is 'AttributeList', the type is mapped to an {@link AttributeListASTNode}.
601
+ * If U is 'Edge', the type is mapped to an {@link EdgeASTNode}.
602
+ * If U is 'Node', the type is mapped to a {@link NodeASTNode}.
603
+ * If U is 'Subgraph', the type is mapped to a {@link SubgraphASTNode}.
604
+ *
605
+ * If T is not a DotObjectModel, the type is mapped to never.
606
+ *
607
+ * @group AST
608
+ */
609
+ export declare type ModelToAST<T> = T extends DotObjectModel<infer U> ? U extends 'Graph' ? GraphASTNode | DotASTNode : U extends 'AttributeList' ? AttributeListASTNode : U extends 'Edge' ? EdgeASTNode : U extends 'Node' ? NodeASTNode : U extends 'Subgraph' ? SubgraphASTNode : never : never;
610
+
611
+ /**
612
+ * NodeASTNode is a type of AST node that represents a node in a graph.
613
+ * @group AST
614
+ */
615
+ export declare interface NodeASTNode extends ASTBaseParentNode<AttributeASTNode | CommentASTNode>, NodeASTPropaties {
616
+ type: 'Node';
617
+ }
618
+
619
+ /**
620
+ * SubgraphASTPropaties describes the properties of an AST node representing a node.
621
+ * @group AST
622
+ */
623
+ export declare interface NodeASTPropaties extends ASTCommonPropaties {
624
+ /**
625
+ * The unique identifier of the node.
626
+ */
627
+ id: LiteralASTNode;
628
+ }
629
+
630
+ /**
631
+ * NodeRefASTNode is a type of AST node that represents a reference to a node.
632
+ * @group AST
633
+ */
634
+ export declare interface NodeRefASTNode extends ASTBaseParentNode<never>, NodeRefASTPropaties {
635
+ type: 'NodeRef';
636
+ }
637
+
638
+ /**
639
+ * NodeRefASTPropaties is an interface that defines the properties of a {@link NodeRefASTNode}.
640
+ * @group AST
641
+ */
642
+ export declare interface NodeRefASTPropaties extends ASTCommonPropaties {
643
+ id: LiteralASTNode;
644
+ port?: LiteralASTNode;
645
+ compass?: LiteralASTNode<Compass>;
646
+ }
647
+
648
+ /**
649
+ * NodeRefGroupASTNode is a type of AST node that represents a group of nodes referenced together.
650
+ * @group AST
651
+ */
652
+ export declare interface NodeRefGroupASTNode extends ASTBaseParentNode<NodeRefASTNode>, NodeRefGroupASTPropaties {
653
+ type: 'NodeRefGroup';
654
+ }
655
+
656
+ /**
657
+ * NodeRefGroupASTPropaties is an interface that defines the properties of a {@link NodeRefGroupASTNode}.
658
+ * @group AST
659
+ */
660
+ export declare interface NodeRefGroupASTPropaties extends ASTCommonPropaties {
661
+ }
662
+
663
+ declare interface OtherExpectation {
664
+ type: "other";
665
+ description: string;
666
+ }
667
+
668
+ /**
669
+ * parse is a function that takes a string input and optional parse options and
670
+ * returns an ASTNode or an array of ClusterStatementASTNodes.
671
+ *
672
+ * Depending on the type of parse option specified, the function will return different types of ASTNodes.
673
+ *
674
+ * The types of ASTNodes that can be returned are:
675
+ *
676
+ * - {@link DotASTNode}
677
+ * - {@link GraphASTNode}
678
+ * - {@link NodeASTNode}
679
+ * - {@link EdgeASTNode}
680
+ * - {@link AttributeListASTNode}
681
+ * - {@link AttributeASTNode}
682
+ * - {@link SubgraphASTNode}
683
+ * - {@link ClusterStatementASTNode}
684
+ *
685
+ * @throws {@link SyntaxError}
686
+ * @group Convert DOT to AST
687
+ */
688
+ export declare function parse(input: string): DotASTNode;
689
+
690
+ export declare function parse(input: string, options?: ParseOptions<'Dot'>): DotASTNode;
691
+
692
+ export declare function parse(input: string, options?: ParseOptions<'Graph'>): GraphASTNode;
693
+
694
+ export declare function parse(input: string, options?: ParseOptions<'Node'>): NodeASTNode;
695
+
696
+ export declare function parse(input: string, options?: ParseOptions<'Edge'>): EdgeASTNode;
697
+
698
+ export declare function parse(input: string, options?: ParseOptions<'AttributeList'>): AttributeListASTNode;
699
+
700
+ export declare function parse(input: string, options?: ParseOptions<'Attribute'>): AttributeASTNode;
701
+
702
+ export declare function parse(input: string, options?: ParseOptions<'Subgraph'>): SubgraphASTNode;
703
+
704
+ export declare function parse(input: string, options?: ParseOptions<'ClusterStatements'>): ClusterStatementASTNode[];
705
+
706
+ export declare function parse(input: string, options?: ParseOptions<Rule>): ASTNode | ClusterStatementASTNode[];
707
+
708
+ /**
709
+ * ParseOptions interface is used to provide additional information to the parser while parsing a rule.
710
+ * @template T The type of the rule to be parsed.
711
+ * @group Convert DOT to AST
712
+ */
713
+ export declare interface ParseOptions<T extends Rule> extends CommonParseOptions {
714
+ startRule?: T;
715
+ }
716
+
717
+ declare const PeggySyntaxError: typeof _PeggySyntaxError;
718
+
719
+ declare type PeggySyntaxError = _PeggySyntaxError;
720
+
721
+ declare class _PeggySyntaxError extends Error {
722
+ static buildMessage(expected: Expectation[], found: string | null): string;
723
+ message: string;
724
+ expected: Expectation[];
725
+ found: string | null;
726
+ location: FileRange_2;
727
+ name: string;
728
+ constructor(message: string, expected: Expectation[], found: string | null, location: FileRange_2);
729
+ format(sources: {
730
+ source?: any;
731
+ text: string;
732
+ }[]): string;
733
+ }
734
+
735
+ /**
736
+ * PrintContext interface provides an interface for printing an ASTNode with a set of options.
737
+ * @group Convert AST to DOT
738
+ */
739
+ export declare interface PrintContext extends Required<PrintOptions> {
740
+ /**
741
+ * Indicates if the AST should be printed in a directed graph.
742
+ */
743
+ directed: boolean;
744
+ /**
745
+ * A function to print an ASTNode, taking in an ASTNode as an argument. Returns a string.
746
+ */
747
+ print(ast: ASTNode): string;
748
+ }
749
+
750
+ /**
751
+ * Printer is a class responsible for converting an AST into a DOT string.
752
+ * @group Convert AST to DOT
753
+ */
754
+ export declare class Printer {
755
+ #private;
756
+ private options;
757
+ /**
758
+ * @param options Options to be used when generating the DOT string.
759
+ */
760
+ constructor(options?: PrintOptions);
761
+ /**
762
+ * Generates a DOT string from an ASTNode.
763
+ * @param ast The ASTNode to be converted into a DOT string.
764
+ * @returns The DOT string generated from the ASTNode.
765
+ */
766
+ print(ast: ASTNode): string;
767
+ }
768
+
769
+ /**
770
+ * This interface provides options for converting an abstract syntax tree (AST) to a DOT representation.
771
+ * @group Convert AST to DOT
772
+ */
773
+ export declare interface PrintOptions {
774
+ /**
775
+ * The style of indentation to use when printing the AST.
776
+ *
777
+ * @default "space"
778
+ */
779
+ indentStyle?: IndentStyle;
780
+ /**
781
+ * The size of the indentation to use when printing the AST.
782
+ *
783
+ * @default 2
784
+ */
785
+ indentSize?: number;
786
+ /**
787
+ * The type of line ending to use when printing the AST.
788
+ *
789
+ * @default lf
790
+ */
791
+ endOfLine?: EndOfLine;
792
+ }
793
+
794
+ /**
795
+ * PrintPlugin is an interface for plugins used for printing an {@link ASTNode}.
796
+ * @template T T extends {@link ASTNode}
797
+ * @group Convert AST to DOT
798
+ */
799
+ export declare interface PrintPlugin<T extends ASTNode = ASTNode> {
800
+ /**
801
+ * Checks if an ASTNode matches the plugin
802
+ * @returns {boolean} true if the ASTNode matches the plugin
803
+ */
804
+ match(ast: ASTNode): boolean;
805
+ /**
806
+ * Prints an ASTNode
807
+ * @param context PrintContext object
808
+ * @param ast an ASTNode
809
+ * @returns printed string
810
+ * @memberof PrintPlugin
811
+ */
812
+ print(context: PrintContext, ast: T): string;
813
+ }
814
+
815
+ /**
816
+ * @group Convert DOT to AST
817
+ */
818
+ export declare type Rule = 'Dot' | 'Graph' | 'Node' | 'Edge' | 'AttributeList' | 'Attribute' | 'Subgraph' | 'ClusterStatements';
819
+
820
+ /**
821
+ * @group AST
822
+ */
823
+ export declare type StatementASTNode = GraphASTNode | CommentASTNode;
824
+
825
+ /**
826
+ * stringify is a function that converts a Graphviz AST Node into a string in DOT language.
827
+ *
828
+ * @param ast Graphviz AST node that is to be converted.
829
+ * @param options PrintOptions object containing formatting options.
830
+ * @returns A string in DOT language.
831
+ * @group Convert AST to DOT
832
+ */
833
+ export declare function stringify(ast: ASTNode, options?: PrintOptions): string;
834
+
835
+ /**
836
+ * SubgraphASTNode is a type of AST node that represents a subgraph.
837
+ * @group AST
838
+ */
839
+ export declare interface SubgraphASTNode extends ASTBaseParentNode<ClusterStatementASTNode>, SubgraphASTPropaties {
840
+ type: 'Subgraph';
841
+ }
842
+
843
+ /**
844
+ * SubgraphASTPropaties describes the properties of an AST node representing a subgraph.
845
+ * @group AST
846
+ */
847
+ export declare interface SubgraphASTPropaties extends ASTCommonPropaties {
848
+ /**
849
+ * id is an optional {@link LiteralASTNode} that represents the identifier of the subgraph.
850
+ */
851
+ id?: LiteralASTNode;
852
+ }
853
+
854
+ /**
855
+ * @group Convert AST to Model
856
+ */
857
+ export declare function toModel<T extends ToModelConvertableASTNode>(ast: T, options?: ConvertToModelOptions): ASTToModel<T>;
858
+
859
+ /**
860
+ * This type is used to define what AST nodes can be converted to a model.
861
+ * @group Convert AST to Model
862
+ */
863
+ export declare type ToModelConvertableASTNode = DotASTNode | GraphASTNode | SubgraphASTNode | NodeASTNode | EdgeASTNode;
864
+
865
+ /**
866
+ * @group Convert AST to Model
867
+ */
868
+ export declare class ToModelConverter {
869
+ private options;
870
+ /** @hidden */
871
+ protected plugins: ConvertToModelPlugin<ToModelConvertableASTNode>[];
872
+ constructor(options?: ConvertToModelOptions);
873
+ /**
874
+ * Convert AST to Model.
875
+ *
876
+ * @param ast AST node.
877
+ */
878
+ convert<T extends ToModelConvertableASTNode>(ast: T): ASTToModel<T>;
879
+ }
880
+
881
+ export { }