@coral-viz/language 0.2.3
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/LICENSE +4 -0
- package/README.md +5 -0
- package/dist/diagnostics.d.ts +81 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +59 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/formats/dot.d.ts +23 -0
- package/dist/formats/dot.d.ts.map +1 -0
- package/dist/formats/dot.js +541 -0
- package/dist/formats/dot.js.map +1 -0
- package/dist/formats/index.d.ts +6 -0
- package/dist/formats/index.d.ts.map +1 -0
- package/dist/formats/index.js +6 -0
- package/dist/formats/index.js.map +1 -0
- package/dist/formats/mermaid.d.ts +29 -0
- package/dist/formats/mermaid.d.ts.map +1 -0
- package/dist/formats/mermaid.js +1051 -0
- package/dist/formats/mermaid.js.map +1 -0
- package/dist/formats/plantuml.d.ts +20 -0
- package/dist/formats/plantuml.d.ts.map +1 -0
- package/dist/formats/plantuml.js +271 -0
- package/dist/formats/plantuml.js.map +1 -0
- package/dist/ids.d.ts +36 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +69 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/index.d.ts +13 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +415 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/printer/index.d.ts +47 -0
- package/dist/printer/index.d.ts.map +1 -0
- package/dist/printer/index.js +392 -0
- package/dist/printer/index.js.map +1 -0
- package/dist/strings.d.ts +17 -0
- package/dist/strings.d.ts.map +1 -0
- package/dist/strings.js +48 -0
- package/dist/strings.js.map +1 -0
- package/dist/types.d.ts +40 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +64 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics channel (R-011).
|
|
3
|
+
*
|
|
4
|
+
* Parsers, importers and the printer report what they could not represent, not
|
|
5
|
+
* only what stopped them. One builder constructs every `ParseResult`, so the
|
|
6
|
+
* relationship between `diagnostics`, `errors` and `success` is structural
|
|
7
|
+
* rather than a convention repeated at nineteen construction sites.
|
|
8
|
+
*/
|
|
9
|
+
import type { GraphIR, ParseError, ParseResult } from './types.js';
|
|
10
|
+
export type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
11
|
+
/**
|
|
12
|
+
* A source location.
|
|
13
|
+
*
|
|
14
|
+
* Named `SourcePosition` rather than `Position` because `Position` is already
|
|
15
|
+
* re-exported from `@graph-ir/core` as the `{ x, y }` of node geometry.
|
|
16
|
+
*/
|
|
17
|
+
export interface SourcePosition {
|
|
18
|
+
line: number;
|
|
19
|
+
column: number;
|
|
20
|
+
offset: number;
|
|
21
|
+
}
|
|
22
|
+
/** The IR element a loss attaches to, when one is known. */
|
|
23
|
+
export interface DiagnosticSubject {
|
|
24
|
+
kind: 'node' | 'edge' | 'graph';
|
|
25
|
+
id: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A diagnostic with no inherent source location — what the printer produces,
|
|
29
|
+
* since a graph has no line numbers.
|
|
30
|
+
*/
|
|
31
|
+
export interface Diagnostic {
|
|
32
|
+
severity: DiagnosticSeverity;
|
|
33
|
+
/** `<producer>.<construct>.<disposition>`; the construct may itself be dotted. */
|
|
34
|
+
code: string;
|
|
35
|
+
message: string;
|
|
36
|
+
position?: SourcePosition;
|
|
37
|
+
/** Verbatim source slice that was dropped or degraded. */
|
|
38
|
+
source?: string;
|
|
39
|
+
subject?: DiagnosticSubject;
|
|
40
|
+
hint?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A diagnostic from a parser, which always knows where it is.
|
|
44
|
+
*
|
|
45
|
+
* Extends `ParseError` as well as `Diagnostic` and mirrors `position` into the
|
|
46
|
+
* flat `line`/`column`/`offset` fields, because `ParseError` is flat and the
|
|
47
|
+
* derived `errors` view must stay assignable to `ParseError[]` without a cast
|
|
48
|
+
* while remaining element-identical to the entries in `diagnostics`.
|
|
49
|
+
*/
|
|
50
|
+
export interface ParseDiagnostic extends Diagnostic, ParseError {
|
|
51
|
+
position: SourcePosition;
|
|
52
|
+
}
|
|
53
|
+
/** Options for constructing a single parse diagnostic. */
|
|
54
|
+
export interface ParseDiagnosticInput {
|
|
55
|
+
severity: DiagnosticSeverity;
|
|
56
|
+
code: string;
|
|
57
|
+
message: string;
|
|
58
|
+
position: SourcePosition;
|
|
59
|
+
source?: string;
|
|
60
|
+
subject?: DiagnosticSubject;
|
|
61
|
+
hint?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build a parse diagnostic, mirroring the position into the flat fields.
|
|
65
|
+
*
|
|
66
|
+
* This is the only place a `ParseDiagnostic` is constructed, so the mirror
|
|
67
|
+
* cannot drift from the nested position.
|
|
68
|
+
*/
|
|
69
|
+
export declare function parseDiagnostic(input: ParseDiagnosticInput): ParseDiagnostic;
|
|
70
|
+
/** Build a printer diagnostic, which carries no position. */
|
|
71
|
+
export declare function printDiagnostic(input: Omit<Diagnostic, 'position'>): Diagnostic;
|
|
72
|
+
/**
|
|
73
|
+
* Construct a `ParseResult` from accumulated diagnostics.
|
|
74
|
+
*
|
|
75
|
+
* `success` is derived from the absence of errors, so a warning never fails a
|
|
76
|
+
* parse; `errors` is the error-severity view of `diagnostics`, element-identical
|
|
77
|
+
* and in the same order; both arrays are frozen so neither can be desynchronised
|
|
78
|
+
* from the other.
|
|
79
|
+
*/
|
|
80
|
+
export declare function finishParse(diagnostics: ParseDiagnostic[], graph?: GraphIR): ParseResult;
|
|
81
|
+
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.d.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,EAAE,oBAAoB,GAAG,eAAe,CAc5E;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,UAAU,CAE/E;AAWD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,eAAe,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,WAAW,CAWxF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics channel (R-011).
|
|
3
|
+
*
|
|
4
|
+
* Parsers, importers and the printer report what they could not represent, not
|
|
5
|
+
* only what stopped them. One builder constructs every `ParseResult`, so the
|
|
6
|
+
* relationship between `diagnostics`, `errors` and `success` is structural
|
|
7
|
+
* rather than a convention repeated at nineteen construction sites.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Build a parse diagnostic, mirroring the position into the flat fields.
|
|
11
|
+
*
|
|
12
|
+
* This is the only place a `ParseDiagnostic` is constructed, so the mirror
|
|
13
|
+
* cannot drift from the nested position.
|
|
14
|
+
*/
|
|
15
|
+
export function parseDiagnostic(input) {
|
|
16
|
+
const { position } = input;
|
|
17
|
+
return {
|
|
18
|
+
severity: input.severity,
|
|
19
|
+
code: input.code,
|
|
20
|
+
message: input.message,
|
|
21
|
+
position,
|
|
22
|
+
line: position.line,
|
|
23
|
+
column: position.column,
|
|
24
|
+
offset: position.offset,
|
|
25
|
+
...(input.source !== undefined ? { source: input.source } : {}),
|
|
26
|
+
...(input.subject !== undefined ? { subject: input.subject } : {}),
|
|
27
|
+
...(input.hint !== undefined ? { hint: input.hint } : {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** Build a printer diagnostic, which carries no position. */
|
|
31
|
+
export function printDiagnostic(input) {
|
|
32
|
+
return { ...input };
|
|
33
|
+
}
|
|
34
|
+
/** Order by line, then column, then offset. */
|
|
35
|
+
function bySourcePosition(a, b) {
|
|
36
|
+
return (a.position.line - b.position.line ||
|
|
37
|
+
a.position.column - b.position.column ||
|
|
38
|
+
a.position.offset - b.position.offset);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Construct a `ParseResult` from accumulated diagnostics.
|
|
42
|
+
*
|
|
43
|
+
* `success` is derived from the absence of errors, so a warning never fails a
|
|
44
|
+
* parse; `errors` is the error-severity view of `diagnostics`, element-identical
|
|
45
|
+
* and in the same order; both arrays are frozen so neither can be desynchronised
|
|
46
|
+
* from the other.
|
|
47
|
+
*/
|
|
48
|
+
export function finishParse(diagnostics, graph) {
|
|
49
|
+
const ordered = Object.freeze([...diagnostics].sort(bySourcePosition));
|
|
50
|
+
const errors = Object.freeze(ordered.filter((d) => d.severity === 'error'));
|
|
51
|
+
const success = errors.length === 0;
|
|
52
|
+
return {
|
|
53
|
+
success,
|
|
54
|
+
...(graph !== undefined ? { graph } : {}),
|
|
55
|
+
errors: errors,
|
|
56
|
+
diagnostics: ordered,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+DH;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3B,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ;QACR,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK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S,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACzC,MAAM,EAAE,MAAiC;QACzC,WAAW,EAAE,OAAuC;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graphviz DOT Importer
|
|
3
|
+
*
|
|
4
|
+
* Converts Graphviz DOT syntax to Graph-IR.
|
|
5
|
+
* Supports: digraph, graph, subgraph/cluster
|
|
6
|
+
*
|
|
7
|
+
* DOT syntax reference:
|
|
8
|
+
* - digraph G { A -> B; }
|
|
9
|
+
* - graph G { A -- B; }
|
|
10
|
+
* - Node attributes: A [label="Label", shape=box];
|
|
11
|
+
* - Edge attributes: A -> B [label="flow"];
|
|
12
|
+
* - Clusters: subgraph cluster_name { ... }
|
|
13
|
+
*/
|
|
14
|
+
import type { ParseResult } from '../types.js';
|
|
15
|
+
export interface DotParseOptions {
|
|
16
|
+
graphId?: string;
|
|
17
|
+
graphName?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse Graphviz DOT syntax into Graph-IR
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseDot(source: string, options?: DotParseOptions): ParseResult;
|
|
23
|
+
//# sourceMappingURL=dot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dot.d.ts","sourceRoot":"","sources":["../../src/formats/dot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAIV,WAAW,EAGZ,MAAM,aAAa,CAAC;AAQrB,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAkCD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,eAAoB,GAC5B,WAAW,CAsEb"}
|