dot-language-support 1.5.4

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 (57) hide show
  1. package/.github/workflows/CD.yml +36 -0
  2. package/.github/workflows/CI.yml +33 -0
  3. package/LICENSE +21 -0
  4. package/README.md +17 -0
  5. package/lib/binder.d.ts +2 -0
  6. package/lib/binder.js +300 -0
  7. package/lib/checker.d.ts +14 -0
  8. package/lib/checker.js +185 -0
  9. package/lib/core.d.ts +1 -0
  10. package/lib/core.js +14 -0
  11. package/lib/error.d.ts +3 -0
  12. package/lib/error.js +14 -0
  13. package/lib/index.d.ts +6 -0
  14. package/lib/index.js +19 -0
  15. package/lib/parser.d.ts +84 -0
  16. package/lib/parser.js +698 -0
  17. package/lib/scanner.d.ts +52 -0
  18. package/lib/scanner.js +580 -0
  19. package/lib/service/codeAction.d.ts +12 -0
  20. package/lib/service/codeAction.js +214 -0
  21. package/lib/service/colorProvider.d.ts +6 -0
  22. package/lib/service/colorProvider.js +74 -0
  23. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.d.ts +10 -0
  24. package/lib/service/command/ChangeAllOtherEdgeOpsAndFixGraphCommand.js +43 -0
  25. package/lib/service/command/ChangeEdgeOpCommand.d.ts +10 -0
  26. package/lib/service/command/ChangeEdgeOpCommand.js +37 -0
  27. package/lib/service/command/ConsolidateDescendantsCommand.d.ts +10 -0
  28. package/lib/service/command/ConsolidateDescendantsCommand.js +106 -0
  29. package/lib/service/command/RemoveSemicolons.d.ts +10 -0
  30. package/lib/service/command/RemoveSemicolons.js +42 -0
  31. package/lib/service/command/common.d.ts +31 -0
  32. package/lib/service/command/common.js +31 -0
  33. package/lib/service/completion.d.ts +4 -0
  34. package/lib/service/completion.js +141 -0
  35. package/lib/service/hover.d.ts +4 -0
  36. package/lib/service/hover.js +123 -0
  37. package/lib/service/interop.d.ts +15 -0
  38. package/lib/service/interop.js +56 -0
  39. package/lib/service/languageFacts.d.ts +659 -0
  40. package/lib/service/languageFacts.js +976 -0
  41. package/lib/service/polyfill.d.ts +16 -0
  42. package/lib/service/polyfill.js +3 -0
  43. package/lib/service/reference.d.ts +5 -0
  44. package/lib/service/reference.js +73 -0
  45. package/lib/service/rename.d.ts +4 -0
  46. package/lib/service/rename.js +49 -0
  47. package/lib/service/service.d.ts +27 -0
  48. package/lib/service/service.js +39 -0
  49. package/lib/service/util.d.ts +11 -0
  50. package/lib/service/util.js +52 -0
  51. package/lib/service/validation.d.ts +4 -0
  52. package/lib/service/validation.js +24 -0
  53. package/lib/types.d.ts +396 -0
  54. package/lib/types.js +74 -0
  55. package/lib/visitor.d.ts +2 -0
  56. package/lib/visitor.js +78 -0
  57. package/package.json +42 -0
