circuitscript 0.5.4 → 0.5.5
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 +11 -10
- package/dist/cjs/builtinMethods.js +6 -5
- package/dist/cjs/environment/environment.js +2 -2
- package/dist/cjs/errors.js +140 -0
- package/dist/cjs/execute.js +12 -5
- package/dist/cjs/main.js +3 -2
- package/dist/cjs/objects/ClassComponent.js +4 -4
- package/dist/cjs/objects/ExecutionScope.js +2 -2
- package/dist/cjs/objects/NumericValue.js +15 -0
- package/dist/cjs/objects/PinDefinition.js +2 -2
- package/dist/cjs/objects/types.js +2 -2
- package/dist/cjs/parser.js +3 -2
- package/dist/cjs/pipeline.js +21 -14
- package/dist/cjs/regenerate-tests.js +6 -6
- package/dist/cjs/render/draw_symbols.js +17 -17
- package/dist/cjs/render/geometry.js +6 -6
- package/dist/cjs/render/layout.js +325 -253
- package/dist/cjs/render/render.js +21 -18
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +13 -110
- package/dist/cjs/validate/validateScript.js +2 -2
- package/dist/cjs/visitor.js +14 -12
- package/dist/esm/BaseVisitor.js +2 -1
- package/dist/esm/builtinMethods.js +6 -5
- package/dist/esm/environment/environment.js +1 -1
- package/dist/esm/errors.js +119 -0
- package/dist/esm/execute.js +10 -3
- package/dist/esm/main.js +3 -2
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +1 -1
- package/dist/esm/objects/NumericValue.js +15 -0
- package/dist/esm/objects/PinDefinition.js +1 -1
- package/dist/esm/objects/types.js +1 -1
- package/dist/esm/parser.js +2 -1
- package/dist/esm/pipeline.js +10 -3
- package/dist/esm/regenerate-tests.js +6 -6
- package/dist/esm/render/draw_symbols.js +15 -15
- package/dist/esm/render/geometry.js +6 -6
- package/dist/esm/render/layout.js +325 -253
- package/dist/esm/render/render.js +22 -19
- package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +10 -95
- package/dist/esm/validate/validateScript.js +1 -1
- package/dist/esm/visitor.js +4 -2
- package/dist/libs/std.cst +31 -31
- package/dist/types/BaseVisitor.d.ts +3 -1
- package/dist/types/errors.d.ts +37 -0
- package/dist/types/execute.d.ts +1 -1
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/objects/NumericValue.d.ts +5 -1
- package/dist/types/render/geometry.d.ts +4 -4
- package/dist/types/render/layout.d.ts +7 -1
- package/dist/types/utils.d.ts +2 -27
- package/dist/types/visitor.d.ts +1 -1
- package/libs/std.cst +31 -31
- package/package.json +1 -1
|
@@ -27,6 +27,9 @@ export class NumericValue {
|
|
|
27
27
|
toString() {
|
|
28
28
|
return 'numeric:' + this.value;
|
|
29
29
|
}
|
|
30
|
+
copy() {
|
|
31
|
+
return this.add(0);
|
|
32
|
+
}
|
|
30
33
|
toDisplayString() {
|
|
31
34
|
if (typeof this.value === 'number') {
|
|
32
35
|
return this.value.toString();
|
|
@@ -81,6 +84,15 @@ export class NumericValue {
|
|
|
81
84
|
eq(value) {
|
|
82
85
|
return this.toBigNumber().eq(value.toBigNumber());
|
|
83
86
|
}
|
|
87
|
+
floor() {
|
|
88
|
+
return numeric(Math.floor(this.toNumber()));
|
|
89
|
+
}
|
|
90
|
+
ceil() {
|
|
91
|
+
return numeric(Math.ceil(this.toNumber()));
|
|
92
|
+
}
|
|
93
|
+
roundDp() {
|
|
94
|
+
return roundValue(this.toNumber());
|
|
95
|
+
}
|
|
84
96
|
}
|
|
85
97
|
export class NumberOperator {
|
|
86
98
|
prepare(value) {
|
|
@@ -185,5 +197,8 @@ export function resolveToNumericValue(value) {
|
|
|
185
197
|
return new NumericValue(useValue, prefixPart * 3);
|
|
186
198
|
}
|
|
187
199
|
export function roundValue(value) {
|
|
200
|
+
if (typeof value === "number") {
|
|
201
|
+
value = numeric(value);
|
|
202
|
+
}
|
|
188
203
|
return resolveToNumericValue(new Big(value.toBigNumber().toFixed(7)));
|
|
189
204
|
}
|
package/dist/esm/parser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CircuitScriptParser } from './antlr/CircuitScriptParser.js';
|
|
2
2
|
import { MainLexer } from './lexer.js';
|
|
3
|
-
import {
|
|
3
|
+
import { SimpleStopwatch } from './utils.js';
|
|
4
|
+
import { ParseSyntaxError, RuntimeExecutionError } from "./errors.js";
|
|
4
5
|
import { CharStream, CommonTokenStream, PredictionMode } from 'antlr4ng';
|
|
5
6
|
export function parseFileWithVisitor(visitor, data, options) {
|
|
6
7
|
const lexerErrorListener = new CircuitscriptParserErrorListener(visitor.onErrorHandler);
|
package/dist/esm/pipeline.js
CHANGED
|
@@ -12,9 +12,10 @@ import { parseFileWithVisitor } from "./parser.js";
|
|
|
12
12
|
import { KiCadNetListOutputHandler } from "./render/KiCadNetListOutputHandler.js";
|
|
13
13
|
import { renderSheetsToSVG, generateSvgOutput, generatePdfOutput } from "./render/render.js";
|
|
14
14
|
import { EvaluateERCRules } from "./rules-check/rules.js";
|
|
15
|
-
import {
|
|
15
|
+
import { printWarnings, generateDebugSequenceAction, sequenceActionString, SimpleStopwatch } from "./utils.js";
|
|
16
16
|
import { ParserVisitor } from "./visitor.js";
|
|
17
17
|
import { getStylesFromDocument } from "./styles.js";
|
|
18
|
+
import { RuntimeExecutionError, ParseSyntaxError, ParseError, RenderError, AutoWireFailedError, AutoWireFailedError_ } from "./errors.js";
|
|
18
19
|
export async function renderScript(scriptData, outputPath, options) {
|
|
19
20
|
const parseHandlers = [
|
|
20
21
|
new KiCadNetListOutputHandler(),
|
|
@@ -208,7 +209,13 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
|
|
|
208
209
|
}
|
|
209
210
|
}
|
|
210
211
|
catch (err) {
|
|
211
|
-
|
|
212
|
+
let useErr = err;
|
|
213
|
+
if (err instanceof AutoWireFailedError_) {
|
|
214
|
+
const errCtx = visitor.wireCtxLinks.get(err.wire);
|
|
215
|
+
useErr = new AutoWireFailedError(err.message, errCtx.start, errCtx.stop);
|
|
216
|
+
}
|
|
217
|
+
dumpData && environment.writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
|
|
218
|
+
throw new RenderError(`Error during layout generation`, 'layout', { cause: useErr });
|
|
212
219
|
}
|
|
213
220
|
layoutEngine.printWarnings();
|
|
214
221
|
showStats && console.log('Layout took:', layoutTimer.lap());
|
|
@@ -270,7 +277,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
|
|
|
270
277
|
}
|
|
271
278
|
}
|
|
272
279
|
catch (err) {
|
|
273
|
-
throw new RenderError(`Error during rendering: ${err}`, 'output_generation');
|
|
280
|
+
throw new RenderError(`Error during rendering: ${err}`, 'output_generation', { cause: err });
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
283
|
return {
|
|
@@ -40,14 +40,14 @@ async function regenerateTests(extra = "") {
|
|
|
40
40
|
cstFiles.forEach(file => {
|
|
41
41
|
const svg1 = 'svgs/' + file + '.svg';
|
|
42
42
|
const svg2 = 'svgs/' + file + '.next.svg';
|
|
43
|
-
const cleanedName = file.replace('script', '')
|
|
44
|
-
|
|
43
|
+
const cleanedName = file.replace('script', '')
|
|
44
|
+
.replace('.cst', '')
|
|
45
|
+
.replace('.annotated', '');
|
|
46
|
+
allFiles.push([file, svg1, svg2, Number(cleanedName)]);
|
|
45
47
|
});
|
|
46
48
|
const sortedFiles = allFiles.sort((a, b) => {
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const indexA = Number(nameA);
|
|
50
|
-
const indexB = Number(nameB);
|
|
49
|
+
const indexA = a[3];
|
|
50
|
+
const indexB = b[3];
|
|
51
51
|
if (indexA > indexB) {
|
|
52
52
|
return 1;
|
|
53
53
|
}
|
|
@@ -2,7 +2,7 @@ import { milsToMM } from "../helpers.js";
|
|
|
2
2
|
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, Defaults, PinTypesList, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "../globals.js";
|
|
3
3
|
import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.js";
|
|
4
4
|
import { PinTypes } from "../objects/PinTypes.js";
|
|
5
|
-
import { RuntimeExecutionError, throwWithContext } from "../
|
|
5
|
+
import { RuntimeExecutionError, throwWithContext } from "../errors.js";
|
|
6
6
|
import { DeclaredReference, UndeclaredReference } from "../objects/types.js";
|
|
7
7
|
import { NumericValue, numeric, roundValue } from "../objects/NumericValue.js";
|
|
8
8
|
import { PinId } from "../objects/PinDefinition.js";
|
|
@@ -153,7 +153,7 @@ export class SymbolGraphic {
|
|
|
153
153
|
}
|
|
154
154
|
const isHorizontalLabel = finalLabelAngle === 0 || finalLabelAngle === 180;
|
|
155
155
|
const isVerticalLabel = finalLabelAngle === 90 || finalLabelAngle === -90;
|
|
156
|
-
if (useAnchor === HorizontalAlign.
|
|
156
|
+
if (useAnchor === HorizontalAlign.Center) {
|
|
157
157
|
anchorStyle = HorizontalAlignProp.Middle;
|
|
158
158
|
}
|
|
159
159
|
else if (useAnchor === HorizontalAlign.Left) {
|
|
@@ -162,7 +162,7 @@ export class SymbolGraphic {
|
|
|
162
162
|
else if (useAnchor === HorizontalAlign.Right) {
|
|
163
163
|
anchorStyle = HorizontalAlignProp.End;
|
|
164
164
|
}
|
|
165
|
-
if (useDominantBaseline === VerticalAlign.
|
|
165
|
+
if (useDominantBaseline === VerticalAlign.Center) {
|
|
166
166
|
dominantBaseline = VerticalAlignProp.Central;
|
|
167
167
|
}
|
|
168
168
|
else if (useDominantBaseline === VerticalAlign.Top) {
|
|
@@ -330,7 +330,7 @@ export class SymbolGraphic {
|
|
|
330
330
|
return HorizontalAlign.Left;
|
|
331
331
|
}
|
|
332
332
|
else {
|
|
333
|
-
return HorizontalAlign.
|
|
333
|
+
return HorizontalAlign.Center;
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
flipDominantBaseline(value) {
|
|
@@ -341,7 +341,7 @@ export class SymbolGraphic {
|
|
|
341
341
|
return VerticalAlign.Top;
|
|
342
342
|
}
|
|
343
343
|
else {
|
|
344
|
-
return VerticalAlign.
|
|
344
|
+
return VerticalAlign.Center;
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
}
|
|
@@ -358,7 +358,7 @@ export class SymbolText extends SymbolGraphic {
|
|
|
358
358
|
drawing.clear();
|
|
359
359
|
drawing.addTextbox(numeric(0), numeric(0), this.text, {
|
|
360
360
|
fontSize: this.fontSize,
|
|
361
|
-
anchor: HorizontalAlign.
|
|
361
|
+
anchor: HorizontalAlign.Center,
|
|
362
362
|
fontWeight: this.fontWeight,
|
|
363
363
|
});
|
|
364
364
|
this.drawing = drawing;
|
|
@@ -646,7 +646,7 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
646
646
|
displayPinName && usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY.add(pinNameOffsetY), usePinName, {
|
|
647
647
|
fontSize: numeric(defaultPinNameTextSize),
|
|
648
648
|
anchor: pinNameAlignment,
|
|
649
|
-
vanchor: VerticalAlign.
|
|
649
|
+
vanchor: VerticalAlign.Center,
|
|
650
650
|
textColor: pinNameColor,
|
|
651
651
|
angle: numeric(usePinIdAngle)
|
|
652
652
|
});
|
|
@@ -759,7 +759,7 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
759
759
|
drawing.addLabel(leftPinStart.add(milsToMM(20)), pinY, pin.text, {
|
|
760
760
|
fontSize: numeric(CustomSymbolPinTextSize),
|
|
761
761
|
anchor: HorizontalAlign.Left,
|
|
762
|
-
vanchor: VerticalAlign.
|
|
762
|
+
vanchor: VerticalAlign.Center,
|
|
763
763
|
textColor: ColorScheme.PinNameColor,
|
|
764
764
|
});
|
|
765
765
|
drawing.addLabel(leftPinStart.sub(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
|
|
@@ -776,7 +776,7 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
776
776
|
drawing.addLabel(rightPinStart.sub(milsToMM(20)), pinY, pin.text, {
|
|
777
777
|
fontSize: numeric(CustomSymbolPinTextSize),
|
|
778
778
|
anchor: HorizontalAlign.Right,
|
|
779
|
-
vanchor: VerticalAlign.
|
|
779
|
+
vanchor: VerticalAlign.Center,
|
|
780
780
|
textColor: ColorScheme.PinNameColor,
|
|
781
781
|
});
|
|
782
782
|
drawing.addLabel(rightPinStart.add(milsToMM(10)), pinY.sub(milsToMM(10)), pin.pinId.toString(), {
|
|
@@ -793,7 +793,7 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
793
793
|
drawing.addLabel(pinX, topPinStart.add(milsToMM(20)), pin.text, {
|
|
794
794
|
fontSize: numeric(CustomSymbolPinTextSize),
|
|
795
795
|
anchor: HorizontalAlign.Right,
|
|
796
|
-
vanchor: VerticalAlign.
|
|
796
|
+
vanchor: VerticalAlign.Center,
|
|
797
797
|
textColor: ColorScheme.PinNameColor,
|
|
798
798
|
angle: numeric(-90),
|
|
799
799
|
});
|
|
@@ -812,7 +812,7 @@ export class SymbolCustom extends SymbolGraphic {
|
|
|
812
812
|
drawing.addLabel(pinX, bottomPinStart.sub(milsToMM(20)), pin.text, {
|
|
813
813
|
fontSize: numeric(CustomSymbolPinTextSize),
|
|
814
814
|
anchor: HorizontalAlign.Left,
|
|
815
|
-
vanchor: VerticalAlign.
|
|
815
|
+
vanchor: VerticalAlign.Center,
|
|
816
816
|
textColor: ColorScheme.PinNameColor,
|
|
817
817
|
angle: numeric(-90),
|
|
818
818
|
});
|
|
@@ -895,7 +895,7 @@ export class SymbolCustomModule extends SymbolCustom {
|
|
|
895
895
|
drawing.addLabel(leftPinStart.add(this.portWidth).add(milsToMM(20)), pinY, pin.text, {
|
|
896
896
|
fontSize: numeric(40),
|
|
897
897
|
anchor: HorizontalAlign.Left,
|
|
898
|
-
vanchor: VerticalAlign.
|
|
898
|
+
vanchor: VerticalAlign.Center,
|
|
899
899
|
textColor: ColorScheme.PinNameColor,
|
|
900
900
|
});
|
|
901
901
|
});
|
|
@@ -907,7 +907,7 @@ export class SymbolCustomModule extends SymbolCustom {
|
|
|
907
907
|
drawing.addLabel(rightPinStart.sub(this.portWidth).sub(milsToMM(20)), pinY, pin.text, {
|
|
908
908
|
fontSize: numeric(40),
|
|
909
909
|
anchor: HorizontalAlign.Right,
|
|
910
|
-
vanchor: VerticalAlign.
|
|
910
|
+
vanchor: VerticalAlign.Center,
|
|
911
911
|
textColor: ColorScheme.PinNameColor,
|
|
912
912
|
});
|
|
913
913
|
});
|
|
@@ -919,7 +919,7 @@ export class SymbolCustomModule extends SymbolCustom {
|
|
|
919
919
|
drawing.addLabel(pinX, topPinStart.add(this.portWidth).add(milsToMM(20)), pin.text, {
|
|
920
920
|
fontSize: numeric(40),
|
|
921
921
|
anchor: HorizontalAlign.Right,
|
|
922
|
-
vanchor: VerticalAlign.
|
|
922
|
+
vanchor: VerticalAlign.Center,
|
|
923
923
|
textColor: ColorScheme.PinNameColor,
|
|
924
924
|
angle: numeric(-90),
|
|
925
925
|
});
|
|
@@ -932,7 +932,7 @@ export class SymbolCustomModule extends SymbolCustom {
|
|
|
932
932
|
drawing.addLabel(pinX, bottomPinStart.sub(this.portWidth).sub(milsToMM(20)), pin.text, {
|
|
933
933
|
fontSize: numeric(40),
|
|
934
934
|
anchor: HorizontalAlign.Left,
|
|
935
|
-
vanchor: VerticalAlign.
|
|
935
|
+
vanchor: VerticalAlign.Center,
|
|
936
936
|
textColor: ColorScheme.PinNameColor,
|
|
937
937
|
angle: numeric(-90),
|
|
938
938
|
});
|
|
@@ -464,7 +464,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
|
464
464
|
[1, 1],
|
|
465
465
|
];
|
|
466
466
|
}
|
|
467
|
-
else if (vAnchor === VerticalAlign.
|
|
467
|
+
else if (vAnchor === VerticalAlign.Center) {
|
|
468
468
|
coordVectors = [
|
|
469
469
|
[0, -0.5],
|
|
470
470
|
[0, 0.5],
|
|
@@ -490,7 +490,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
|
490
490
|
[0, -1],
|
|
491
491
|
];
|
|
492
492
|
}
|
|
493
|
-
else if (vAnchor === VerticalAlign.
|
|
493
|
+
else if (vAnchor === VerticalAlign.Center) {
|
|
494
494
|
coordVectors = [
|
|
495
495
|
[0, -0.5],
|
|
496
496
|
[0, 0.5],
|
|
@@ -507,7 +507,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
|
507
507
|
];
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
else if (hAnchor === HorizontalAlign.
|
|
510
|
+
else if (hAnchor === HorizontalAlign.Center) {
|
|
511
511
|
if (vAnchor === VerticalAlign.Bottom) {
|
|
512
512
|
coordVectors = [
|
|
513
513
|
[-0.5, 0],
|
|
@@ -516,7 +516,7 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
|
516
516
|
[0.5, 0]
|
|
517
517
|
];
|
|
518
518
|
}
|
|
519
|
-
else if (vAnchor === VerticalAlign.
|
|
519
|
+
else if (vAnchor === VerticalAlign.Center) {
|
|
520
520
|
coordVectors = [
|
|
521
521
|
[-0.5, 0.5],
|
|
522
522
|
[-0.5, -0.5],
|
|
@@ -543,13 +543,13 @@ function labelPolygonForAnchors(x, y, width, height, hAnchor, vAnchor) {
|
|
|
543
543
|
export var HorizontalAlign;
|
|
544
544
|
(function (HorizontalAlign) {
|
|
545
545
|
HorizontalAlign["Left"] = "left";
|
|
546
|
-
HorizontalAlign["
|
|
546
|
+
HorizontalAlign["Center"] = "center";
|
|
547
547
|
HorizontalAlign["Right"] = "right";
|
|
548
548
|
})(HorizontalAlign || (HorizontalAlign = {}));
|
|
549
549
|
export var VerticalAlign;
|
|
550
550
|
(function (VerticalAlign) {
|
|
551
551
|
VerticalAlign["Top"] = "top";
|
|
552
|
-
VerticalAlign["
|
|
552
|
+
VerticalAlign["Center"] = "center";
|
|
553
553
|
VerticalAlign["Bottom"] = "bottom";
|
|
554
554
|
})(VerticalAlign || (VerticalAlign = {}));
|
|
555
555
|
export var HorizontalAlignProp;
|