circuitscript 0.5.3 → 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/annotate/ComponentAnnotater.js +3 -2
- 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/globals.js +10 -6
- 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/Frame.js +7 -0
- 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 +25 -15
- package/dist/cjs/regenerate-tests.js +6 -6
- package/dist/cjs/render/draw_symbols.js +40 -25
- package/dist/cjs/render/geometry.js +6 -6
- package/dist/cjs/render/graph.js +4 -0
- package/dist/cjs/render/layout.js +325 -253
- package/dist/cjs/render/render.js +38 -24
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +2 -2
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/styles.js +19 -0
- 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/annotate/ComponentAnnotater.js +3 -2
- 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/globals.js +8 -4
- 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/Frame.js +7 -0
- 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 +14 -4
- package/dist/esm/regenerate-tests.js +6 -6
- package/dist/esm/render/draw_symbols.js +41 -24
- package/dist/esm/render/geometry.js +6 -6
- package/dist/esm/render/graph.js +5 -0
- package/dist/esm/render/layout.js +325 -253
- package/dist/esm/render/render.js +38 -24
- package/dist/esm/semantic-tokens/getSemanticTokens.js +1 -1
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/styles.js +20 -0
- 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 +37 -37
- 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/globals.d.ts +8 -4
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/objects/Frame.d.ts +7 -0
- package/dist/types/objects/NumericValue.d.ts +5 -1
- package/dist/types/render/draw_symbols.d.ts +8 -3
- package/dist/types/render/geometry.d.ts +4 -4
- package/dist/types/render/graph.d.ts +3 -0
- package/dist/types/render/layout.d.ts +7 -1
- package/dist/types/render/render.d.ts +2 -1
- package/dist/types/styles.d.ts +11 -0
- package/dist/types/utils.d.ts +2 -27
- package/dist/types/visitor.d.ts +1 -1
- package/libs/std.cst +37 -37
- package/package.json +1 -1
|
@@ -25,7 +25,7 @@ function createSvgCanvas() {
|
|
|
25
25
|
(0, sizing_js_1.applyFontsToSVG)(canvas);
|
|
26
26
|
return canvas;
|
|
27
27
|
}
|
|
28
|
-
function renderSheetsToSVG(sheetFrames, logger, documentVariable) {
|
|
28
|
+
function renderSheetsToSVG(sheetFrames, logger, documentVariable, styles) {
|
|
29
29
|
const canvas = createSvgCanvas();
|
|
30
30
|
sheetFrames.forEach((sheet, index) => {
|
|
31
31
|
const sheetGroup = canvas.group();
|
|
@@ -87,8 +87,9 @@ function renderSheetsToSVG(sheetFrames, logger, documentVariable) {
|
|
|
87
87
|
extendGrid,
|
|
88
88
|
style: documentVariable[Frame_js_1.FrameParamKeys.GridStyle],
|
|
89
89
|
color: documentVariable[Frame_js_1.FrameParamKeys.GridColor],
|
|
90
|
+
backgroundColor: documentVariable[Frame_js_1.FrameParamKeys.BackgroundColor],
|
|
90
91
|
};
|
|
91
|
-
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridProperties, logger);
|
|
92
|
+
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridProperties, styles, logger);
|
|
92
93
|
sheetElements.translate(xOffset, yOffset);
|
|
93
94
|
sheetGroup.translate(0, sheetYOffset.toNumber());
|
|
94
95
|
});
|
|
@@ -135,7 +136,7 @@ function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoomScale =
|
|
|
135
136
|
});
|
|
136
137
|
}
|
|
137
138
|
exports.generatePdfOutput = generatePdfOutput;
|
|
138
|
-
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridProperties, logger) {
|
|
139
|
+
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridProperties, styles, logger) {
|
|
139
140
|
const displayWireId = false;
|
|
140
141
|
if (gridProperties.gridBounds === null) {
|
|
141
142
|
logger.add('get grid bounds');
|
|
@@ -189,19 +190,22 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
189
190
|
}
|
|
190
191
|
const mergedWireHighlightGroup = canvas.group();
|
|
191
192
|
const mergedWireGroup = canvas.group();
|
|
193
|
+
styles = styles ?? {};
|
|
194
|
+
const defaultWireColor = styles.wireColor;
|
|
195
|
+
const defaultWireLineWidth = (0, helpers_js_1.milsToMM)(styles.wireWidth).toNumber();
|
|
192
196
|
mergedWires.forEach(tmpItem => {
|
|
193
197
|
const { intersectPoints, net = null, lines = null } = tmpItem;
|
|
194
198
|
let useJunctionColor = globals_js_1.ColorScheme.JunctionColor;
|
|
195
|
-
let useColor =
|
|
196
|
-
let useLineWidth =
|
|
199
|
+
let useColor = defaultWireColor;
|
|
200
|
+
let useLineWidth = defaultWireLineWidth;
|
|
197
201
|
let displayHighlight = false;
|
|
198
202
|
let displayHighlightColor = null;
|
|
199
203
|
let displayHighlightOpacity = 0.3;
|
|
200
204
|
let displayHighlightWidth = 5 * globals_js_1.MilsToMM;
|
|
201
205
|
if (net !== null) {
|
|
202
|
-
useColor = net.color ??
|
|
206
|
+
useColor = net.color ?? defaultWireColor;
|
|
203
207
|
useJunctionColor = net.color ?? globals_js_1.ColorScheme.JunctionColor;
|
|
204
|
-
useLineWidth = net.lineWidth ??
|
|
208
|
+
useLineWidth = net.lineWidth ?? defaultWireLineWidth;
|
|
205
209
|
if (net.highlight !== null) {
|
|
206
210
|
displayHighlight = true;
|
|
207
211
|
displayHighlightColor = net.highlight ?? null;
|
|
@@ -264,25 +268,25 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
264
268
|
frameObjects.forEach(item => {
|
|
265
269
|
const { bounds, borderWidth } = item;
|
|
266
270
|
const { width, height } = (0, utils_js_1.getBoundsSize)(bounds);
|
|
267
|
-
|
|
271
|
+
const useWidth = (0, NumericValue_js_1.roundValue)(width).toNumber();
|
|
272
|
+
const useHeight = (0, NumericValue_js_1.roundValue)(height).toNumber();
|
|
273
|
+
const useBorderWidth = (0, NumericValue_js_1.roundValue)(borderWidth).toNumber();
|
|
274
|
+
let strokeColor = item.borderColor ?? '#111';
|
|
268
275
|
if (item.frame.frameType === globals_js_1.FrameType.Sheet) {
|
|
269
276
|
drawSheetFrameBorder(frameGroup, item);
|
|
270
277
|
}
|
|
271
278
|
else {
|
|
272
|
-
if (
|
|
273
|
-
if (item.renderType === layout_js_1.RenderFrameType.
|
|
274
|
-
strokeColor = '#111';
|
|
275
|
-
}
|
|
276
|
-
else if (item.renderType === layout_js_1.RenderFrameType.Elements) {
|
|
279
|
+
if (useBorderWidth > 0) {
|
|
280
|
+
if (item.renderType === layout_js_1.RenderFrameType.Elements) {
|
|
277
281
|
strokeColor = '#aaa';
|
|
278
282
|
if (!globals_js_1.RenderFlags.ShowElementFrames) {
|
|
279
283
|
return;
|
|
280
284
|
}
|
|
281
285
|
}
|
|
282
|
-
const tmpRect = frameGroup.rect(
|
|
286
|
+
const tmpRect = frameGroup.rect(useWidth, useHeight)
|
|
283
287
|
.fill('none')
|
|
284
288
|
.stroke({
|
|
285
|
-
width: (0, helpers_js_1.milsToMM)(
|
|
289
|
+
width: (0, helpers_js_1.milsToMM)(useBorderWidth).toNumber(),
|
|
286
290
|
color: strokeColor
|
|
287
291
|
});
|
|
288
292
|
tmpRect.translate(item.x.toNumber(), item.y.toNumber());
|
|
@@ -302,19 +306,22 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
302
306
|
.stroke('none').fill('red');
|
|
303
307
|
}
|
|
304
308
|
function drawGrid(group, gridProperties, logger) {
|
|
305
|
-
const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000" } = gridProperties;
|
|
309
|
+
const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000", backgroundColor = "", } = gridProperties;
|
|
306
310
|
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
307
|
-
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
308
311
|
const extraValue = extendGrid ? 1 : 0;
|
|
309
|
-
const
|
|
310
|
-
const
|
|
312
|
+
const xmin = (0, NumericValue_js_1.roundValue)(canvasSize.xmin);
|
|
313
|
+
const ymin = (0, NumericValue_js_1.roundValue)(canvasSize.ymin);
|
|
314
|
+
const xmax = (0, NumericValue_js_1.roundValue)(canvasSize.xmax);
|
|
315
|
+
const ymax = (0, NumericValue_js_1.roundValue)(canvasSize.ymax);
|
|
316
|
+
const gridStartX = xmin.div(gridSize).floor().sub(extraValue).mul(gridSize);
|
|
317
|
+
const gridStartY = ymin.div(gridSize).floor().sub(extraValue).mul(gridSize);
|
|
311
318
|
const gridEndX = extendGrid
|
|
312
|
-
? (
|
|
313
|
-
:
|
|
319
|
+
? xmax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
320
|
+
: xmax;
|
|
314
321
|
const gridEndY = extendGrid
|
|
315
|
-
? (
|
|
316
|
-
:
|
|
317
|
-
const numCols =
|
|
322
|
+
? ymax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
323
|
+
: ymax;
|
|
324
|
+
const numCols = gridEndX.sub(gridStartX).div(gridSize).floor().toNumber()
|
|
318
325
|
+ (extendGrid ? 1 : 0);
|
|
319
326
|
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
320
327
|
globals_js_1.RenderFlags.ShowGridOrigin && group.circle(originSize)
|
|
@@ -330,6 +337,13 @@ function drawGrid(group, gridProperties, logger) {
|
|
|
330
337
|
const startX = gridStartX.add(numericGridSize.mul(i)).toNumber();
|
|
331
338
|
lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
|
|
332
339
|
}
|
|
340
|
+
if (backgroundColor !== "") {
|
|
341
|
+
const width = gridEndX.sub(gridStartX).roundDp().toNumber();
|
|
342
|
+
const height = gridEndY.sub(gridStartY).roundDp().toNumber();
|
|
343
|
+
group
|
|
344
|
+
.rect(width, height).fill(backgroundColor)
|
|
345
|
+
.translate(gridStartX.toNumber(), gridStartY.toNumber());
|
|
346
|
+
}
|
|
333
347
|
const strokeSize = (0, helpers_js_1.milsToMM)(3);
|
|
334
348
|
group.addClass('grid')
|
|
335
349
|
.path(lines.join(" "))
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getSemanticTokens = void 0;
|
|
4
4
|
const helpers_js_1 = require("../helpers.js");
|
|
5
5
|
const SemanticTokenVisitor_js_1 = require("./SemanticTokenVisitor.js");
|
|
6
|
-
const
|
|
6
|
+
const errors_js_1 = require("../errors.js");
|
|
7
7
|
async function getSemanticTokens(filePath, scriptData, options) {
|
|
8
8
|
const { parser, lexer, tokens } = (0, helpers_js_1.prepareFile)(scriptData);
|
|
9
9
|
const tree = parser.script();
|
|
@@ -22,7 +22,7 @@ async function getSemanticTokens(filePath, scriptData, options) {
|
|
|
22
22
|
console.log('Error while parsing: ', err);
|
|
23
23
|
hasParseError = true;
|
|
24
24
|
hasError = true;
|
|
25
|
-
throw new
|
|
25
|
+
throw new errors_js_1.ParseError(`Error parsing semantic tokens in imported file: ${err}`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
else {
|
package/dist/cjs/sizing.js
CHANGED
|
@@ -20,7 +20,7 @@ function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', an
|
|
|
20
20
|
case geometry_js_1.VerticalAlign.Top:
|
|
21
21
|
dominantBaseline = geometry_js_1.VerticalAlignProp.Hanging;
|
|
22
22
|
break;
|
|
23
|
-
case geometry_js_1.VerticalAlign.
|
|
23
|
+
case geometry_js_1.VerticalAlign.Center:
|
|
24
24
|
dominantBaseline = geometry_js_1.VerticalAlignProp.Central;
|
|
25
25
|
break;
|
|
26
26
|
case geometry_js_1.VerticalAlign.Bottom:
|
|
@@ -32,7 +32,7 @@ function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regular', an
|
|
|
32
32
|
case geometry_js_1.HorizontalAlign.Left:
|
|
33
33
|
useAnchor = geometry_js_1.HorizontalAlignProp.Start;
|
|
34
34
|
break;
|
|
35
|
-
case geometry_js_1.HorizontalAlign.
|
|
35
|
+
case geometry_js_1.HorizontalAlign.Center:
|
|
36
36
|
useAnchor = geometry_js_1.HorizontalAlignProp.Middle;
|
|
37
37
|
break;
|
|
38
38
|
case geometry_js_1.HorizontalAlign.Right:
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStylesFromDocument = exports.Styles = void 0;
|
|
4
|
+
const globals_js_1 = require("./globals.js");
|
|
5
|
+
const Frame_js_1 = require("./objects/Frame.js");
|
|
6
|
+
class Styles {
|
|
7
|
+
}
|
|
8
|
+
exports.Styles = Styles;
|
|
9
|
+
function getStylesFromDocument(document) {
|
|
10
|
+
const styles = new Styles();
|
|
11
|
+
styles.lineColor = document[Frame_js_1.FrameParamKeys.LineColor] ?? globals_js_1.ColorScheme.PinLineColor;
|
|
12
|
+
styles.lineWidth = document[Frame_js_1.FrameParamKeys.LineWidth] ?? globals_js_1.Defaults.LineWidth;
|
|
13
|
+
styles.fillColor = document[Frame_js_1.FrameParamKeys.FillColor];
|
|
14
|
+
styles.textColor = document[Frame_js_1.FrameParamKeys.TextColor] ?? globals_js_1.ColorScheme.PinNameColor;
|
|
15
|
+
styles.wireColor = document[Frame_js_1.FrameParamKeys.WireColor] ?? globals_js_1.ColorScheme.WireColor;
|
|
16
|
+
styles.wireWidth = document[Frame_js_1.FrameParamKeys.WireWidth] ?? globals_js_1.Defaults.WireLineWidth;
|
|
17
|
+
return styles;
|
|
18
|
+
}
|
|
19
|
+
exports.getStylesFromDocument = getStylesFromDocument;
|
package/dist/cjs/utils.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isReference = exports.unwrapValue = exports.printWarnings = exports.
|
|
4
|
-
const antlr4ng_1 = require("antlr4ng");
|
|
3
|
+
exports.isReference = exports.unwrapValue = exports.printWarnings = exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.combineMaps = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid2 = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
5
4
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
6
5
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
7
6
|
const BlockTypes_js_1 = require("./objects/BlockTypes.js");
|
|
8
7
|
const types_js_1 = require("./objects/types.js");
|
|
8
|
+
const errors_js_1 = require("./errors.js");
|
|
9
|
+
const NumericValue_js_1 = require("./objects/NumericValue.js");
|
|
9
10
|
class SimpleStopwatch {
|
|
10
11
|
constructor() {
|
|
11
12
|
this.startTime = performance.now();
|
|
@@ -45,17 +46,21 @@ function resizeToNearestGrid(bounds, gridSize = 20) {
|
|
|
45
46
|
const addXMax = hasRemainder(bounds.xmax, gridSize) === 0 ? 1 : 0;
|
|
46
47
|
const addYMax = hasRemainder(bounds.ymax, gridSize) === 0 ? 1 : 0;
|
|
47
48
|
return {
|
|
48
|
-
xmin: Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize,
|
|
49
|
-
ymin: Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize,
|
|
50
|
-
xmax: Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize,
|
|
51
|
-
ymax: Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize,
|
|
49
|
+
xmin: (0, NumericValue_js_1.roundValue)(Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize).toNumber(),
|
|
50
|
+
ymin: (0, NumericValue_js_1.roundValue)(Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize).toNumber(),
|
|
51
|
+
xmax: (0, NumericValue_js_1.roundValue)(Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize).toNumber(),
|
|
52
|
+
ymax: (0, NumericValue_js_1.roundValue)(Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize).toNumber(),
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
exports.resizeToNearestGrid = resizeToNearestGrid;
|
|
55
56
|
function toNearestGrid(value, gridSize) {
|
|
56
|
-
return
|
|
57
|
+
return (0, NumericValue_js_1.roundValue)(value / gridSize).floor().mul(gridSize).toNumber();
|
|
57
58
|
}
|
|
58
59
|
exports.toNearestGrid = toNearestGrid;
|
|
60
|
+
function toNearestGrid2(value, gridSize) {
|
|
61
|
+
return (0, NumericValue_js_1.roundValue)(value / gridSize).ceil().mul(gridSize).toNumber();
|
|
62
|
+
}
|
|
63
|
+
exports.toNearestGrid2 = toNearestGrid2;
|
|
59
64
|
function getBoundsSize(bounds) {
|
|
60
65
|
return {
|
|
61
66
|
width: bounds.xmax - bounds.xmin,
|
|
@@ -78,21 +83,6 @@ function getPortType(component) {
|
|
|
78
83
|
return foundPinType;
|
|
79
84
|
}
|
|
80
85
|
exports.getPortType = getPortType;
|
|
81
|
-
function throwWithContext(context, messageOrError) {
|
|
82
|
-
if (messageOrError instanceof BaseError) {
|
|
83
|
-
throw messageOrError;
|
|
84
|
-
}
|
|
85
|
-
throwWithTokenRange(messageOrError, context.start, context.stop);
|
|
86
|
-
}
|
|
87
|
-
exports.throwWithContext = throwWithContext;
|
|
88
|
-
function throwWithToken(message, token) {
|
|
89
|
-
throw new ParseError(message, token);
|
|
90
|
-
}
|
|
91
|
-
exports.throwWithToken = throwWithToken;
|
|
92
|
-
function throwWithTokenRange(message, startToken, endToken) {
|
|
93
|
-
throw new ParseError(message, startToken, endToken);
|
|
94
|
-
}
|
|
95
|
-
exports.throwWithTokenRange = throwWithTokenRange;
|
|
96
86
|
function combineMaps(map1, map2) {
|
|
97
87
|
const newMap = new Map(map1);
|
|
98
88
|
map2.forEach((value, key) => {
|
|
@@ -192,98 +182,11 @@ function getBlockTypeString(type) {
|
|
|
192
182
|
return returnValue;
|
|
193
183
|
}
|
|
194
184
|
exports.getBlockTypeString = getBlockTypeString;
|
|
195
|
-
class BaseError extends Error {
|
|
196
|
-
constructor(message, startTokenOrCtx, endToken, filePath) {
|
|
197
|
-
super(message);
|
|
198
|
-
this.name = 'BaseError';
|
|
199
|
-
this.message = message;
|
|
200
|
-
if (startTokenOrCtx instanceof antlr4ng_1.ParserRuleContext) {
|
|
201
|
-
this.startToken = startTokenOrCtx.start;
|
|
202
|
-
this.endToken = startTokenOrCtx.stop;
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
this.startToken = startTokenOrCtx;
|
|
206
|
-
this.endToken = endToken;
|
|
207
|
-
}
|
|
208
|
-
this.filePath = filePath;
|
|
209
|
-
}
|
|
210
|
-
toString() {
|
|
211
|
-
const parts = [this.name];
|
|
212
|
-
const linePosition = getLinePositionAsString({
|
|
213
|
-
start: this.startToken,
|
|
214
|
-
stop: this.endToken
|
|
215
|
-
});
|
|
216
|
-
if (linePosition !== null) {
|
|
217
|
-
parts.push(linePosition);
|
|
218
|
-
}
|
|
219
|
-
parts.push(`: ${this.message}`);
|
|
220
|
-
return parts.join('');
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
exports.BaseError = BaseError;
|
|
224
|
-
function getLinePositionAsString(ctx) {
|
|
225
|
-
if (ctx === null || ctx === undefined) {
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
const { start: startToken, stop: stopToken } = ctx;
|
|
229
|
-
let result = null;
|
|
230
|
-
if (startToken) {
|
|
231
|
-
const { line, column } = startToken;
|
|
232
|
-
let stopLine = 0;
|
|
233
|
-
let stopCol = 0;
|
|
234
|
-
if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
|
|
235
|
-
stopLine = stopToken.line;
|
|
236
|
-
stopCol = stopToken.column + (stopToken.stop - stopToken.start);
|
|
237
|
-
}
|
|
238
|
-
else if (startToken === stopToken || startToken) {
|
|
239
|
-
stopLine = line;
|
|
240
|
-
stopCol = column + 1 + (startToken.stop - startToken.start);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
stopCol = -1;
|
|
244
|
-
}
|
|
245
|
-
result = ` at ${line}:${column + 1}`;
|
|
246
|
-
if (stopCol !== -1) {
|
|
247
|
-
result += `-${stopLine}:${stopCol + 1}`;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
exports.getLinePositionAsString = getLinePositionAsString;
|
|
253
|
-
class ParseSyntaxError extends BaseError {
|
|
254
|
-
constructor() {
|
|
255
|
-
super(...arguments);
|
|
256
|
-
this.name = 'ParseSyntaxError';
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
exports.ParseSyntaxError = ParseSyntaxError;
|
|
260
|
-
class ParseError extends ParseSyntaxError {
|
|
261
|
-
constructor() {
|
|
262
|
-
super(...arguments);
|
|
263
|
-
this.name = 'ParseError';
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
exports.ParseError = ParseError;
|
|
267
|
-
class RuntimeExecutionError extends BaseError {
|
|
268
|
-
constructor() {
|
|
269
|
-
super(...arguments);
|
|
270
|
-
this.name = 'RuntimeExecutionError';
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
exports.RuntimeExecutionError = RuntimeExecutionError;
|
|
274
|
-
class RenderError extends Error {
|
|
275
|
-
constructor(message, stage) {
|
|
276
|
-
super(message);
|
|
277
|
-
this.name = 'RenderError';
|
|
278
|
-
this.stage = stage;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
exports.RenderError = RenderError;
|
|
282
185
|
function printWarnings(warnings) {
|
|
283
186
|
const warningMessages = [];
|
|
284
187
|
warnings.forEach(item => {
|
|
285
188
|
const { message } = item;
|
|
286
|
-
const linePosition = getLinePositionAsString(item.ctx);
|
|
189
|
+
const linePosition = (0, errors_js_1.getLinePositionAsString)(item.ctx);
|
|
287
190
|
const parts = [message];
|
|
288
191
|
if (linePosition !== null) {
|
|
289
192
|
parts.push(linePosition);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateScript = void 0;
|
|
4
4
|
const helpers_js_1 = require("../helpers.js");
|
|
5
|
-
const
|
|
5
|
+
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const SymbolValidatorResolveVisitor_js_1 = require("./SymbolValidatorResolveVisitor.js");
|
|
7
7
|
const SymbolValidatorVisitor_js_1 = require("./SymbolValidatorVisitor.js");
|
|
8
8
|
async function validateScript(filePath, scriptData, options) {
|
|
@@ -29,7 +29,7 @@ async function validateScript(filePath, scriptData, options) {
|
|
|
29
29
|
console.log('got an error while parsing tree: ', err);
|
|
30
30
|
hasParseError = true;
|
|
31
31
|
hasError = true;
|
|
32
|
-
throw new
|
|
32
|
+
throw new errors_js_1.ParseError(`Error parsing validation in imported file: ${err}`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
else {
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -14,6 +14,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
14
14
|
const draw_symbols_js_1 = require("./render/draw_symbols.js");
|
|
15
15
|
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
16
16
|
const utils_js_2 = require("./utils.js");
|
|
17
|
+
const errors_js_1 = require("./errors.js");
|
|
17
18
|
const helpers_js_1 = require("./helpers.js");
|
|
18
19
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
19
20
|
const ComponentAnnotater_js_1 = require("./annotate/ComponentAnnotater.js");
|
|
@@ -35,7 +36,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
35
36
|
pinValue = result;
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
|
-
throw new
|
|
39
|
+
throw new errors_js_1.RuntimeExecutionError("Invalid select pin: " + result, ctx);
|
|
39
40
|
}
|
|
40
41
|
if (pinValue !== undefined) {
|
|
41
42
|
pinId = new PinDefinition_js_1.PinId(pinValue);
|
|
@@ -85,7 +86,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
85
86
|
refComponent = component;
|
|
86
87
|
}
|
|
87
88
|
catch (err) {
|
|
88
|
-
throw new
|
|
89
|
+
throw new errors_js_1.RuntimeExecutionError(err.message, ctx);
|
|
89
90
|
}
|
|
90
91
|
});
|
|
91
92
|
this.linkComponentToCtx(item, refComponent, creationFlag);
|
|
@@ -785,8 +786,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
785
786
|
if (segments.length === 0) {
|
|
786
787
|
this.throwWithContext(ctx, "Invalid wire expression");
|
|
787
788
|
}
|
|
788
|
-
const newWire = this.getExecutor().addWire(segments);
|
|
789
|
+
const newWire = this.getExecutor().addWire(segments, ctx);
|
|
789
790
|
this.creationCtx.set(newWire, ctx);
|
|
791
|
+
this.wireCtxLinks.set(newWire, ctx);
|
|
790
792
|
};
|
|
791
793
|
this.visitPoint_expr = (ctx) => {
|
|
792
794
|
const ctxDataExpr = ctx.data_expr();
|
|
@@ -799,7 +801,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
799
801
|
pointValue = resultValue;
|
|
800
802
|
}
|
|
801
803
|
else {
|
|
802
|
-
throw new
|
|
804
|
+
throw new errors_js_1.RuntimeExecutionError('Invalid value for point');
|
|
803
805
|
}
|
|
804
806
|
}
|
|
805
807
|
else {
|
|
@@ -1185,13 +1187,13 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1185
1187
|
break;
|
|
1186
1188
|
case 'display':
|
|
1187
1189
|
if (didDefineArrangeProp) {
|
|
1188
|
-
throw new
|
|
1190
|
+
throw new errors_js_1.RuntimeExecutionError("arrange property has already been defined", ctx);
|
|
1189
1191
|
}
|
|
1190
1192
|
didDefineDisplayProp = true;
|
|
1191
1193
|
break;
|
|
1192
1194
|
case 'arrange':
|
|
1193
1195
|
if (didDefineDisplayProp) {
|
|
1194
|
-
throw new
|
|
1196
|
+
throw new errors_js_1.RuntimeExecutionError("display property already defined", ctx);
|
|
1195
1197
|
}
|
|
1196
1198
|
didDefineArrangeProp = true;
|
|
1197
1199
|
break;
|
|
@@ -1212,7 +1214,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1212
1214
|
this.validateBoolean(value, ctx);
|
|
1213
1215
|
}
|
|
1214
1216
|
else {
|
|
1215
|
-
throw new
|
|
1217
|
+
throw new errors_js_1.RuntimeExecutionError("Invalid value for 'copy' property", ctx);
|
|
1216
1218
|
}
|
|
1217
1219
|
break;
|
|
1218
1220
|
}
|
|
@@ -1222,7 +1224,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1222
1224
|
if (keyName === 'arrange') {
|
|
1223
1225
|
const [sideKeyCtx, sideKeyName] = path[1];
|
|
1224
1226
|
if (globals_js_1.ValidPinSides.indexOf(sideKeyName) === -1) {
|
|
1225
|
-
throw new
|
|
1227
|
+
throw new errors_js_1.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
|
|
1226
1228
|
}
|
|
1227
1229
|
else {
|
|
1228
1230
|
if (path.length === 2 && value instanceof NumericValue_js_1.NumericValue) {
|
|
@@ -1233,12 +1235,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1233
1235
|
const goodBlank = value.length === 1 &&
|
|
1234
1236
|
value[0] instanceof NumericValue_js_1.NumericValue;
|
|
1235
1237
|
if (!goodBlank) {
|
|
1236
|
-
throw new
|
|
1238
|
+
throw new errors_js_1.RuntimeExecutionError(`Invalid blank specifier`, ctx);
|
|
1237
1239
|
}
|
|
1238
1240
|
}
|
|
1239
1241
|
else {
|
|
1240
1242
|
if (!(value instanceof NumericValue_js_1.NumericValue) && !(typeof value === 'string')) {
|
|
1241
|
-
throw new
|
|
1243
|
+
throw new errors_js_1.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
|
|
1242
1244
|
}
|
|
1243
1245
|
else {
|
|
1244
1246
|
let useValue;
|
|
@@ -1274,7 +1276,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1274
1276
|
if (value.length === 2) {
|
|
1275
1277
|
const [pinType,] = value;
|
|
1276
1278
|
if (pinType instanceof types_js_1.UndeclaredReference) {
|
|
1277
|
-
throw new
|
|
1279
|
+
throw new errors_js_1.RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx);
|
|
1278
1280
|
}
|
|
1279
1281
|
}
|
|
1280
1282
|
}
|
|
@@ -1631,7 +1633,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1631
1633
|
net.name = net.baseName =
|
|
1632
1634
|
`NET-(${component.assignedRefDes}-${pin.toString()})`;
|
|
1633
1635
|
if (fullNetNames.indexOf(net.toString()) !== -1) {
|
|
1634
|
-
throw new
|
|
1636
|
+
throw new errors_js_1.RuntimeExecutionError('Net renaming failed due to clash: ' + net);
|
|
1635
1637
|
}
|
|
1636
1638
|
seenNets.push(net);
|
|
1637
1639
|
}
|
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Direction, AnyReference, UndeclaredReference, ImportedLibrary, ImportFu
|
|
|
11
11
|
import { BaseNamespace, DoubleDelimiter1, GlobalDocumentName, ParamKeys, PinTypesList, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
12
12
|
import { isReference, unwrapValue as unwrapValue } from "./utils.js";
|
|
13
13
|
import { linkBuiltInMethods } from './builtinMethods.js';
|
|
14
|
-
import {
|
|
14
|
+
import { throwWithContext, RuntimeExecutionError } from './errors.js';
|
|
15
15
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
16
16
|
import { computeContentHash } from './cache/hash.js';
|
|
17
17
|
import { readCache, writeCache } from './cache/storage.js';
|
|
@@ -32,6 +32,7 @@ export class BaseVisitor extends CircuitScriptParserVisitor {
|
|
|
32
32
|
Direction.Right, Direction.Left];
|
|
33
33
|
resultData = new Map;
|
|
34
34
|
componentCtxLinks = new Map;
|
|
35
|
+
wireCtxLinks = new Map;
|
|
35
36
|
onErrorHandler = null;
|
|
36
37
|
environment;
|
|
37
38
|
importedFiles = [];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComponentRefDesPrefixes } from './../visitor.js';
|
|
2
|
+
import { KeywordRefdesPrefix } from '../globals.js';
|
|
2
3
|
export class ComponentAnnotater {
|
|
3
4
|
counter = {};
|
|
4
5
|
indexedContextPrefix = new Map();
|
|
@@ -11,8 +12,8 @@ export class ComponentAnnotater {
|
|
|
11
12
|
getAnnotation(instance) {
|
|
12
13
|
let usePrefix;
|
|
13
14
|
let useCounterKey;
|
|
14
|
-
if (instance.hasParam(
|
|
15
|
-
const prefix = instance.getParam(
|
|
15
|
+
if (instance.hasParam(KeywordRefdesPrefix)) {
|
|
16
|
+
const prefix = instance.getParam(KeywordRefdesPrefix);
|
|
16
17
|
if (this.counter[prefix] === undefined) {
|
|
17
18
|
this.counter[prefix] = 1;
|
|
18
19
|
}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
2
|
import { NumericValue, numeric, resolveToNumericValue } from "./objects/NumericValue.js";
|
|
3
3
|
import { CFunctionEntry, ImportedLibrary } from "./objects/types.js";
|
|
4
|
-
import { unwrapValue
|
|
4
|
+
import { unwrapValue } from "./utils.js";
|
|
5
|
+
import { RuntimeExecutionError } from "./errors.js";
|
|
5
6
|
import { BaseNamespace } from "./globals.js";
|
|
6
7
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
7
8
|
import { Net } from "./objects/Net.js";
|
|
8
9
|
const builtInMethods = [
|
|
9
10
|
['enumerate', enumerate],
|
|
10
|
-
['
|
|
11
|
+
['to_mils', toMils],
|
|
11
12
|
['range', range],
|
|
12
13
|
['len', objectLength],
|
|
13
|
-
['
|
|
14
|
-
['
|
|
15
|
-
['
|
|
14
|
+
['array_push', arrayPush],
|
|
15
|
+
['array_get', arrayGet],
|
|
16
|
+
['array_set', arraySet],
|
|
16
17
|
['print', null],
|
|
17
18
|
];
|
|
18
19
|
export const buildInMethodNamesList = builtInMethods.map(item => item[0]);
|
|
@@ -3,7 +3,7 @@ import fs from 'fs';
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import CryptoJs from "crypto-js";
|
|
5
5
|
import { TOOL_VERSION } from "../globals.js";
|
|
6
|
-
import { RuntimeExecutionError } from "../
|
|
6
|
+
import { RuntimeExecutionError } from "../errors.js";
|
|
7
7
|
export class NodeScriptEnvironment {
|
|
8
8
|
existsSync(pathLike) {
|
|
9
9
|
return fs.existsSync(pathLike);
|