circuitscript 0.0.22 → 0.0.25
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 +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MainLexer = void 0;
|
|
4
|
+
const antlr4ng_1 = require("antlr4ng");
|
|
5
|
+
const CircuitScriptParser_js_1 = require("./antlr/CircuitScriptParser.js");
|
|
6
|
+
const CircuitScriptLexer_js_1 = require("./antlr/CircuitScriptLexer.js");
|
|
7
|
+
class MainLexer extends CircuitScriptLexer_js_1.CircuitScriptLexer {
|
|
8
|
+
constructor(input) {
|
|
9
|
+
super(input);
|
|
10
|
+
this.tokens = [];
|
|
11
|
+
this.indents = [];
|
|
12
|
+
this.opened = 0;
|
|
13
|
+
}
|
|
14
|
+
reset() {
|
|
15
|
+
this.tokens = [];
|
|
16
|
+
this.indents = [];
|
|
17
|
+
this.opened = 0;
|
|
18
|
+
super.reset();
|
|
19
|
+
}
|
|
20
|
+
emitToken(token) {
|
|
21
|
+
super.emitToken(token);
|
|
22
|
+
this.tokens.push(token);
|
|
23
|
+
}
|
|
24
|
+
nextToken() {
|
|
25
|
+
if (this.inputStream.LA(1) === CircuitScriptParser_js_1.CircuitScriptParser.EOF && this.indents.length) {
|
|
26
|
+
this.tokens = this.tokens.filter(function (val) {
|
|
27
|
+
return val.type !== CircuitScriptParser_js_1.CircuitScriptParser.EOF;
|
|
28
|
+
});
|
|
29
|
+
this.emitToken(this.commonToken(CircuitScriptParser_js_1.CircuitScriptParser.NEWLINE, "\n"));
|
|
30
|
+
while (this.indents.length) {
|
|
31
|
+
this.emitToken(this.createDedent());
|
|
32
|
+
this.indents.pop();
|
|
33
|
+
}
|
|
34
|
+
this.emitToken(this.commonToken(CircuitScriptParser_js_1.CircuitScriptParser.EOF, "<EOF>"));
|
|
35
|
+
}
|
|
36
|
+
const next = super.nextToken();
|
|
37
|
+
return this.tokens.length ? this.tokens.shift() : next;
|
|
38
|
+
}
|
|
39
|
+
createDedent() {
|
|
40
|
+
return this.commonToken(CircuitScriptParser_js_1.CircuitScriptParser.DEDENT, "");
|
|
41
|
+
}
|
|
42
|
+
getCharIndex() {
|
|
43
|
+
return this.inputStream.index;
|
|
44
|
+
}
|
|
45
|
+
commonToken(type, text) {
|
|
46
|
+
const stop = this.getCharIndex() - 1;
|
|
47
|
+
const start = text.length ? stop - text.length + 1 : stop;
|
|
48
|
+
const token = antlr4ng_1.CommonToken.fromSource([this, this.inputStream], type, 0, start, stop);
|
|
49
|
+
let tokenTypeString = null;
|
|
50
|
+
if (type === CircuitScriptParser_js_1.CircuitScriptParser.INDENT) {
|
|
51
|
+
tokenTypeString = "indent";
|
|
52
|
+
}
|
|
53
|
+
else if (type === CircuitScriptParser_js_1.CircuitScriptParser.DEDENT) {
|
|
54
|
+
tokenTypeString = "dedent";
|
|
55
|
+
}
|
|
56
|
+
if (tokenTypeString !== null) {
|
|
57
|
+
token.text = tokenTypeString;
|
|
58
|
+
}
|
|
59
|
+
return token;
|
|
60
|
+
}
|
|
61
|
+
getIndentationCount(whitespace) {
|
|
62
|
+
let count = 0;
|
|
63
|
+
for (let i = 0; i < whitespace.length; i++) {
|
|
64
|
+
if (whitespace[i] === '\t') {
|
|
65
|
+
count += 8 - count % 8;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
count++;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return count;
|
|
72
|
+
}
|
|
73
|
+
atStartOfInput() {
|
|
74
|
+
return this.getCharIndex() === 0;
|
|
75
|
+
}
|
|
76
|
+
openBrace() {
|
|
77
|
+
this.opened++;
|
|
78
|
+
}
|
|
79
|
+
closeBrace() {
|
|
80
|
+
this.opened--;
|
|
81
|
+
}
|
|
82
|
+
onNewLine() {
|
|
83
|
+
const newLine = this.text.replace(/[^\r\n]+/g, '');
|
|
84
|
+
const spaces = this.text.replace(/[\r\n]+/g, '');
|
|
85
|
+
const next = this.inputStream.LA(1);
|
|
86
|
+
const nextnext = this.inputStream.LA(2);
|
|
87
|
+
if (this.opened > 0 || (nextnext != -1 &&
|
|
88
|
+
(next === 13 || next === 10 || next === 35))) {
|
|
89
|
+
this.skip();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.emitToken(this.commonToken(CircuitScriptParser_js_1.CircuitScriptParser.NEWLINE, newLine));
|
|
93
|
+
const indent = this.getIndentationCount(spaces);
|
|
94
|
+
const previous = this.indents.length ? this.indents[this.indents.length - 1] : 0;
|
|
95
|
+
if (indent === previous) {
|
|
96
|
+
this.skip();
|
|
97
|
+
}
|
|
98
|
+
else if (indent > previous) {
|
|
99
|
+
this.indents.push(indent);
|
|
100
|
+
this.emitToken(this.commonToken(CircuitScriptParser_js_1.CircuitScriptParser.INDENT, spaces));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
while (this.indents.length && this.indents[this.indents.length - 1] > indent) {
|
|
104
|
+
this.emitToken(this.createDedent());
|
|
105
|
+
this.indents.pop();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
exports.MainLexer = MainLexer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.logs = [];
|
|
7
|
+
this.add((new Date()).toISOString());
|
|
8
|
+
this.add('starting logger...');
|
|
9
|
+
}
|
|
10
|
+
add(message) {
|
|
11
|
+
this.logs.push((new Date()).toISOString() + " | " + message);
|
|
12
|
+
}
|
|
13
|
+
dump() {
|
|
14
|
+
return this.logs.join('\n');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Logger = Logger;
|
package/dist/cjs/main.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const figlet_1 = __importDefault(require("figlet"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const sizing_js_1 = require("./sizing.js");
|
|
12
|
+
const helpers_js_1 = require("./helpers.js");
|
|
13
|
+
async function main() {
|
|
14
|
+
const fontsPath = (0, helpers_js_1.getFontsPath)();
|
|
15
|
+
const defaultLibsPath = (0, helpers_js_1.getDefaultLibsPath)();
|
|
16
|
+
const version = (0, helpers_js_1.getPackageVersion)();
|
|
17
|
+
commander_1.program
|
|
18
|
+
.description('generate graphical output from circuitscript files')
|
|
19
|
+
.version(version)
|
|
20
|
+
.option('-i, --input text <input text>', 'Input text directly')
|
|
21
|
+
.option('-f, --input-file <path>', 'Input file')
|
|
22
|
+
.option('-o, --output <path>', 'Output path')
|
|
23
|
+
.option('-c, --current-directory <path>', 'Set current directory')
|
|
24
|
+
.option('-k, --kicad-netlist <filename>', 'Create KiCad netlist')
|
|
25
|
+
.option('-w, --watch', 'Watch for file changes')
|
|
26
|
+
.option('-n, --dump-nets', 'Dump out net information')
|
|
27
|
+
.option('-d, --dump-data', 'Dump data during parsing')
|
|
28
|
+
.option('-s, --stats', 'Show stats during generation');
|
|
29
|
+
commander_1.program.addHelpText('before', figlet_1.default.textSync('circuitscript', {
|
|
30
|
+
font: 'Small Slant'
|
|
31
|
+
}));
|
|
32
|
+
if (process.argv.length < 3) {
|
|
33
|
+
commander_1.program.help();
|
|
34
|
+
}
|
|
35
|
+
commander_1.program.parse();
|
|
36
|
+
const options = commander_1.program.opts();
|
|
37
|
+
const watchFileChanges = options.watch;
|
|
38
|
+
const outputPath = options.output ?? null;
|
|
39
|
+
const dumpNets = options.dumpNets;
|
|
40
|
+
const dumpData = options.dumpData;
|
|
41
|
+
const kicadNetlist = options.kicadNetlist;
|
|
42
|
+
let currentDirectory = options.currentDirectory ?? null;
|
|
43
|
+
if (watchFileChanges) {
|
|
44
|
+
console.log('watching for file changes...');
|
|
45
|
+
}
|
|
46
|
+
await (0, sizing_js_1.prepareSVGEnvironment)(fontsPath);
|
|
47
|
+
let inputFilePath = null;
|
|
48
|
+
let scriptData;
|
|
49
|
+
if (options.input) {
|
|
50
|
+
scriptData = options.input;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
inputFilePath = options.inputFile;
|
|
54
|
+
scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
55
|
+
if (currentDirectory === null) {
|
|
56
|
+
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const scriptOptions = {
|
|
60
|
+
currentDirectory,
|
|
61
|
+
defaultLibsPath,
|
|
62
|
+
dumpNets,
|
|
63
|
+
dumpData,
|
|
64
|
+
kicadNetlistPath: kicadNetlist,
|
|
65
|
+
showStats: options.stats,
|
|
66
|
+
};
|
|
67
|
+
const output = (0, helpers_js_1.renderScript)(scriptData, outputPath, scriptOptions);
|
|
68
|
+
if (outputPath === null && output) {
|
|
69
|
+
console.log(output);
|
|
70
|
+
}
|
|
71
|
+
if (watchFileChanges) {
|
|
72
|
+
(0, fs_1.watch)(inputFilePath, event => {
|
|
73
|
+
if (event === 'change') {
|
|
74
|
+
const scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
75
|
+
(0, helpers_js_1.renderScript)(scriptData, outputPath, scriptOptions);
|
|
76
|
+
console.log('done');
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.default = main;
|
|
82
|
+
main();
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClassComponent = void 0;
|
|
4
|
+
const draw_symbols_js_1 = require("../draw_symbols.js");
|
|
5
|
+
const PinDefinition_js_1 = require("./PinDefinition.js");
|
|
6
|
+
const PinTypes_js_1 = require("./PinTypes.js");
|
|
7
|
+
class ClassComponent {
|
|
8
|
+
constructor(instanceName, numPins, className) {
|
|
9
|
+
this.parameters = new Map();
|
|
10
|
+
this.pins = new Map();
|
|
11
|
+
this.pinNets = new Map();
|
|
12
|
+
this.pinWires = new Map();
|
|
13
|
+
this._copyID = null;
|
|
14
|
+
this._copyFrom = null;
|
|
15
|
+
this.arrangeProps = null;
|
|
16
|
+
this.displayProp = null;
|
|
17
|
+
this.widthProp = null;
|
|
18
|
+
this.typeProp = null;
|
|
19
|
+
this.styles = {};
|
|
20
|
+
this.assignedRefDes = null;
|
|
21
|
+
this.instanceName = instanceName;
|
|
22
|
+
this.numPins = numPins;
|
|
23
|
+
this.className = className;
|
|
24
|
+
}
|
|
25
|
+
setupPins() {
|
|
26
|
+
for (let i = 1; i < this.numPins + 1; i++) {
|
|
27
|
+
const pinIndex = i;
|
|
28
|
+
this.pins.set(pinIndex, new PinDefinition_js_1.PinDefinition(pinIndex, PinDefinition_js_1.PinIdType.Int, pinIndex.toString(), PinTypes_js_1.PinTypes.Any));
|
|
29
|
+
}
|
|
30
|
+
this.refreshPinsCache();
|
|
31
|
+
}
|
|
32
|
+
getDefaultPin() {
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
hasPin(pinId) {
|
|
36
|
+
if (typeof pinId === 'number') {
|
|
37
|
+
return this.pins.has(pinId);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
for (const [, pinDef] of this.pins) {
|
|
41
|
+
if (pinDef.name === pinId ||
|
|
42
|
+
pinDef.altNames.indexOf(pinId) !== -1) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
getPin(pinId) {
|
|
50
|
+
if (typeof pinId === 'number') {
|
|
51
|
+
return pinId;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
for (const [pin, pinDef] of this.pins) {
|
|
55
|
+
if (pinDef.name === pinId ||
|
|
56
|
+
pinDef.altNames.indexOf(pinId) !== -1) {
|
|
57
|
+
return pin;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getNextPinAfter(pinIndex) {
|
|
64
|
+
if (pinIndex + 1 <= this.numPins) {
|
|
65
|
+
return pinIndex + 1;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
setParam(key, value) {
|
|
72
|
+
this.parameters.set(key, value);
|
|
73
|
+
this.refreshParamCache();
|
|
74
|
+
}
|
|
75
|
+
refreshParamCache() {
|
|
76
|
+
this._cachedParams =
|
|
77
|
+
JSON.stringify(Object.fromEntries(this.parameters));
|
|
78
|
+
}
|
|
79
|
+
refreshPinsCache() {
|
|
80
|
+
this._cachedPins = JSON.stringify(Object.fromEntries(this.pins));
|
|
81
|
+
}
|
|
82
|
+
refreshCache() {
|
|
83
|
+
this.refreshParamCache();
|
|
84
|
+
this.refreshPinsCache();
|
|
85
|
+
}
|
|
86
|
+
getParam(key) {
|
|
87
|
+
if (this.parameters.has(key)) {
|
|
88
|
+
return this.parameters.get(key);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw 'Invalid parameter key';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
toString() {
|
|
95
|
+
return this.instanceName;
|
|
96
|
+
}
|
|
97
|
+
static simple(instanceName, numPins, className) {
|
|
98
|
+
const component = new ClassComponent(instanceName, numPins, className);
|
|
99
|
+
component.setupPins();
|
|
100
|
+
return component;
|
|
101
|
+
}
|
|
102
|
+
isEqual(other) {
|
|
103
|
+
return this.instanceName === other.instanceName
|
|
104
|
+
&& this.numPins === other.numPins
|
|
105
|
+
&& this.className === other.className
|
|
106
|
+
&& this._copyID === other._copyID
|
|
107
|
+
&& this.arrangeProps === other.arrangeProps
|
|
108
|
+
&& this.displayProp === other.displayProp
|
|
109
|
+
&& this.widthProp === other.widthProp
|
|
110
|
+
&& this.typeProp === other.typeProp
|
|
111
|
+
&& this._cachedPins === other._cachedPins
|
|
112
|
+
&& this._cachedParams === other._cachedParams;
|
|
113
|
+
}
|
|
114
|
+
clone() {
|
|
115
|
+
const component = new ClassComponent(this.instanceName, this.numPins, this.className);
|
|
116
|
+
component._copyID = this._copyID;
|
|
117
|
+
component.arrangeProps = this.arrangeProps;
|
|
118
|
+
component.widthProp = this.widthProp;
|
|
119
|
+
component.typeProp = this.typeProp;
|
|
120
|
+
if (this.displayProp) {
|
|
121
|
+
if (typeof this.displayProp === "string") {
|
|
122
|
+
component.displayProp = this.displayProp;
|
|
123
|
+
}
|
|
124
|
+
else if (this.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
|
|
125
|
+
component.displayProp =
|
|
126
|
+
this.displayProp.clone();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const [key, value] of this.parameters) {
|
|
130
|
+
if (key === 'flipX' || key === 'flipY' || key === 'angle') {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
component.parameters.set(key, value);
|
|
134
|
+
}
|
|
135
|
+
for (const [key, value] of this.pins) {
|
|
136
|
+
component.pins.set(key, value);
|
|
137
|
+
}
|
|
138
|
+
for (const key in this.styles) {
|
|
139
|
+
component.styles[key] = this.styles[key];
|
|
140
|
+
}
|
|
141
|
+
component.refreshCache();
|
|
142
|
+
return component;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ClassComponent = ClassComponent;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActiveObject = exports.FrameAction = exports.SequenceAction = exports.ExecutionScope = void 0;
|
|
4
|
+
class ExecutionScope {
|
|
5
|
+
constructor(scopeId) {
|
|
6
|
+
this.nets = [];
|
|
7
|
+
this.instances = new Map();
|
|
8
|
+
this.functions = new Map();
|
|
9
|
+
this.variables = new Map();
|
|
10
|
+
this.symbols = new Map();
|
|
11
|
+
this.blockStack = new Map();
|
|
12
|
+
this.wires = [];
|
|
13
|
+
this.frames = [];
|
|
14
|
+
this.indentLevel = 0;
|
|
15
|
+
this.netCounter = 1;
|
|
16
|
+
this.unnamedCounter = 1;
|
|
17
|
+
this.currentComponent = null;
|
|
18
|
+
this.currentPin = null;
|
|
19
|
+
this.currentWireId = -1;
|
|
20
|
+
this.currentFrameId = -1;
|
|
21
|
+
this.netGnd = null;
|
|
22
|
+
this.componentGnd = null;
|
|
23
|
+
this.componentRoot = null;
|
|
24
|
+
this.copyIDs = new Map();
|
|
25
|
+
this.sequence = [];
|
|
26
|
+
this.scopeId = scopeId;
|
|
27
|
+
}
|
|
28
|
+
static create() {
|
|
29
|
+
const scope = new ExecutionScope(ExecutionScope.scopeId);
|
|
30
|
+
ExecutionScope.scopeId += 1;
|
|
31
|
+
return scope;
|
|
32
|
+
}
|
|
33
|
+
findNet(component, pin) {
|
|
34
|
+
return this.nets.find(([tmpComponent, tmpPin]) => {
|
|
35
|
+
return tmpComponent.isEqual(component) && tmpPin === pin;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
getNetWithName(name) {
|
|
39
|
+
const found = this.nets.find(([, , net]) => {
|
|
40
|
+
return net.name === name;
|
|
41
|
+
});
|
|
42
|
+
return found ? found[2] : null;
|
|
43
|
+
}
|
|
44
|
+
hasNet(component, pin) {
|
|
45
|
+
return this.findNet(component, pin) !== undefined;
|
|
46
|
+
}
|
|
47
|
+
getNet(component, pin) {
|
|
48
|
+
const result = this.findNet(component, pin);
|
|
49
|
+
if (result) {
|
|
50
|
+
return result[2];
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
setNet(component, pin, net) {
|
|
55
|
+
const pair = this.findNet(component, pin);
|
|
56
|
+
const result = this.nets.indexOf(pair);
|
|
57
|
+
if (result === -1) {
|
|
58
|
+
this.nets.push([component, pin, net]);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.nets[result][2] = net;
|
|
62
|
+
}
|
|
63
|
+
component.pinNets.set(pin, net);
|
|
64
|
+
}
|
|
65
|
+
removeNet(component, pin) {
|
|
66
|
+
const pair = this.findNet(component, pin);
|
|
67
|
+
const result = this.nets.indexOf(pair);
|
|
68
|
+
if (result !== -1) {
|
|
69
|
+
this.nets.splice(result, 1);
|
|
70
|
+
}
|
|
71
|
+
component.pinNets.delete(pin);
|
|
72
|
+
}
|
|
73
|
+
getNets() {
|
|
74
|
+
return this.nets;
|
|
75
|
+
}
|
|
76
|
+
dumpNets() {
|
|
77
|
+
const sortedNet = [...this.nets].sort((a, b) => {
|
|
78
|
+
const netA = a[2];
|
|
79
|
+
const netB = b[2];
|
|
80
|
+
const netAId = netA.namespace + netA.name;
|
|
81
|
+
const netBId = netB.namespace + b[2].name;
|
|
82
|
+
if (netAId > netBId) {
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
else if (netAId < netBId) {
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return sortedNet.map(([component, pin, net]) => {
|
|
93
|
+
return [net.namespace + net.name, component.instanceName, pin];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
printNets() {
|
|
97
|
+
this.dumpNets().forEach(item => {
|
|
98
|
+
const [netName, instanceName, pin] = item;
|
|
99
|
+
console.log(netName.padEnd(10), '=>', instanceName, pin);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
setActive(type, item) {
|
|
103
|
+
this.clearActive();
|
|
104
|
+
if (type === ActiveObject.Wire) {
|
|
105
|
+
this.currentWireId = item;
|
|
106
|
+
}
|
|
107
|
+
else if (type === ActiveObject.Frame) {
|
|
108
|
+
this.currentFrameId = item;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
clearActive() {
|
|
112
|
+
this.currentWireId = -1;
|
|
113
|
+
this.currentFrameId = -1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.ExecutionScope = ExecutionScope;
|
|
117
|
+
ExecutionScope.scopeId = 0;
|
|
118
|
+
var SequenceAction;
|
|
119
|
+
(function (SequenceAction) {
|
|
120
|
+
SequenceAction["To"] = "to";
|
|
121
|
+
SequenceAction["At"] = "at";
|
|
122
|
+
SequenceAction["Wire"] = "wire";
|
|
123
|
+
SequenceAction["WireJump"] = "wire-jump";
|
|
124
|
+
SequenceAction["Frame"] = "frame";
|
|
125
|
+
})(SequenceAction || (exports.SequenceAction = SequenceAction = {}));
|
|
126
|
+
var FrameAction;
|
|
127
|
+
(function (FrameAction) {
|
|
128
|
+
FrameAction["Enter"] = "enter";
|
|
129
|
+
FrameAction["Exit"] = "exit";
|
|
130
|
+
})(FrameAction || (exports.FrameAction = FrameAction = {}));
|
|
131
|
+
var ActiveObject;
|
|
132
|
+
(function (ActiveObject) {
|
|
133
|
+
ActiveObject["Frame"] = "frame";
|
|
134
|
+
ActiveObject["Wire"] = "wire";
|
|
135
|
+
})(ActiveObject || (exports.ActiveObject = ActiveObject = {}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FramePlotDirection = exports.FrameParamKeys = exports.Frame = void 0;
|
|
4
|
+
class Frame {
|
|
5
|
+
constructor(frameId) {
|
|
6
|
+
this.parameters = new Map();
|
|
7
|
+
this.frameId = frameId;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.Frame = Frame;
|
|
11
|
+
var FrameParamKeys;
|
|
12
|
+
(function (FrameParamKeys) {
|
|
13
|
+
FrameParamKeys["Title"] = "title";
|
|
14
|
+
FrameParamKeys["Direction"] = "direction";
|
|
15
|
+
FrameParamKeys["Padding"] = "padding";
|
|
16
|
+
FrameParamKeys["Border"] = "border";
|
|
17
|
+
})(FrameParamKeys || (exports.FrameParamKeys = FrameParamKeys = {}));
|
|
18
|
+
var FramePlotDirection;
|
|
19
|
+
(function (FramePlotDirection) {
|
|
20
|
+
FramePlotDirection["Row"] = "row";
|
|
21
|
+
FramePlotDirection["Column"] = "column";
|
|
22
|
+
})(FramePlotDirection || (exports.FramePlotDirection = FramePlotDirection = {}));
|
|
@@ -1,43 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Defines where the net was created. This is important for determining
|
|
9
|
-
// the 'location' of global nets.
|
|
10
|
-
namespace: string;
|
|
11
|
-
|
|
12
|
-
priority: number;
|
|
13
|
-
type: any;
|
|
14
|
-
|
|
15
|
-
constructor(namespace: string, name: string, priority = 0, type: any = null) {
|
|
16
|
-
if (namespace.indexOf(' ') !== -1){
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Net = void 0;
|
|
4
|
+
class Net {
|
|
5
|
+
constructor(namespace, name, priority = 0, type = null) {
|
|
6
|
+
if (namespace.indexOf(' ') !== -1) {
|
|
17
7
|
throw "Invalid net namespace provided";
|
|
18
8
|
}
|
|
19
|
-
|
|
20
9
|
if (name.indexOf(' ') !== -1) {
|
|
21
10
|
throw "Invalid net name provided!";
|
|
22
11
|
}
|
|
23
|
-
|
|
24
12
|
this.namespace = namespace;
|
|
25
13
|
this.name = name;
|
|
26
|
-
|
|
27
14
|
this.priority = priority;
|
|
28
15
|
this.type = type;
|
|
29
|
-
|
|
30
16
|
this.baseName = name;
|
|
31
17
|
}
|
|
32
|
-
|
|
33
|
-
toString(): string {
|
|
18
|
+
toString() {
|
|
34
19
|
return this.name;
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
static isSame(netA: Net, netB: Net): boolean {
|
|
21
|
+
static isSame(netA, netB) {
|
|
38
22
|
return netA.name === netB.name &&
|
|
39
23
|
netA.baseName === netB.baseName &&
|
|
40
24
|
netA.priority === netB.priority &&
|
|
41
25
|
netA.type === netB.type;
|
|
42
26
|
}
|
|
43
27
|
}
|
|
28
|
+
exports.Net = Net;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PinBlankValue = exports.PercentageValue = exports.NumericValue = exports.ParamDefinition = void 0;
|
|
4
|
+
class ParamDefinition {
|
|
5
|
+
constructor(paramName, paramValue) {
|
|
6
|
+
this.paramName = paramName;
|
|
7
|
+
this.paramValue = paramValue;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ParamDefinition = ParamDefinition;
|
|
11
|
+
class NumericValue {
|
|
12
|
+
constructor(value) {
|
|
13
|
+
this.value = value;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return 'numeric:' + this.value;
|
|
17
|
+
}
|
|
18
|
+
toDisplayString() {
|
|
19
|
+
if (typeof this.value === 'number') {
|
|
20
|
+
return this.value.toString();
|
|
21
|
+
}
|
|
22
|
+
else if (typeof this.value === 'string') {
|
|
23
|
+
return this.value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.NumericValue = NumericValue;
|
|
28
|
+
class PercentageValue {
|
|
29
|
+
constructor(value) {
|
|
30
|
+
this.value = value;
|
|
31
|
+
}
|
|
32
|
+
toString() {
|
|
33
|
+
return this.value.toString();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PercentageValue = PercentageValue;
|
|
37
|
+
class PinBlankValue {
|
|
38
|
+
constructor(value) {
|
|
39
|
+
this.blank = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.PinBlankValue = PinBlankValue;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PinReference = exports.PortSide = exports.PinIdType = exports.PinDefinition = void 0;
|
|
4
|
+
const PinTypes_js_1 = require("./PinTypes.js");
|
|
5
|
+
class PinDefinition {
|
|
6
|
+
constructor(id, idType, name, pinType = PinTypes_js_1.PinTypes.Any, altNames = []) {
|
|
7
|
+
this.side = PortSide.EAST;
|
|
8
|
+
this.position = -1;
|
|
9
|
+
this.id = id;
|
|
10
|
+
this.idType = idType;
|
|
11
|
+
this.pinType = pinType;
|
|
12
|
+
this.name = name;
|
|
13
|
+
this.altNames = altNames;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.PinDefinition = PinDefinition;
|
|
17
|
+
var PinIdType;
|
|
18
|
+
(function (PinIdType) {
|
|
19
|
+
PinIdType["Int"] = "int";
|
|
20
|
+
PinIdType["Str"] = "str";
|
|
21
|
+
})(PinIdType || (exports.PinIdType = PinIdType = {}));
|
|
22
|
+
var PortSide;
|
|
23
|
+
(function (PortSide) {
|
|
24
|
+
PortSide["WEST"] = "WEST";
|
|
25
|
+
PortSide["EAST"] = "EAST";
|
|
26
|
+
PortSide["SOUTH"] = "SOUTH";
|
|
27
|
+
PortSide["NORTH"] = "NORTH";
|
|
28
|
+
})(PortSide || (exports.PortSide = PortSide = {}));
|
|
29
|
+
class PinReference {
|
|
30
|
+
}
|
|
31
|
+
exports.PinReference = PinReference;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PinTypes = void 0;
|
|
4
|
+
var PinTypes;
|
|
5
|
+
(function (PinTypes) {
|
|
6
|
+
PinTypes["Any"] = "any";
|
|
7
|
+
PinTypes["Input"] = "input";
|
|
8
|
+
PinTypes["Output"] = "output";
|
|
9
|
+
PinTypes["IO"] = "io";
|
|
10
|
+
PinTypes["Power"] = "power";
|
|
11
|
+
})(PinTypes || (exports.PinTypes = PinTypes = {}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
4
|
+
class UndeclaredReference {
|
|
5
|
+
constructor(reference) {
|
|
6
|
+
this.reference = reference;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.UndeclaredReference = UndeclaredReference;
|
|
10
|
+
var ParseSymbolType;
|
|
11
|
+
(function (ParseSymbolType) {
|
|
12
|
+
ParseSymbolType["Variable"] = "variable";
|
|
13
|
+
ParseSymbolType["Function"] = "function";
|
|
14
|
+
ParseSymbolType["Undefined"] = "undefined";
|
|
15
|
+
})(ParseSymbolType || (exports.ParseSymbolType = ParseSymbolType = {}));
|