circuitscript 0.1.29 → 0.1.32
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 +185 -22
- package/dist/cjs/RefdesAnnotationVisitor.js +27 -10
- package/dist/cjs/antlr/CircuitScriptLexer.js +241 -236
- package/dist/cjs/antlr/CircuitScriptParser.js +1197 -901
- package/dist/cjs/builtinMethods.js +6 -2
- package/dist/cjs/draw_symbols.js +38 -34
- package/dist/cjs/environment.js +28 -4
- package/dist/cjs/execute.js +195 -125
- package/dist/cjs/globals.js +6 -1
- package/dist/cjs/graph.js +14 -12
- package/dist/cjs/helpers.js +90 -17
- package/dist/cjs/layout.js +50 -25
- package/dist/cjs/main.js +16 -14
- package/dist/cjs/objects/ClassComponent.js +199 -30
- package/dist/cjs/objects/ExecutionScope.js +9 -0
- package/dist/cjs/objects/types.js +25 -2
- package/dist/cjs/parser.js +6 -2
- package/dist/cjs/regenerate-tests.js +3 -3
- package/dist/cjs/render.js +5 -3
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +9 -8
- package/dist/cjs/rules-check/rules.js +7 -2
- package/dist/cjs/rules-check/unconnected-pins.js +10 -8
- package/dist/cjs/utils.js +2 -1
- package/dist/cjs/validate/SymbolTable.js +7 -1
- package/dist/cjs/validate/SymbolValidatorVisitor.js +54 -17
- package/dist/cjs/visitor.js +299 -238
- package/dist/esm/BaseVisitor.js +187 -24
- package/dist/esm/RefdesAnnotationVisitor.js +27 -10
- package/dist/esm/antlr/CircuitScriptLexer.js +241 -236
- package/dist/esm/antlr/CircuitScriptParser.js +1196 -899
- package/dist/esm/antlr/CircuitScriptVisitor.js +4 -1
- package/dist/esm/builtinMethods.js +7 -3
- package/dist/esm/draw_symbols.js +38 -34
- package/dist/esm/environment.js +25 -1
- package/dist/esm/execute.js +197 -127
- package/dist/esm/globals.js +4 -0
- package/dist/esm/graph.js +14 -12
- package/dist/esm/helpers.js +91 -18
- package/dist/esm/layout.js +51 -26
- package/dist/esm/main.js +16 -14
- package/dist/esm/objects/ClassComponent.js +201 -30
- package/dist/esm/objects/ExecutionScope.js +9 -0
- package/dist/esm/objects/types.js +33 -1
- package/dist/esm/parser.js +6 -2
- package/dist/esm/regenerate-tests.js +3 -3
- package/dist/esm/render.js +5 -3
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +9 -8
- package/dist/esm/rules-check/rules.js +7 -2
- package/dist/esm/rules-check/unconnected-pins.js +10 -8
- package/dist/esm/utils.js +2 -1
- package/dist/esm/validate/SymbolTable.js +5 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +53 -16
- package/dist/esm/visitor.js +201 -137
- package/dist/types/BaseVisitor.d.ts +27 -10
- package/dist/types/RefdesAnnotationVisitor.d.ts +2 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +43 -42
- package/dist/types/antlr/CircuitScriptParser.d.ts +102 -58
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +8 -2
- package/dist/types/environment.d.ts +8 -1
- package/dist/types/execute.d.ts +6 -3
- package/dist/types/globals.d.ts +4 -0
- package/dist/types/graph.d.ts +2 -2
- package/dist/types/helpers.d.ts +2 -1
- package/dist/types/layout.d.ts +5 -4
- package/dist/types/objects/ClassComponent.d.ts +34 -9
- package/dist/types/objects/ExecutionScope.d.ts +3 -1
- package/dist/types/objects/types.d.ts +40 -3
- package/dist/types/validate/SymbolTable.d.ts +1 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +6 -6
- package/dist/types/visitor.d.ts +10 -2
- package/package.json +4 -1
|
@@ -8,6 +8,7 @@ const big_js_1 = __importDefault(require("big.js"));
|
|
|
8
8
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
9
9
|
const types_js_1 = require("./objects/types.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
11
|
+
const globals_js_1 = require("./globals.js");
|
|
11
12
|
const builtInMethods = [
|
|
12
13
|
['enumerate', enumerate],
|
|
13
14
|
['toMils', toMils],
|
|
@@ -20,7 +21,7 @@ const builtInMethods = [
|
|
|
20
21
|
];
|
|
21
22
|
exports.buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
22
23
|
function linkBuiltInMethods(context, visitor) {
|
|
23
|
-
context.createFunction('print', (params) => {
|
|
24
|
+
context.createFunction(globals_js_1.BaseNamespace, 'print', (params) => {
|
|
24
25
|
const args = getPositionParams(params);
|
|
25
26
|
const items = args.map(item => {
|
|
26
27
|
return toString((0, utils_js_1.unwrapValue)(item));
|
|
@@ -34,7 +35,7 @@ function linkBuiltInMethods(context, visitor) {
|
|
|
34
35
|
});
|
|
35
36
|
builtInMethods.forEach(([functionName, functionImpl]) => {
|
|
36
37
|
if (functionImpl !== null) {
|
|
37
|
-
context.createFunction(functionName, params => {
|
|
38
|
+
context.createFunction(globals_js_1.BaseNamespace, functionName, params => {
|
|
38
39
|
const args = getPositionParams(params);
|
|
39
40
|
const functionReturn = functionImpl(...args);
|
|
40
41
|
return [visitor, functionReturn];
|
|
@@ -155,6 +156,9 @@ function toString(obj) {
|
|
|
155
156
|
else if (obj instanceof types_js_1.CFunctionEntry) {
|
|
156
157
|
return obj.toString();
|
|
157
158
|
}
|
|
159
|
+
else if (obj instanceof types_js_1.ImportedModule) {
|
|
160
|
+
return `[module: ${obj.moduleName}]`;
|
|
161
|
+
}
|
|
158
162
|
else {
|
|
159
163
|
if (obj === undefined) {
|
|
160
164
|
return 'undefined';
|
package/dist/cjs/draw_symbols.js
CHANGED
|
@@ -135,7 +135,7 @@ class SymbolGraphic {
|
|
|
135
135
|
}
|
|
136
136
|
drawLabels(group) {
|
|
137
137
|
const labels = this.drawing.getLabels();
|
|
138
|
-
|
|
138
|
+
for (const label of labels) {
|
|
139
139
|
const tmpLabel = label;
|
|
140
140
|
const { fontSize = (0, ParamDefinition_js_1.numeric)(50), anchor = geometry_js_1.HorizontalAlign.Left, vanchor = geometry_js_1.VerticalAlign.Bottom, fontWeight = 'regular', angle: tmpLabelAngle = (0, ParamDefinition_js_1.numeric)(0), textColor = "#333", } = tmpLabel.style ?? {};
|
|
141
141
|
const labelAngle = tmpLabelAngle.toNumber();
|
|
@@ -148,31 +148,35 @@ class SymbolGraphic {
|
|
|
148
148
|
useAnchor = this.flipTextAnchor(anchor);
|
|
149
149
|
useDominantBaseline = this.flipDominantBaseline(vanchor);
|
|
150
150
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
break;
|
|
156
|
-
case geometry_js_1.HorizontalAlign.Middle:
|
|
157
|
-
anchorStyle = geometry_js_1.HorizontalAlignProp.Middle;
|
|
158
|
-
break;
|
|
159
|
-
case geometry_js_1.HorizontalAlign.Right:
|
|
160
|
-
anchorStyle = (this.flipX === 0)
|
|
161
|
-
? geometry_js_1.HorizontalAlignProp.End : geometry_js_1.HorizontalAlignProp.Start;
|
|
162
|
-
break;
|
|
151
|
+
const isHorizontalLabel = labelAngle === 0 || labelAngle === 180;
|
|
152
|
+
const isVerticalLabel = labelAngle === 90 || labelAngle === -90;
|
|
153
|
+
if (useAnchor === geometry_js_1.HorizontalAlign.Middle) {
|
|
154
|
+
anchorStyle = geometry_js_1.HorizontalAlignProp.Middle;
|
|
163
155
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
156
|
+
else if (useAnchor === geometry_js_1.HorizontalAlign.Left) {
|
|
157
|
+
anchorStyle = geometry_js_1.HorizontalAlignProp.Start;
|
|
158
|
+
}
|
|
159
|
+
else if (useAnchor === geometry_js_1.HorizontalAlign.Right) {
|
|
160
|
+
anchorStyle = geometry_js_1.HorizontalAlignProp.End;
|
|
161
|
+
}
|
|
162
|
+
if (useDominantBaseline === geometry_js_1.VerticalAlign.Middle) {
|
|
163
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
|
|
164
|
+
}
|
|
165
|
+
else if (useDominantBaseline === geometry_js_1.VerticalAlign.Top) {
|
|
166
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
|
|
167
|
+
}
|
|
168
|
+
else if (useDominantBaseline === geometry_js_1.VerticalAlign.Bottom) {
|
|
169
|
+
dominantBaseline = geometry_js_1.VerticalAlignProp.TextTop;
|
|
170
|
+
}
|
|
171
|
+
if (anchorStyle !== geometry_js_1.HorizontalAlignProp.Middle &&
|
|
172
|
+
((isHorizontalLabel && this.flipX === 1) || (isVerticalLabel && this.flipY === 1))) {
|
|
173
|
+
anchorStyle = (anchorStyle === geometry_js_1.HorizontalAlignProp.Start)
|
|
174
|
+
? geometry_js_1.HorizontalAlignProp.End : geometry_js_1.HorizontalAlignProp.Start;
|
|
175
|
+
}
|
|
176
|
+
if (dominantBaseline !== geometry_js_1.VerticalAlignProp.Central &&
|
|
177
|
+
((isHorizontalLabel && this.flipY === 1) || (isVerticalLabel && this.flipX === 1))) {
|
|
178
|
+
dominantBaseline = (dominantBaseline === geometry_js_1.VerticalAlignProp.Hanging)
|
|
179
|
+
? geometry_js_1.VerticalAlignProp.TextTop : geometry_js_1.VerticalAlignProp.Hanging;
|
|
176
180
|
}
|
|
177
181
|
const position = tmpLabel.getLabelPosition();
|
|
178
182
|
if (this.flipX !== 0) {
|
|
@@ -316,7 +320,7 @@ class SymbolGraphic {
|
|
|
316
320
|
.translate(-originSize / 2, -originSize / 2)
|
|
317
321
|
.fill('green');
|
|
318
322
|
}
|
|
319
|
-
}
|
|
323
|
+
}
|
|
320
324
|
}
|
|
321
325
|
flipTextAnchor(value) {
|
|
322
326
|
if (value === geometry_js_1.HorizontalAlign.Left) {
|
|
@@ -712,7 +716,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
712
716
|
const pinStartY = bodyHeightMM.neg().half();
|
|
713
717
|
const pinStartX = bodyWidthMM.neg().half();
|
|
714
718
|
const tmpPinSpacing = this.pinSpacing.toNumber();
|
|
715
|
-
|
|
719
|
+
for (const pin of leftPins) {
|
|
716
720
|
const position = pin.position;
|
|
717
721
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
718
722
|
drawing.addPinMM(pin.pinId, leftPinStart.sub(this.pinLength), pinY, leftPinStart, pinY, defaultLineColor);
|
|
@@ -728,8 +732,8 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
728
732
|
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
729
733
|
textColor: defaultLineColor
|
|
730
734
|
});
|
|
731
|
-
}
|
|
732
|
-
|
|
735
|
+
}
|
|
736
|
+
for (const pin of rightPins) {
|
|
733
737
|
const position = pin.position;
|
|
734
738
|
const pinY = pinStartY.add((position + 1) * tmpPinSpacing);
|
|
735
739
|
drawing.addPinMM(pin.pinId, rightPinStart.add(this.pinLength), pinY, rightPinStart, pinY, defaultLineColor);
|
|
@@ -745,8 +749,8 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
745
749
|
vanchor: geometry_js_1.VerticalAlign.Bottom,
|
|
746
750
|
textColor: defaultLineColor
|
|
747
751
|
});
|
|
748
|
-
}
|
|
749
|
-
|
|
752
|
+
}
|
|
753
|
+
for (const pin of topPins) {
|
|
750
754
|
const position = pin.position;
|
|
751
755
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
752
756
|
drawing.addPinMM(pin.pinId, pinX, topPinStart.sub(this.pinLength), pinX, topPinStart, defaultLineColor);
|
|
@@ -764,8 +768,8 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
764
768
|
textColor: defaultLineColor,
|
|
765
769
|
angle: (0, ParamDefinition_js_1.numeric)(-90),
|
|
766
770
|
});
|
|
767
|
-
}
|
|
768
|
-
|
|
771
|
+
}
|
|
772
|
+
for (const pin of bottomPins) {
|
|
769
773
|
const position = pin.position;
|
|
770
774
|
const pinX = pinStartX.add((position + 1) * tmpPinSpacing);
|
|
771
775
|
drawing.addPinMM(pin.pinId, pinX, bottomPinStart.add(this.pinLength), pinX, bottomPinStart, defaultLineColor);
|
|
@@ -783,7 +787,7 @@ class SymbolCustom extends SymbolGraphic {
|
|
|
783
787
|
textColor: defaultLineColor,
|
|
784
788
|
angle: (0, ParamDefinition_js_1.numeric)(-90)
|
|
785
789
|
});
|
|
786
|
-
}
|
|
790
|
+
}
|
|
787
791
|
const instanceName = drawing.variables.get('refdes');
|
|
788
792
|
instanceName && drawing.addLabel(bodyWidthMM.neg().half(), bodyHeightMM.neg().half().sub((0, helpers_js_1.milsToMM)(20)), instanceName, {
|
|
789
793
|
fontSize: (0, ParamDefinition_js_1.numeric)(globals_js_1.CustomSymbolRefDesSize),
|
package/dist/cjs/environment.js
CHANGED
|
@@ -5,8 +5,10 @@ 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 =
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const fs_2 = __importDefault(require("fs"));
|
|
9
10
|
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
10
12
|
const globals_js_1 = require("./globals.js");
|
|
11
13
|
const utils_js_1 = require("./utils.js");
|
|
12
14
|
class NodeScriptEnvironment {
|
|
@@ -38,7 +40,7 @@ class NodeScriptEnvironment {
|
|
|
38
40
|
}
|
|
39
41
|
try {
|
|
40
42
|
const packageJsonPath = path_1.default.join(this.getToolsPath(), '../', 'package.json');
|
|
41
|
-
const packageJsonContent =
|
|
43
|
+
const packageJsonContent = fs_2.default.readFileSync(packageJsonPath, 'utf-8');
|
|
42
44
|
const packageJson = JSON.parse(packageJsonContent);
|
|
43
45
|
this.cachedVersion = packageJson.version || globals_js_1.TOOL_VERSION;
|
|
44
46
|
return this.cachedVersion;
|
|
@@ -117,7 +119,11 @@ class NodeScriptEnvironment {
|
|
|
117
119
|
return this.prepareSVGEnvironmentInternal(this.getFontsPath());
|
|
118
120
|
}
|
|
119
121
|
async readFile(path, options) {
|
|
120
|
-
|
|
122
|
+
options = options ?? { encoding: 'utf8' };
|
|
123
|
+
return fs_2.default.promises.readFile(path, options);
|
|
124
|
+
}
|
|
125
|
+
writeFileSync(path, data) {
|
|
126
|
+
return (0, fs_1.writeFileSync)(path, data);
|
|
121
127
|
}
|
|
122
128
|
getAbsolutePath(filePath) {
|
|
123
129
|
return path_1.default.resolve(filePath);
|
|
@@ -137,13 +143,31 @@ class NodeScriptEnvironment {
|
|
|
137
143
|
}
|
|
138
144
|
async exists(path) {
|
|
139
145
|
try {
|
|
140
|
-
|
|
146
|
+
await fs_2.default.promises.access(path, fs_2.default.constants.F_OK);
|
|
141
147
|
return true;
|
|
142
148
|
}
|
|
143
149
|
catch (err) {
|
|
144
150
|
return false;
|
|
145
151
|
}
|
|
146
152
|
}
|
|
153
|
+
hashStringSHA256(value) {
|
|
154
|
+
return crypto_js_1.default.SHA256(value).toString();
|
|
155
|
+
}
|
|
156
|
+
dirname(filePath) {
|
|
157
|
+
return path_1.default.dirname(filePath);
|
|
158
|
+
}
|
|
159
|
+
extname(filePath) {
|
|
160
|
+
return path_1.default.extname(filePath);
|
|
161
|
+
}
|
|
162
|
+
basename(filePath, ext) {
|
|
163
|
+
return path_1.default.basename(filePath, ext);
|
|
164
|
+
}
|
|
165
|
+
join(...paths) {
|
|
166
|
+
return path_1.default.join(...paths);
|
|
167
|
+
}
|
|
168
|
+
relative(from, to) {
|
|
169
|
+
return path_1.default.relative(from, to);
|
|
170
|
+
}
|
|
147
171
|
}
|
|
148
172
|
exports.NodeScriptEnvironment = NodeScriptEnvironment;
|
|
149
173
|
NodeScriptEnvironment._instance = null;
|