@@ -0,0 +1,36 @@
1
+ name: Node.js CD
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "!*"
7
+ tags:
8
+ - "v*"
9
+
10
+ jobs:
11
+ build:
12
+
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+
18
+ - name: Use Node.js 16.x
19
+ uses: actions/setup-node@v1
20
+ with:
21
+ node-version: 16.x
22
+
23
+ - uses: actions/cache@v2
24
+ with:
25
+ path: ~/.npm
26
+ key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
27
+ restore-keys: |
28
+ ${{ runner.os }}-node-
29
+
30
+ - run: npm ci
31
+ - run: npm run compile
32
+ - run: npm test
33
+ env:
34
+ CI: true
35
+ - run: npm config set "//registry.npmjs.org/:_authToken" "${{ secrets.NPM_TOKEN }}"
36
+ - run: npm publish
@@ -0,0 +1,33 @@
1
+ name: Node.js CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ matrix:
12
+ node-version: [14.x, 16.x]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Use Node.js ${{ matrix.node-version }}
18
+ uses: actions/setup-node@v1
19
+ with:
20
+ node-version: ${{ matrix.node-version }}
21
+
22
+ - uses: actions/cache@v2
23
+ with:
24
+ path: ~/.npm
25
+ key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
26
+ restore-keys: |
27
+ ${{ runner.os }}-node-${{ matrix.node-version }}-
28
+
29
+ - run: npm ci
30
+ - run: npm run compile
31
+ - run: npm test
32
+ env:
33
+ CI: true
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Niklas Mollenhauer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # dot-language-support
2
+ > [![Build Status](https://travis-ci.com/nikeee/dot-language-support.svg?branch=master)](https://travis-ci.com/nikeee/dot-language-support) ![Dependency Status](https://david-dm.org/nikeee/dot-language-support.svg) [![npm version](https://badge.fury.io/js/dot-language-support.svg)](https://www.npmjs.com/package/dot-language-support)
3
+
4
+ A language service library, written in TypeScript. Used by [dot-language-server](https://github.com/nikeee/dot-language-server) and [edotor.net](https://edotor.net).
5
+
6
+ ## Features
7
+ - Hightlight semantic and syntactic errors
8
+ - Auto completion for colors and shapes
9
+ - Code Actions:
10
+ - Refactoring Graphs to Digraphs and vice-versa
11
+ - Fix wrong graph edges
12
+ - Refactor edges to sub graphs
13
+
14
+ ## Installation
15
+ ```Shell
16
+ npm -S i dot-language-support
17
+ ```
@@ -0,0 +1,2 @@
1
+ import { SourceFile } from "./types";
2
+ export declare function bindSourceFile(file: SourceFile): void;
package/lib/binder.js ADDED
@@ -0,0 +1,300 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindSourceFile = void 0;
4
+ const types_1 = require("./types");
5
+ const checker_1 = require("./checker");
6
+ const parser_1 = require("./parser");
7
+ const binder = createBinder();
8
+ function bindSourceFile(file) {
9
+ binder.bind(file);
10
+ }
11
+ exports.bindSourceFile = bindSourceFile;
12
+ function createBinder() {
13
+ let parent = undefined;
14
+ let symbolTable = undefined;
15
+ let colorTable = undefined;
16
+ let graphContext = 0;
17
+ function bind(node) {
18
+ if (!node)
19
+ return;
20
+ const saveParent = parent;
21
+ const saveContext = graphContext;
22
+ node.parent = saveParent;
23
+ node.graphContext = saveContext;
24
+ parent = node;
25
+ innerBind(node);
26
+ parent = saveParent;
27
+ graphContext = saveContext;
28
+ }
29
+ function innerBind(node) {
30
+ switch (node.kind) {
31
+ case types_1.SyntaxKind.DirectedGraph:
32
+ case types_1.SyntaxKind.UndirectedGraph:
33
+ return bindGraph(node);
34
+ case types_1.SyntaxKind.AttributeStatement:
35
+ return bindAttributeStatement(node);
36
+ case types_1.SyntaxKind.EdgeStatement:
37
+ return bindEdgeStatement(node);
38
+ case types_1.SyntaxKind.NodeStatement:
39
+ return bindNodeStatement(node);
40
+ case types_1.SyntaxKind.SubGraph:
41
+ return bindSubGraph(node);
42
+ case types_1.SyntaxKind.SubGraphStatement:
43
+ return bindSubGraphStatement(node);
44
+ case types_1.SyntaxKind.IdEqualsIdStatement:
45
+ return bindIdEqualsIdStatement(node);
46
+ case types_1.SyntaxKind.QuotedTextIdentifier:
47
+ return bindQuotedTextIdentifier(node);
48
+ case types_1.SyntaxKind.EdgeRhs:
49
+ return bindEdgeRhs(node);
50
+ case types_1.SyntaxKind.AttributeContainer:
51
+ return bindAttributeContainer(node);
52
+ case types_1.SyntaxKind.Assignment:
53
+ return bindAssignment(node);
54
+ case types_1.SyntaxKind.NormalPortDeclaration:
55
+ return bindNormalPortDeclaration(node);
56
+ case types_1.SyntaxKind.CompassPortDeclaration:
57
+ return bindCompassPortDeclaration(node);
58
+ case types_1.SyntaxKind.NodeId:
59
+ return bindNodeId(node);
60
+ default:
61
+ if (node.kind >= types_1.SyntaxKind.FirstNode)
62
+ throw "TODO";
63
+ }
64
+ }
65
+ function bindGraph(node) {
66
+ if (node.strict) {
67
+ graphContext |= 2;
68
+ }
69
+ switch (node.kind) {
70
+ case types_1.SyntaxKind.DirectedGraph:
71
+ graphContext |= 4;
72
+ break;
73
+ case types_1.SyntaxKind.UndirectedGraph:
74
+ graphContext |= 8;
75
+ break;
76
+ }
77
+ if (node.id) {
78
+ ensureGlobalSymbol(node.id);
79
+ bind(node.id);
80
+ }
81
+ ;
82
+ if (node.strict)
83
+ bind(node.strict);
84
+ bindChildren(node.statements);
85
+ }
86
+ function bindAttributeStatement(node) {
87
+ bind(node.subject);
88
+ bindChildren(node.attributes);
89
+ if (node.terminator)
90
+ bind(node.terminator);
91
+ }
92
+ function bindEdgeStatement(node) {
93
+ bindChildren(node.attributes);
94
+ bindChildren(node.rhs);
95
+ bind(node.source);
96
+ if (node.terminator)
97
+ bind(node.terminator);
98
+ }
99
+ function bindNodeStatement(node) {
100
+ bind(node.id);
101
+ bindChildren(node.attributes);
102
+ if (node.terminator)
103
+ bind(node.terminator);
104
+ }
105
+ function bindSubGraph(node) {
106
+ if (node.id) {
107
+ bind(node.id);
108
+ }
109
+ ;
110
+ bindChildren(node.statements);
111
+ }
112
+ function bindSubGraphStatement(node) {
113
+ bind(node.subgraph);
114
+ if (node.terminator)
115
+ bind(node.terminator);
116
+ }
117
+ function bindIdEqualsIdStatement(node) {
118
+ bind(node.leftId);
119
+ bind(node.rightId);
120
+ if (node.rightId && !(0, checker_1.nodeContainsErrors)(node.rightId)) {
121
+ if (isAttributeName("color", node.leftId)) {
122
+ ensureGlobalColor(node.rightId);
123
+ }
124
+ else if (isAttributeName("fillcolor", node.leftId)) {
125
+ ensureGlobalColor(node.rightId);
126
+ }
127
+ else if (isAttributeName("bgcolor", node.leftId)) {
128
+ ensureGlobalColor(node.rightId);
129
+ }
130
+ else if (isAttributeName("fontcolor", node.leftId)) {
131
+ ensureGlobalColor(node.rightId);
132
+ }
133
+ }
134
+ if (node.terminator)
135
+ bind(node.terminator);
136
+ }
137
+ function bindQuotedTextIdentifier(node) {
138
+ bindChildren(node.values);
139
+ node.concatenation = node.values.map(v => v.text).join("");
140
+ }
141
+ function bindEdgeRhs(node) {
142
+ bind(node.operation);
143
+ bind(node.target);
144
+ }
145
+ function bindAttributeContainer(node) {
146
+ bind(node.openBracket);
147
+ bindChildren(node.assignments);
148
+ bind(node.closeBracket);
149
+ }
150
+ function bindAssignment(node) {
151
+ const attrContainer = node.parent;
152
+ console.assert(!!attrContainer);
153
+ const superParentStatement = attrContainer.parent;
154
+ console.assert(!!superParentStatement);
155
+ bind(node.leftId);
156
+ let carrierIdentifier = undefined;
157
+ switch (superParentStatement.kind) {
158
+ case types_1.SyntaxKind.NodeStatement:
159
+ carrierIdentifier = superParentStatement.id.id;
160
+ break;
161
+ case types_1.SyntaxKind.EdgeStatement:
162
+ break;
163
+ case types_1.SyntaxKind.SubGraphStatement:
164
+ break;
165
+ case types_1.SyntaxKind.AttributeStatement:
166
+ break;
167
+ }
168
+ if (carrierIdentifier)
169
+ ensureMemberSymbol(node.leftId, carrierIdentifier);
170
+ bind(node.rightId);
171
+ if (node.rightId && !(0, checker_1.nodeContainsErrors)(node.rightId)) {
172
+ if (isAttributeName("color", node.leftId)) {
173
+ ensureGlobalColor(node.rightId);
174
+ }
175
+ }
176
+ if (node.terminator)
177
+ bind(node.terminator);
178
+ }
179
+ function bindNormalPortDeclaration(node) {
180
+ bind(node.colon);
181
+ ensureGlobalSymbol(node.id);
182
+ bind(node.id);
183
+ if (node.compassPt)
184
+ bind(node.compassPt);
185
+ }
186
+ function bindCompassPortDeclaration(node) {
187
+ bind(node.colon);
188
+ if (node.compassPt)
189
+ bind(node.compassPt);
190
+ }
191
+ function bindNodeId(node) {
192
+ ensureGlobalSymbol(node.id);
193
+ bind(node.id);
194
+ if (node.port)
195
+ bind(node.port);
196
+ }
197
+ function bindChildren(nodes) {
198
+ for (const n of nodes)
199
+ bind(n);
200
+ }
201
+ function createSymbolTable() {
202
+ return new Map();
203
+ }
204
+ function createColorTable() {
205
+ return new Map();
206
+ }
207
+ function ensureMemberSymbol(node, carrier) {
208
+ if (node && carrier && (0, parser_1.isIdentifierNode)(node)) {
209
+ const name = (0, checker_1.getIdentifierText)(node);
210
+ if (name === undefined)
211
+ return;
212
+ const carrierSymbol = carrier.symbol;
213
+ if (carrierSymbol === undefined)
214
+ throw "carrierSymbol is undefined";
215
+ let symbols = carrierSymbol.members;
216
+ if (symbols === undefined)
217
+ carrierSymbol.members = symbols = createSymbolTable();
218
+ ensureSymbolOnTable(name, node, symbols);
219
+ return;
220
+ }
221
+ console.warn("ensureSymbol called on non-identifier node");
222
+ debugger;
223
+ }
224
+ function ensureGlobalSymbol(node) {
225
+ if (node && (0, parser_1.isIdentifierNode)(node)) {
226
+ const symbols = symbolTable;
227
+ const name = (0, checker_1.getIdentifierText)(node);
228
+ if (name === undefined)
229
+ return;
230
+ if (symbols === undefined)
231
+ throw "symbolTable is undefined";
232
+ ensureSymbolOnTable(name, node, symbols);
233
+ return;
234
+ }
235
+ console.warn("ensureSymbol called on non-identifier node");
236
+ debugger;
237
+ }
238
+ function ensureSymbolOnTable(name, node, symbols) {
239
+ if (!name)
240
+ return;
241
+ let sym = symbols.get(name);
242
+ if (sym === undefined) {
243
+ sym = createSymbol(name, node);
244
+ symbols.set(name, sym);
245
+ }
246
+ else {
247
+ if (!sym.references)
248
+ sym.references = [node];
249
+ else
250
+ sym.references.push(node);
251
+ }
252
+ node.symbol = sym;
253
+ }
254
+ function ensureGlobalColor(node) {
255
+ if (node && (0, parser_1.isIdentifierNode)(node)) {
256
+ const colors = colorTable;
257
+ const name = (0, checker_1.getIdentifierText)(node);
258
+ if (name === undefined)
259
+ return;
260
+ if (colors === undefined)
261
+ throw "symbolTable is undefined";
262
+ const color = createColor(node);
263
+ colors.set(name, color);
264
+ return;
265
+ }
266
+ console.warn("ensureSymbol called on non-identifier node");
267
+ debugger;
268
+ }
269
+ function createSymbol(name, node) {
270
+ if (!name)
271
+ throw "name is falsy";
272
+ if (!node)
273
+ throw "node is undefined or null";
274
+ return {
275
+ name,
276
+ firstMention: node,
277
+ references: undefined,
278
+ };
279
+ }
280
+ function createColor(node) {
281
+ return {
282
+ node,
283
+ };
284
+ }
285
+ function isAttributeName(name, id) {
286
+ return id ? (0, checker_1.getIdentifierText)(id).trim().toLowerCase() === name : false;
287
+ }
288
+ return {
289
+ bind: file => {
290
+ symbolTable = createSymbolTable();
291
+ colorTable = createColorTable();
292
+ const { graph } = file;
293
+ if (graph)
294
+ bind(graph);
295
+ file.symbols = symbolTable;
296
+ file.colors = colorTable;
297
+ },
298
+ };
299
+ }
300
+ //# sourceMappingURL=binder.js.map
@@ -0,0 +1,14 @@
1
+ import { SyntaxNode, Identifier, SyntaxKind, Graph, EdgeStatement, EdgeRhs, SourceFile, SubGraphStatement, NodeId, AttributeStatement, Statement, StatementOf, Token } from "./types";
2
+ export declare function checkSourceFile(file: SourceFile): void;
3
+ export declare function findNodeAtOffset(root: SyntaxNode, offset: number, inclusiveEnd?: boolean): SyntaxNode | undefined;
4
+ export declare function getAllowedEdgeOperation(graph: Graph): SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp;
5
+ export declare function findAllEdges(node: SyntaxNode): EdgeRhs[];
6
+ export declare function findOptionalSemicolons(node: SyntaxNode): Token<SyntaxKind.SemicolonToken>[];
7
+ export declare function findAllStatements<T extends Statement["kind"]>(node: SyntaxNode, kind?: T): StatementOf<T>[];
8
+ export declare function isAttrStatement(node: SyntaxNode): node is AttributeStatement;
9
+ export declare function isEdgeStatement(node: SyntaxNode): node is EdgeStatement;
10
+ export declare function isSubGraphStatement(node: SyntaxNode): node is SubGraphStatement;
11
+ export declare function isNodeId(node: SyntaxNode): node is NodeId;
12
+ export declare function edgeStatementHasAttributes(es: EdgeStatement): boolean;
13
+ export declare function getIdentifierText(n: Identifier): string;
14
+ export declare function nodeContainsErrors(node: SyntaxNode): boolean;
package/lib/checker.js ADDED
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeContainsErrors = exports.getIdentifierText = exports.edgeStatementHasAttributes = exports.isNodeId = exports.isSubGraphStatement = exports.isEdgeStatement = exports.isAttrStatement = exports.findAllStatements = exports.findOptionalSemicolons = exports.findAllEdges = exports.getAllowedEdgeOperation = exports.findNodeAtOffset = exports.checkSourceFile = void 0;
4
+ const types_1 = require("./types");
5
+ const util_1 = require("./service/util");
6
+ const visitor_1 = require("./visitor");
7
+ function checkSourceFile(file) {
8
+ const g = file.graph;
9
+ if (g) {
10
+ const messages = checkGraphSemantics(file, g);
11
+ if (messages) {
12
+ file.diagnostics.push.apply(file.diagnostics, messages);
13
+ }
14
+ }
15
+ }
16
+ exports.checkSourceFile = checkSourceFile;
17
+ function getNarrowerNode(offset, prev, toCheck) {
18
+ const prevRange = prev.end - prev.pos;
19
+ if (toCheck.pos <= offset && offset <= toCheck.end) {
20
+ let nrange = toCheck.end - toCheck.pos;
21
+ if (nrange < prevRange) {
22
+ return toCheck;
23
+ }
24
+ }
25
+ return prev;
26
+ }
27
+ function rangeContainsOffset(range, offset, inclusiveEnd) {
28
+ return inclusiveEnd
29
+ ? range.pos <= offset && offset <= range.end
30
+ : range.pos <= offset && offset < range.end;
31
+ }
32
+ function findNodeAtOffset(root, offset, inclusiveEnd = false) {
33
+ if (root.pos === offset && root.pos === root.end)
34
+ return root;
35
+ if (rangeContainsOffset(root, offset, inclusiveEnd)) {
36
+ const narrowerChild = (0, visitor_1.forEachChild)(root, child => findNodeAtOffset(child, offset, inclusiveEnd));
37
+ return narrowerChild ? narrowerChild : root;
38
+ }
39
+ return undefined;
40
+ }
41
+ exports.findNodeAtOffset = findNodeAtOffset;
42
+ function getAllowedEdgeOperation(graph) {
43
+ return graph.kind === types_1.SyntaxKind.DirectedGraph
44
+ ? types_1.SyntaxKind.DirectedEdgeOp
45
+ : types_1.SyntaxKind.UndirectedEdgeOp;
46
+ }
47
+ exports.getAllowedEdgeOperation = getAllowedEdgeOperation;
48
+ function checkGraphSemantics(file, root) {
49
+ const expectedEdgeOp = getAllowedEdgeOperation(root);
50
+ const invalidEdgeRhses = findEdgeErrors(expectedEdgeOp, root);
51
+ return invalidEdgeRhses == undefined || invalidEdgeRhses.length === 0
52
+ ? undefined
53
+ : createEdgeViolationDiagnostics(file, expectedEdgeOp, invalidEdgeRhses);
54
+ }
55
+ function findAllEdges(node) {
56
+ const allEdges = [];
57
+ (0, visitor_1.forEachChild)(node, child => {
58
+ if (isEdgeStatement(child)) {
59
+ if (child.rhs && child.rhs.length > 0) {
60
+ for (const edgeRhs of child.rhs)
61
+ allEdges.push(edgeRhs);
62
+ }
63
+ }
64
+ const childEdges = findAllEdges(child);
65
+ if (childEdges && childEdges.length > 0)
66
+ allEdges.push.apply(allEdges, childEdges);
67
+ });
68
+ return allEdges;
69
+ }
70
+ exports.findAllEdges = findAllEdges;
71
+ function findOptionalSemicolons(node) {
72
+ const statements = findAllStatements(node);
73
+ const terminators = statements.map(p => p.terminator);
74
+ return terminators.filter(t => !!t);
75
+ }
76
+ exports.findOptionalSemicolons = findOptionalSemicolons;
77
+ function isStatement(node) {
78
+ return node.kind === types_1.SyntaxKind.SubGraphStatement
79
+ || node.kind === types_1.SyntaxKind.EdgeStatement
80
+ || node.kind === types_1.SyntaxKind.NodeStatement
81
+ || node.kind === types_1.SyntaxKind.IdEqualsIdStatement
82
+ || node.kind === types_1.SyntaxKind.AttributeStatement;
83
+ }
84
+ function findAllStatements(node, kind) {
85
+ const allStatements = [];
86
+ (0, visitor_1.forEachChild)(node, child => {
87
+ if ((kind === undefined && isStatement(child)) || (child.kind === kind)) {
88
+ allStatements.push(child);
89
+ }
90
+ const childStatements = findAllStatements(child, kind);
91
+ if (childStatements && childStatements.length > 0)
92
+ allStatements.push.apply(allStatements, childStatements);
93
+ });
94
+ return allStatements;
95
+ }
96
+ exports.findAllStatements = findAllStatements;
97
+ function findEdgeErrors(expectedEdgeOp, node) {
98
+ const edges = findAllEdges(node);
99
+ const wrongEdges = edges && edges.length > 0
100
+ ? edges.filter(e => e.operation.kind !== expectedEdgeOp)
101
+ : undefined;
102
+ if (wrongEdges && wrongEdges.length > 0) {
103
+ wrongEdges.forEach(e => e.operation.flags |= 2);
104
+ return wrongEdges;
105
+ }
106
+ return undefined;
107
+ }
108
+ function createEdgeViolationDiagnostics(file, expectedEdgeOp, violators) {
109
+ const op = expectedEdgeOp === types_1.SyntaxKind.UndirectedEdgeOp ? "--" : "->";
110
+ const graphType = expectedEdgeOp === types_1.SyntaxKind.UndirectedEdgeOp ? "undirected" : "directed";
111
+ const message = `Invalid edge operation, use "${op}" in ${graphType} graph`;
112
+ const code = createCheckerError(0);
113
+ const category = types_1.DiagnosticCategory.Error;
114
+ violators.forEach(edge => edge.operation.flags |= 2);
115
+ return violators.map(edge => {
116
+ const start = (0, util_1.getStart)(file, edge.operation);
117
+ const end = edge.operation.end;
118
+ return {
119
+ message,
120
+ code,
121
+ category,
122
+ start,
123
+ end,
124
+ };
125
+ });
126
+ }
127
+ function getInvalidEdgeRhs(allowedOp, edges) {
128
+ const res = [];
129
+ for (const e of edges) {
130
+ if (e.operation.kind !== allowedOp)
131
+ res.push(e);
132
+ }
133
+ return res;
134
+ }
135
+ function isAttrStatement(node) {
136
+ return node.kind === types_1.SyntaxKind.AttributeStatement;
137
+ }
138
+ exports.isAttrStatement = isAttrStatement;
139
+ function isEdgeStatement(node) {
140
+ return node.kind === types_1.SyntaxKind.EdgeStatement;
141
+ }
142
+ exports.isEdgeStatement = isEdgeStatement;
143
+ function isSubGraphStatement(node) {
144
+ return node.kind === types_1.SyntaxKind.SubGraphStatement;
145
+ }
146
+ exports.isSubGraphStatement = isSubGraphStatement;
147
+ function isGraph(node) {
148
+ return node.kind === types_1.SyntaxKind.DirectedGraph || node.kind === types_1.SyntaxKind.UndirectedGraph;
149
+ }
150
+ function isNodeId(node) {
151
+ return node.kind === types_1.SyntaxKind.NodeId;
152
+ }
153
+ exports.isNodeId = isNodeId;
154
+ function edgeStatementHasAttributes(es) {
155
+ return es.attributes
156
+ && es.attributes.length > 0
157
+ && es.attributes.some(a => a.assignments && a.assignments.length > 0);
158
+ }
159
+ exports.edgeStatementHasAttributes = edgeStatementHasAttributes;
160
+ function getIdentifierText(n) {
161
+ switch (n.kind) {
162
+ case types_1.SyntaxKind.HtmlIdentifier:
163
+ return n.htmlContent;
164
+ case types_1.SyntaxKind.TextIdentifier:
165
+ return n.text;
166
+ case types_1.SyntaxKind.NumericIdentifier:
167
+ return n.text;
168
+ case types_1.SyntaxKind.QuotedTextIdentifier:
169
+ return n.concatenation;
170
+ default:
171
+ return (0, util_1.assertNever)(n);
172
+ }
173
+ }
174
+ exports.getIdentifierText = getIdentifierText;
175
+ function createCheckerError(sub) {
176
+ return {
177
+ source: 4,
178
+ sub,
179
+ };
180
+ }
181
+ function nodeContainsErrors(node) {
182
+ return (node.flags & 2) === 2;
183
+ }
184
+ exports.nodeContainsErrors = nodeContainsErrors;
185
+ //# sourceMappingURL=checker.js.map
package/lib/core.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function createMapFromTemplate<T>(template: Record<string, T>): Map<string, T>;
package/lib/core.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMapFromTemplate = void 0;
4
+ function createMapFromTemplate(template) {
5
+ const map = new Map();
6
+ for (const key in template) {
7
+ if (template.hasOwnProperty(key)) {
8
+ map.set(key, template[key]);
9
+ }
10
+ }
11
+ return map;
12
+ }
13
+ exports.createMapFromTemplate = createMapFromTemplate;
14
+ //# sourceMappingURL=core.js.map
package/lib/error.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { ErrorCode } from "./types";
2
+ export declare const diagnosicSource = "DOT";
3
+ export declare function formatError(error: ErrorCode): string;
package/lib/error.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatError = exports.diagnosicSource = void 0;
4
+ exports.diagnosicSource = "DOT";
5
+ const errorCodeLength = 4;
6
+ const subErrorCodeLength = errorCodeLength - 1;
7
+ function formatError(error) {
8
+ const subCode = (error.sub | 0)
9
+ .toString()
10
+ .padStart(subErrorCodeLength, "0");
11
+ return exports.diagnosicSource + error.source + subCode;
12
+ }
13
+ exports.formatError = formatError;
14
+ //# sourceMappingURL=error.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from "./types";
2
+ export * from "./scanner";
3
+ export * from "./parser";
4
+ export * from "./visitor";
5
+ export * from "./service/service";
6
+ export * from "./service/interop";
package/lib/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./types"), exports);
14
+ __exportStar(require("./scanner"), exports);
15
+ __exportStar(require("./parser"), exports);
16
+ __exportStar(require("./visitor"), exports);
17
+ __exportStar(require("./service/service"), exports);
18
+ __exportStar(require("./service/interop"), exports);
19
+ //# sourceMappingURL=index.js.map