circuitscript 0.1.33 → 0.3.0
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/dist/cjs/BaseVisitor.js +32 -32
- package/dist/cjs/BomGeneration.js +2 -3
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/SemanticTokenVisitor.js +1 -1
- package/dist/cjs/antlr/CircuitScriptParser.js +3 -3
- package/dist/cjs/builtinMethods.js +2 -2
- package/dist/cjs/environment.js +14 -6
- package/dist/cjs/execute.js +28 -24
- package/dist/cjs/globals.js +2 -1
- package/dist/cjs/graph.js +1 -1
- package/dist/cjs/helpers.js +28 -29
- package/dist/cjs/objects/ExecutionScope.js +1 -1
- package/dist/cjs/objects/types.js +7 -18
- package/dist/cjs/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/cjs/visitor.js +6 -6
- package/dist/esm/BaseVisitor.js +33 -33
- package/dist/esm/BomGeneration.js +2 -3
- package/dist/esm/ComponentMatchConditions.js +2 -2
- package/dist/esm/SemanticTokenVisitor.js +1 -1
- package/dist/esm/antlr/CircuitScriptParser.js +6 -6
- package/dist/esm/builtinMethods.js +3 -3
- package/dist/esm/environment.js +10 -2
- package/dist/esm/execute.js +28 -24
- package/dist/esm/globals.js +2 -1
- package/dist/esm/graph.js +2 -2
- package/dist/esm/helpers.js +28 -29
- package/dist/esm/objects/ExecutionScope.js +1 -1
- package/dist/esm/objects/types.js +8 -19
- package/dist/esm/validate/SymbolValidatorVisitor.js +7 -7
- package/dist/esm/visitor.js +7 -7
- package/dist/types/BaseVisitor.d.ts +6 -6
- package/dist/types/BomGeneration.d.ts +2 -1
- package/dist/types/antlr/CircuitScriptParser.d.ts +3 -3
- package/dist/types/environment.d.ts +7 -4
- package/dist/types/globals.d.ts +3 -2
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/objects/ExecutionScope.d.ts +2 -2
- package/dist/types/objects/types.d.ts +5 -15
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +1 -1
- package/dist/types/visitor.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/BaseVisitor.js
CHANGED
|
@@ -528,17 +528,17 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
528
528
|
});
|
|
529
529
|
specificImports.push(...tmpSpecificImports);
|
|
530
530
|
}
|
|
531
|
-
const id = ctx.
|
|
531
|
+
const id = ctx._libraryName.text;
|
|
532
532
|
const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
|
|
533
533
|
const ctxImportAnnotation = ctx.import_annotation_expr();
|
|
534
534
|
if (ctxImportAnnotation) {
|
|
535
535
|
const textValue = ctxImportAnnotation.getText().replace('#=', '');
|
|
536
|
-
const {
|
|
536
|
+
const { importedLibrary } = importedFile;
|
|
537
537
|
if (textValue === 'annotate') {
|
|
538
|
-
|
|
538
|
+
importedLibrary.enableRefdesAnnotation = true;
|
|
539
539
|
}
|
|
540
540
|
else if (textValue === 'annotate-external') {
|
|
541
|
-
|
|
541
|
+
importedLibrary.enableRefdesAnnotationFile = true;
|
|
542
542
|
}
|
|
543
543
|
}
|
|
544
544
|
}
|
|
@@ -585,23 +585,23 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
585
585
|
}
|
|
586
586
|
const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
|
|
587
587
|
try {
|
|
588
|
-
const
|
|
589
|
-
&& currentReference.rootValue instanceof types_js_1.
|
|
590
|
-
if (
|
|
591
|
-
this.log('create new
|
|
592
|
-
const
|
|
593
|
-
const
|
|
594
|
-
this.enterFile(
|
|
595
|
-
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack,
|
|
588
|
+
const isLibraryFunction = currentReference.rootValue
|
|
589
|
+
&& currentReference.rootValue instanceof types_js_1.ImportedLibrary;
|
|
590
|
+
if (isLibraryFunction) {
|
|
591
|
+
this.log('create new library context');
|
|
592
|
+
const importedLibrary = currentReference.rootValue;
|
|
593
|
+
const { context: importedLibraryContext } = importedLibrary;
|
|
594
|
+
this.enterFile(importedLibrary.libraryFilePath);
|
|
595
|
+
const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
|
|
596
596
|
netNamespace: executor.netNamespace,
|
|
597
|
-
namespace:
|
|
597
|
+
namespace: importedLibrary.libraryNamespace
|
|
598
598
|
}, [], [], false);
|
|
599
|
-
this.log('copy
|
|
600
|
-
|
|
599
|
+
this.log('copy library context scope');
|
|
600
|
+
importedLibraryContext.scope.copyTo(newExecutor.scope);
|
|
601
601
|
}
|
|
602
602
|
const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
|
|
603
|
-
if (
|
|
604
|
-
this.log('pop
|
|
603
|
+
if (isLibraryFunction) {
|
|
604
|
+
this.log('pop library context scope');
|
|
605
605
|
this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
|
|
606
606
|
this.exitFile();
|
|
607
607
|
}
|
|
@@ -717,8 +717,8 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
717
717
|
return item.id === name;
|
|
718
718
|
});
|
|
719
719
|
if (importAlready) {
|
|
720
|
-
const
|
|
721
|
-
const alreadyImportedFlag =
|
|
720
|
+
const { importedLibrary: tmpImportedLibrary } = importAlready;
|
|
721
|
+
const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
|
|
722
722
|
const isMergedNamespace = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace
|
|
723
723
|
|| alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
724
724
|
const invalidImportCondition1 = alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllWithNamespace &&
|
|
@@ -732,11 +732,11 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
732
732
|
if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
733
733
|
}
|
|
734
734
|
else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace) {
|
|
735
|
-
|
|
736
|
-
|
|
735
|
+
tmpImportedLibrary.specifiedImports = [];
|
|
736
|
+
tmpImportedLibrary.importHandlingFlag = types_js_1.ImportFunctionHandling.AllMergeIntoNamespace;
|
|
737
737
|
}
|
|
738
738
|
else if (alreadyImportedFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace) {
|
|
739
|
-
|
|
739
|
+
tmpImportedLibrary.specifiedImports.push(...specificImports);
|
|
740
740
|
}
|
|
741
741
|
}
|
|
742
742
|
return importAlready;
|
|
@@ -757,7 +757,7 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
757
757
|
this.log('failed to read file');
|
|
758
758
|
pathExists = false;
|
|
759
759
|
}
|
|
760
|
-
let
|
|
760
|
+
let importedLibrary;
|
|
761
761
|
if (!pathExists) {
|
|
762
762
|
try {
|
|
763
763
|
const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
|
|
@@ -778,26 +778,26 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
778
778
|
const executor = this.getExecutor();
|
|
779
779
|
const executionContextName = name;
|
|
780
780
|
const netNamespace = executor.netNamespace;
|
|
781
|
-
const
|
|
781
|
+
const libraryNamespace = `${globals_js_1.BaseNamespace}${name}.`;
|
|
782
782
|
this.enterNewChildContext(executionStack, executor, executionContextName, {
|
|
783
783
|
netNamespace,
|
|
784
|
-
namespace:
|
|
784
|
+
namespace: libraryNamespace,
|
|
785
785
|
}, [], []);
|
|
786
786
|
const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
|
|
787
787
|
hasError = importResult.hasError;
|
|
788
788
|
hasParseError = importResult.hasParseError;
|
|
789
789
|
const importContext = executionStack.pop();
|
|
790
790
|
this.log(`import handling flag: ${importHandling}`);
|
|
791
|
-
|
|
791
|
+
importedLibrary = new types_js_1.ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
|
|
792
792
|
if (specificImports.length > 0) {
|
|
793
793
|
this.log('specific import: ' + specificImports.join(', '));
|
|
794
794
|
}
|
|
795
795
|
const scope = this.getScope();
|
|
796
|
-
scope.
|
|
797
|
-
|
|
798
|
-
scope.
|
|
796
|
+
scope.libraries.set(name, importedLibrary);
|
|
797
|
+
importedLibrary.context.scope.libraries.forEach((lib, key) => {
|
|
798
|
+
scope.libraries.set(key, lib);
|
|
799
799
|
});
|
|
800
|
-
await this.
|
|
800
|
+
await this.checkLibraryHasRefdesFile(filePathUsed);
|
|
801
801
|
}
|
|
802
802
|
}
|
|
803
803
|
catch (err) {
|
|
@@ -825,12 +825,12 @@ class BaseVisitor extends CircuitScriptVisitor_js_1.CircuitScriptVisitor {
|
|
|
825
825
|
hasError,
|
|
826
826
|
hasParseError,
|
|
827
827
|
pathExists,
|
|
828
|
-
|
|
828
|
+
importedLibrary: importedLibrary
|
|
829
829
|
};
|
|
830
830
|
this.importedFiles.push(newImportedFile);
|
|
831
831
|
return newImportedFile;
|
|
832
832
|
}
|
|
833
|
-
async
|
|
833
|
+
async checkLibraryHasRefdesFile(filePath) {
|
|
834
834
|
return;
|
|
835
835
|
}
|
|
836
836
|
getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
|
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.saveBomOutputCsv = exports.generateBomCSV = exports.groupComponents = exports.generateBom = void 0;
|
|
27
27
|
const csv = __importStar(require("@fast-csv/format"));
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
28
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
30
29
|
const TypeSortOrder = {
|
|
31
30
|
"res": 1,
|
|
@@ -151,9 +150,9 @@ function generateBomCSV(bomData) {
|
|
|
151
150
|
return rows;
|
|
152
151
|
}
|
|
153
152
|
exports.generateBomCSV = generateBomCSV;
|
|
154
|
-
async function saveBomOutputCsv(bomCsvOutput, filePath) {
|
|
153
|
+
async function saveBomOutputCsv(environment, bomCsvOutput, filePath) {
|
|
155
154
|
return new Promise(resolve => {
|
|
156
|
-
const outputStream =
|
|
155
|
+
const outputStream = environment.createWriteStream(filePath);
|
|
157
156
|
const csvStream = csv.format();
|
|
158
157
|
csvStream.pipe(outputStream).on("finish", () => {
|
|
159
158
|
resolve();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyPartConditions = exports.partMatchesConditions = exports.extractPartConditions = exports.flattenConditionNodes = void 0;
|
|
4
|
+
const globals_js_1 = require("./globals.js");
|
|
4
5
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
5
|
-
const types_js_1 = require("./objects/types.js");
|
|
6
6
|
function flattenConditionNodes(conditionNodes, level = 0) {
|
|
7
7
|
const conditionBranches = [];
|
|
8
8
|
conditionNodes.forEach(node => {
|
|
@@ -101,7 +101,7 @@ function partMatchesConditions(instance, partConditions) {
|
|
|
101
101
|
exports.partMatchesConditions = partMatchesConditions;
|
|
102
102
|
function applyPartConditions(instances, paramKeys, partConditions) {
|
|
103
103
|
instances.forEach(item => {
|
|
104
|
-
if (item.typeProp !==
|
|
104
|
+
if (item.typeProp !== globals_js_1.ComponentTypes.graphic) {
|
|
105
105
|
const matchedResult = partMatchesConditions(item, partConditions);
|
|
106
106
|
if (matchedResult !== undefined) {
|
|
107
107
|
paramKeys.forEach((paramKey, index) => {
|
|
@@ -211,7 +211,7 @@ exports.prepareTokens = prepareTokens;
|
|
|
211
211
|
const languageKeywords = [
|
|
212
212
|
'break', 'branch', 'create', 'component',
|
|
213
213
|
'graphic', 'wire', 'pin', 'add', 'at', 'to',
|
|
214
|
-
'point', 'join', 'parallel', 'return', 'def', 'import',
|
|
214
|
+
'point', 'join', 'parallel', 'return', 'def', 'from', 'import',
|
|
215
215
|
'true', 'false', 'nc', 'sheet', 'frame', 'if', 'else', 'for', 'in',
|
|
216
216
|
];
|
|
217
217
|
const operatorKeywords = [
|
|
@@ -3406,7 +3406,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3406
3406
|
this.state = 686;
|
|
3407
3407
|
this.match(CircuitScriptParser.Import);
|
|
3408
3408
|
this.state = 687;
|
|
3409
|
-
localContext.
|
|
3409
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3410
3410
|
this.state = 689;
|
|
3411
3411
|
this.errorHandler.sync(this);
|
|
3412
3412
|
switch (this.interpreter.adaptivePredict(this.tokenStream, 76, this.context)) {
|
|
@@ -3426,7 +3426,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3426
3426
|
this.state = 691;
|
|
3427
3427
|
this.match(CircuitScriptParser.From);
|
|
3428
3428
|
this.state = 692;
|
|
3429
|
-
localContext.
|
|
3429
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3430
3430
|
this.state = 693;
|
|
3431
3431
|
this.match(CircuitScriptParser.Import);
|
|
3432
3432
|
this.state = 694;
|
|
@@ -3450,7 +3450,7 @@ class CircuitScriptParser extends antlr.Parser {
|
|
|
3450
3450
|
this.state = 698;
|
|
3451
3451
|
this.match(CircuitScriptParser.From);
|
|
3452
3452
|
this.state = 699;
|
|
3453
|
-
localContext.
|
|
3453
|
+
localContext._libraryName = this.match(CircuitScriptParser.ID);
|
|
3454
3454
|
this.state = 700;
|
|
3455
3455
|
this.match(CircuitScriptParser.Import);
|
|
3456
3456
|
this.state = 701;
|
|
@@ -156,8 +156,8 @@ function toString(obj) {
|
|
|
156
156
|
else if (obj instanceof types_js_1.CFunctionEntry) {
|
|
157
157
|
return obj.toString();
|
|
158
158
|
}
|
|
159
|
-
else if (obj instanceof types_js_1.
|
|
160
|
-
return `[
|
|
159
|
+
else if (obj instanceof types_js_1.ImportedLibrary) {
|
|
160
|
+
return `[library: ${obj.libraryName}]`;
|
|
161
161
|
}
|
|
162
162
|
else {
|
|
163
163
|
if (obj === undefined) {
|
package/dist/cjs/environment.js
CHANGED
|
@@ -5,8 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.NodeScriptEnvironment = void 0;
|
|
7
7
|
const svg_js_1 = require("@svgdotjs/svg.js");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const fs_2 = __importDefault(require("fs"));
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
12
11
|
const globals_js_1 = require("./globals.js");
|
|
@@ -22,6 +21,12 @@ class NodeScriptEnvironment {
|
|
|
22
21
|
'Arial': 'Arial.ttf',
|
|
23
22
|
};
|
|
24
23
|
}
|
|
24
|
+
existsSync(pathLike) {
|
|
25
|
+
return fs_1.default.existsSync(pathLike);
|
|
26
|
+
}
|
|
27
|
+
mkdirSync(pathLike) {
|
|
28
|
+
return fs_1.default.mkdirSync(pathLike);
|
|
29
|
+
}
|
|
25
30
|
static setInstance(instance) {
|
|
26
31
|
NodeScriptEnvironment._instance = instance;
|
|
27
32
|
}
|
|
@@ -40,7 +45,7 @@ class NodeScriptEnvironment {
|
|
|
40
45
|
}
|
|
41
46
|
try {
|
|
42
47
|
const packageJsonPath = path_1.default.join(this.getToolsPath(), '../', 'package.json');
|
|
43
|
-
const packageJsonContent =
|
|
48
|
+
const packageJsonContent = fs_1.default.readFileSync(packageJsonPath, 'utf-8');
|
|
44
49
|
const packageJson = JSON.parse(packageJsonContent);
|
|
45
50
|
this.cachedVersion = packageJson.version || globals_js_1.TOOL_VERSION;
|
|
46
51
|
return this.cachedVersion;
|
|
@@ -120,10 +125,10 @@ class NodeScriptEnvironment {
|
|
|
120
125
|
}
|
|
121
126
|
async readFile(path, options) {
|
|
122
127
|
options = options ?? { encoding: 'utf8' };
|
|
123
|
-
return
|
|
128
|
+
return fs_1.default.promises.readFile(path, options);
|
|
124
129
|
}
|
|
125
130
|
writeFileSync(path, data) {
|
|
126
|
-
return
|
|
131
|
+
return fs_1.default.writeFileSync(path, data);
|
|
127
132
|
}
|
|
128
133
|
getAbsolutePath(filePath) {
|
|
129
134
|
return path_1.default.resolve(filePath);
|
|
@@ -143,7 +148,7 @@ class NodeScriptEnvironment {
|
|
|
143
148
|
}
|
|
144
149
|
async exists(path) {
|
|
145
150
|
try {
|
|
146
|
-
await
|
|
151
|
+
await fs_1.default.promises.access(path, fs_1.default.constants.F_OK);
|
|
147
152
|
return true;
|
|
148
153
|
}
|
|
149
154
|
catch (err) {
|
|
@@ -168,6 +173,9 @@ class NodeScriptEnvironment {
|
|
|
168
173
|
relative(from, to) {
|
|
169
174
|
return path_1.default.relative(from, to);
|
|
170
175
|
}
|
|
176
|
+
createWriteStream(filePath) {
|
|
177
|
+
return fs_1.default.createWriteStream(filePath);
|
|
178
|
+
}
|
|
171
179
|
}
|
|
172
180
|
exports.NodeScriptEnvironment = NodeScriptEnvironment;
|
|
173
181
|
NodeScriptEnvironment._instance = null;
|
package/dist/cjs/execute.js
CHANGED
|
@@ -641,19 +641,18 @@ class ExecutionContext {
|
|
|
641
641
|
});
|
|
642
642
|
}
|
|
643
643
|
else {
|
|
644
|
-
const
|
|
645
|
-
for (
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
if (module.context.hasFunction(functionPath)) {
|
|
644
|
+
const libraries = Array.from(context.scope.libraries.values());
|
|
645
|
+
for (const library of libraries) {
|
|
646
|
+
if (library.importHandlingFlag === types_js_1.ImportFunctionHandling.AllMergeIntoNamespace ||
|
|
647
|
+
(library.importHandlingFlag === types_js_1.ImportFunctionHandling.SpecificMergeIntoNamespace
|
|
648
|
+
&& library.specifiedImports.indexOf(idName) !== -1)) {
|
|
649
|
+
const { context: libraryContext } = library;
|
|
650
|
+
const functionPath = `${libraryContext.namespace}${idName}`;
|
|
651
|
+
if (library.context.hasFunction(functionPath)) {
|
|
653
652
|
return new types_js_1.DeclaredReference({
|
|
654
653
|
found: true,
|
|
655
|
-
rootValue:
|
|
656
|
-
value:
|
|
654
|
+
rootValue: library,
|
|
655
|
+
value: library.context.getFunction(functionPath),
|
|
657
656
|
type: globals_js_1.ReferenceTypes.function,
|
|
658
657
|
name: idName,
|
|
659
658
|
trailerIndex: 1,
|
|
@@ -662,24 +661,24 @@ class ExecutionContext {
|
|
|
662
661
|
}
|
|
663
662
|
}
|
|
664
663
|
}
|
|
665
|
-
let
|
|
666
|
-
if (context.scope.
|
|
667
|
-
const
|
|
668
|
-
if (
|
|
669
|
-
|
|
664
|
+
let isLibrary = false;
|
|
665
|
+
if (context.scope.libraries.has(idName)) {
|
|
666
|
+
const library = context.scope.libraries.get(idName);
|
|
667
|
+
if (library.importHandlingFlag === types_js_1.ImportFunctionHandling.AllWithNamespace) {
|
|
668
|
+
isLibrary = true;
|
|
670
669
|
}
|
|
671
670
|
}
|
|
672
671
|
let isVariable = context.scope.variables.has(idName);
|
|
673
672
|
let isComponentInstance = context.scope.instances.has(idName);
|
|
674
|
-
if (
|
|
675
|
-
const scopeList =
|
|
673
|
+
if (isLibrary || isVariable || isComponentInstance) {
|
|
674
|
+
const scopeList = isLibrary ? context.scope.libraries :
|
|
676
675
|
(isVariable ? context.scope.variables : context.scope.instances);
|
|
677
676
|
const useValue = scopeList.get(idName);
|
|
678
677
|
if (!isComponentInstance && (useValue instanceof ClassComponent_js_1.ClassComponent)) {
|
|
679
678
|
isComponentInstance = true;
|
|
680
679
|
isVariable = false;
|
|
681
680
|
}
|
|
682
|
-
const referenceType =
|
|
681
|
+
const referenceType = isLibrary ? globals_js_1.ReferenceTypes.library :
|
|
683
682
|
(isVariable ? globals_js_1.ReferenceTypes.variable : globals_js_1.ReferenceTypes.instance);
|
|
684
683
|
const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
|
|
685
684
|
return new types_js_1.DeclaredReference({
|
|
@@ -726,12 +725,12 @@ class ExecutionContext {
|
|
|
726
725
|
}
|
|
727
726
|
break;
|
|
728
727
|
}
|
|
729
|
-
case globals_js_1.ReferenceTypes.
|
|
728
|
+
case globals_js_1.ReferenceTypes.library: {
|
|
730
729
|
const funcName = trailers[0];
|
|
731
|
-
const
|
|
732
|
-
const functionPath = `${
|
|
733
|
-
if (
|
|
734
|
-
const foundFunc =
|
|
730
|
+
const library = rootValue;
|
|
731
|
+
const functionPath = `${library.libraryNamespace}${funcName}`;
|
|
732
|
+
if (library.context.hasFunction(functionPath)) {
|
|
733
|
+
const foundFunc = library.context.getFunction(functionPath);
|
|
735
734
|
return new types_js_1.AnyReference({
|
|
736
735
|
found: true,
|
|
737
736
|
type: globals_js_1.ReferenceTypes.function,
|
|
@@ -1012,6 +1011,11 @@ class ExecutionContext {
|
|
|
1012
1011
|
globals_js_1.ParamKeys.flipY,
|
|
1013
1012
|
];
|
|
1014
1013
|
if (unitModifiers.indexOf(paramName) !== -1) {
|
|
1014
|
+
if (paramName === globals_js_1.ParamKeys.flipX || paramName == globals_js_1.ParamKeys.flipY) {
|
|
1015
|
+
if (typeof value === "boolean") {
|
|
1016
|
+
value = value ? (0, ParamDefinition_js_1.numeric)(1) : (0, ParamDefinition_js_1.numeric)(0);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1015
1019
|
component.getUnit().setParam(paramName, value);
|
|
1016
1020
|
}
|
|
1017
1021
|
}
|
package/dist/cjs/globals.js
CHANGED
|
@@ -91,6 +91,7 @@ var ComponentTypes;
|
|
|
91
91
|
ComponentTypes["graphic"] = "graphic";
|
|
92
92
|
ComponentTypes["port"] = "port";
|
|
93
93
|
ComponentTypes["module"] = "module";
|
|
94
|
+
ComponentTypes["resistor"] = "res";
|
|
94
95
|
})(ComponentTypes || (exports.ComponentTypes = ComponentTypes = {}));
|
|
95
96
|
var ReferenceTypes;
|
|
96
97
|
(function (ReferenceTypes) {
|
|
@@ -99,7 +100,7 @@ var ReferenceTypes;
|
|
|
99
100
|
ReferenceTypes["variable"] = "variable";
|
|
100
101
|
ReferenceTypes["instance"] = "instance";
|
|
101
102
|
ReferenceTypes["pinType"] = "pinType";
|
|
102
|
-
ReferenceTypes["
|
|
103
|
+
ReferenceTypes["library"] = "library";
|
|
103
104
|
ReferenceTypes["unknown"] = "unknown";
|
|
104
105
|
})(ReferenceTypes || (exports.ReferenceTypes = ReferenceTypes = {}));
|
|
105
106
|
var BlockTypes;
|
package/dist/cjs/graph.js
CHANGED
|
@@ -257,7 +257,7 @@ class NetGraph {
|
|
|
257
257
|
const netsLength = netsIndexed.length;
|
|
258
258
|
const conductanceMatrix = ml_matrix_1.default.zeros(netsLength, netsLength);
|
|
259
259
|
components.forEach(item => {
|
|
260
|
-
if (item.typeProp ===
|
|
260
|
+
if (item.typeProp === globals_js_1.ComponentTypes.resistor) {
|
|
261
261
|
const net1 = item.pinNets.get(1);
|
|
262
262
|
const net2 = item.pinNets.get(2);
|
|
263
263
|
const net1Index = netsIndexed.indexOf(net1);
|
package/dist/cjs/helpers.js
CHANGED
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getPaperSize = exports.isSupportedPaperSize = exports.PaperGridReferences = exports.pxToMM = exports.milsToMM = exports.UnitDimension = exports.detectJSModuleType = exports.KiCadNetListOutputHandler = exports.ParseOutputHandler = exports.renderScriptCustom = exports.renderScript = exports.validateScript = exports.ParseErrorStrategy = exports.getSemanticTokens = exports.prepareFile = exports.JSModuleType = void 0;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const pdfkit_1 = __importDefault(require("pdfkit"));
|
|
10
9
|
const export_js_1 = require("./export.js");
|
|
@@ -160,7 +159,7 @@ async function validateScript(filePath, scriptData, options) {
|
|
|
160
159
|
return visitorResolver;
|
|
161
160
|
}
|
|
162
161
|
exports.validateScript = validateScript;
|
|
163
|
-
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks,
|
|
162
|
+
async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
|
|
164
163
|
const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
|
|
165
164
|
if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
|
|
166
165
|
const annotatedFiles = [{
|
|
@@ -171,29 +170,29 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
171
170
|
filePath: inputPath,
|
|
172
171
|
outputType: RefdesOutputType.WithSource
|
|
173
172
|
}];
|
|
174
|
-
for (const
|
|
173
|
+
for (const library of importedLibraries) {
|
|
175
174
|
let outputType = RefdesOutputType.None;
|
|
176
|
-
if (
|
|
175
|
+
if (library.enableRefdesAnnotation) {
|
|
177
176
|
outputType = RefdesOutputType.WithSource;
|
|
178
177
|
}
|
|
179
|
-
else if (
|
|
178
|
+
else if (library.enableRefdesAnnotationFile) {
|
|
180
179
|
outputType = RefdesOutputType.CreateExternalFile;
|
|
181
180
|
}
|
|
182
181
|
if (outputType !== RefdesOutputType.None) {
|
|
183
|
-
const {
|
|
184
|
-
const
|
|
182
|
+
const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
|
|
183
|
+
const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
|
|
185
184
|
annotatedFiles.push({
|
|
186
|
-
tokens:
|
|
187
|
-
tree:
|
|
188
|
-
filePath:
|
|
189
|
-
scriptData:
|
|
190
|
-
|
|
185
|
+
tokens: libTokens,
|
|
186
|
+
tree: libTree,
|
|
187
|
+
filePath: libraryFilePath,
|
|
188
|
+
scriptData: libraryScriptData,
|
|
189
|
+
libraryName,
|
|
191
190
|
outputType
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
193
|
}
|
|
195
194
|
for (const item of annotatedFiles) {
|
|
196
|
-
const { scriptData, tokens, tree, filePath,
|
|
195
|
+
const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
|
|
197
196
|
const tmpVisitor = new RefdesAnnotationVisitor_js_1.RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
|
|
198
197
|
await tmpVisitor.visit(tree);
|
|
199
198
|
let usePath = filePath;
|
|
@@ -219,15 +218,15 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
|
|
|
219
218
|
const relativeFilePath = environment.relative(inputDir, filePath);
|
|
220
219
|
const jsonFile = {
|
|
221
220
|
format: 'v1',
|
|
222
|
-
|
|
221
|
+
library: libraryName,
|
|
223
222
|
file: relativeFilePath,
|
|
224
223
|
items: output,
|
|
225
224
|
};
|
|
226
225
|
environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
|
|
227
226
|
}
|
|
228
227
|
let display = 'Refdes annotations';
|
|
229
|
-
if (
|
|
230
|
-
display += ` for
|
|
228
|
+
if (libraryName) {
|
|
229
|
+
display += ` for library ${libraryName}`;
|
|
231
230
|
}
|
|
232
231
|
console.log(`${display} saved to ${usePath}`);
|
|
233
232
|
}
|
|
@@ -294,8 +293,8 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
294
293
|
const dumpDirectory = environment.getRelativeToModule('/dump/');
|
|
295
294
|
if (dumpData) {
|
|
296
295
|
console.log('Dump data to:', dumpDirectory);
|
|
297
|
-
if (!
|
|
298
|
-
|
|
296
|
+
if (!environment.existsSync(dumpDirectory)) {
|
|
297
|
+
environment.mkdirSync(dumpDirectory);
|
|
299
298
|
}
|
|
300
299
|
}
|
|
301
300
|
if (inputPath !== '') {
|
|
@@ -312,16 +311,16 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
312
311
|
throw new utils_js_1.RenderError(`Error during component annotation: ${err}`, 'annotation');
|
|
313
312
|
}
|
|
314
313
|
const componentLinks = visitor.getComponentCtxLinks();
|
|
315
|
-
const
|
|
314
|
+
const importedLibraries = Array.from(visitor.getScope().libraries.values());
|
|
316
315
|
for (let i = 0; i < postAnnotationCallbacks.length; i++) {
|
|
317
|
-
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks,
|
|
316
|
+
await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedLibraries, environment);
|
|
318
317
|
}
|
|
319
318
|
if (dumpNets) {
|
|
320
319
|
const nets = visitor.dumpNets();
|
|
321
320
|
nets.forEach(item => console.log(item.join(" | ")));
|
|
322
321
|
}
|
|
323
|
-
dumpData &&
|
|
324
|
-
dumpData &&
|
|
322
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
|
|
323
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
|
|
325
324
|
if (throwError) {
|
|
326
325
|
throw throwError;
|
|
327
326
|
}
|
|
@@ -334,11 +333,11 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
334
333
|
const bomConfig = documentVariable.bom;
|
|
335
334
|
const bomData = (0, BomGeneration_js_1.generateBom)(bomConfig, visitor.getScope().getInstances());
|
|
336
335
|
const bomCsvOutput = (0, BomGeneration_js_1.generateBomCSV)(bomData);
|
|
337
|
-
await (0, BomGeneration_js_1.saveBomOutputCsv)(bomCsvOutput, bomOutputPath);
|
|
336
|
+
await (0, BomGeneration_js_1.saveBomOutputCsv)(environment, bomCsvOutput, bomOutputPath);
|
|
338
337
|
console.log('Generated BOM file', bomOutputPath);
|
|
339
338
|
}
|
|
340
339
|
const tmpSequence = (0, utils_js_1.generateDebugSequenceAction)(sequence).map(item => (0, utils_js_1.sequenceActionString)(item));
|
|
341
|
-
dumpData &&
|
|
340
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
|
|
342
341
|
try {
|
|
343
342
|
let fileExtension = null;
|
|
344
343
|
let outputDefaultZoom = globals_js_1.defaultZoomScale;
|
|
@@ -383,7 +382,7 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
383
382
|
}
|
|
384
383
|
layoutEngine.printWarnings();
|
|
385
384
|
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
386
|
-
dumpData &&
|
|
385
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
|
|
387
386
|
const generateSvgTimer = new utils_js_1.SimpleStopwatch();
|
|
388
387
|
const renderLogger = new logger_js_1.Logger();
|
|
389
388
|
let svgCanvas;
|
|
@@ -394,7 +393,7 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
394
393
|
throw new utils_js_1.RenderError(`Error during SVG generation: ${err}`, 'svg_generation');
|
|
395
394
|
}
|
|
396
395
|
showStats && console.log('Render took:', generateSvgTimer.lap());
|
|
397
|
-
dumpData &&
|
|
396
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'raw-render.txt', renderLogger.dump());
|
|
398
397
|
try {
|
|
399
398
|
if (fileExtension === "pdf") {
|
|
400
399
|
outputDefaultZoom = 1;
|
|
@@ -407,7 +406,7 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
407
406
|
if (outputPath) {
|
|
408
407
|
if (fileExtension === 'svg') {
|
|
409
408
|
try {
|
|
410
|
-
|
|
409
|
+
environment.writeFileSync(outputPath, svgOutput);
|
|
411
410
|
}
|
|
412
411
|
catch (err) {
|
|
413
412
|
throw new utils_js_1.RenderError(`Error writing SVG file: ${err}`, 'file_output');
|
|
@@ -425,7 +424,7 @@ async function renderScriptCustom(scriptData, outputPath, options, parseHandlers
|
|
|
425
424
|
layout: 'landscape',
|
|
426
425
|
size: sheetSize
|
|
427
426
|
});
|
|
428
|
-
const outputStream =
|
|
427
|
+
const outputStream = environment.createWriteStream(outputPath);
|
|
429
428
|
(0, render_js_1.generatePdfOutput)(doc, svgCanvas, sheetSize, sheetSizeDefined, outputDefaultZoom);
|
|
430
429
|
doc.pipe(outputStream);
|
|
431
430
|
doc.end();
|
|
@@ -468,7 +467,7 @@ class KiCadNetListOutputHandler extends ParseOutputHandler {
|
|
|
468
467
|
missingFootprints.forEach(entry => {
|
|
469
468
|
console.log(`${entry.refdes} (${entry.instanceName}) does not have footprint`);
|
|
470
469
|
});
|
|
471
|
-
|
|
470
|
+
visitor.environment.writeFileSync(outputPath, (0, export_js_1.printTree)(kiCadNetList));
|
|
472
471
|
console.log('Generated file', outputPath);
|
|
473
472
|
return false;
|
|
474
473
|
}
|
|
@@ -12,7 +12,7 @@ class ExecutionScope {
|
|
|
12
12
|
this.functionCounter = new Map();
|
|
13
13
|
this.variables = new Map();
|
|
14
14
|
this.symbols = new Map();
|
|
15
|
-
this.
|
|
15
|
+
this.libraries = new Map();
|
|
16
16
|
this.blockStack = new Map();
|
|
17
17
|
this.contextStack = [];
|
|
18
18
|
this.onPropertyHandler = [];
|