circuitscript 0.5.4 → 0.5.6
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/README.md +105 -2
- 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/index.js +1 -0
- 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/index.js +1 -0
- 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/index.d.ts +1 -0
- 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 +5 -2
|
@@ -268,25 +268,25 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
268
268
|
frameObjects.forEach(item => {
|
|
269
269
|
const { bounds, borderWidth } = item;
|
|
270
270
|
const { width, height } = (0, utils_js_1.getBoundsSize)(bounds);
|
|
271
|
-
|
|
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';
|
|
272
275
|
if (item.frame.frameType === globals_js_1.FrameType.Sheet) {
|
|
273
276
|
drawSheetFrameBorder(frameGroup, item);
|
|
274
277
|
}
|
|
275
278
|
else {
|
|
276
|
-
if (
|
|
277
|
-
if (item.renderType === layout_js_1.RenderFrameType.
|
|
278
|
-
strokeColor = '#111';
|
|
279
|
-
}
|
|
280
|
-
else if (item.renderType === layout_js_1.RenderFrameType.Elements) {
|
|
279
|
+
if (useBorderWidth > 0) {
|
|
280
|
+
if (item.renderType === layout_js_1.RenderFrameType.Elements) {
|
|
281
281
|
strokeColor = '#aaa';
|
|
282
282
|
if (!globals_js_1.RenderFlags.ShowElementFrames) {
|
|
283
283
|
return;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
|
-
const tmpRect = frameGroup.rect(
|
|
286
|
+
const tmpRect = frameGroup.rect(useWidth, useHeight)
|
|
287
287
|
.fill('none')
|
|
288
288
|
.stroke({
|
|
289
|
-
width: (0, helpers_js_1.milsToMM)(
|
|
289
|
+
width: (0, helpers_js_1.milsToMM)(useBorderWidth).toNumber(),
|
|
290
290
|
color: strokeColor
|
|
291
291
|
});
|
|
292
292
|
tmpRect.translate(item.x.toNumber(), item.y.toNumber());
|
|
@@ -308,17 +308,20 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
308
308
|
function drawGrid(group, gridProperties, logger) {
|
|
309
309
|
const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000", backgroundColor = "", } = gridProperties;
|
|
310
310
|
const gridSize = globals_js_1.defaultGridSizeUnits;
|
|
311
|
-
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
312
311
|
const extraValue = extendGrid ? 1 : 0;
|
|
313
|
-
const
|
|
314
|
-
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);
|
|
315
318
|
const gridEndX = extendGrid
|
|
316
|
-
? (
|
|
317
|
-
:
|
|
319
|
+
? xmax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
320
|
+
: xmax;
|
|
318
321
|
const gridEndY = extendGrid
|
|
319
|
-
? (
|
|
320
|
-
:
|
|
321
|
-
const numCols =
|
|
322
|
+
? ymax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
323
|
+
: ymax;
|
|
324
|
+
const numCols = gridEndX.sub(gridStartX).div(gridSize).floor().toNumber()
|
|
322
325
|
+ (extendGrid ? 1 : 0);
|
|
323
326
|
const originSize = (0, helpers_js_1.milsToMM)(10).toNumber();
|
|
324
327
|
globals_js_1.RenderFlags.ShowGridOrigin && group.circle(originSize)
|
|
@@ -335,8 +338,8 @@ function drawGrid(group, gridProperties, logger) {
|
|
|
335
338
|
lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
|
|
336
339
|
}
|
|
337
340
|
if (backgroundColor !== "") {
|
|
338
|
-
const width = gridEndX.sub(gridStartX).toNumber();
|
|
339
|
-
const height = gridEndY.sub(gridStartY).toNumber();
|
|
341
|
+
const width = gridEndX.sub(gridStartX).roundDp().toNumber();
|
|
342
|
+
const height = gridEndY.sub(gridStartY).roundDp().toNumber();
|
|
340
343
|
group
|
|
341
344
|
.rect(width, height).fill(backgroundColor)
|
|
342
345
|
.translate(gridStartX.toNumber(), gridStartY.toNumber());
|
|
@@ -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:
|
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,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);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ParserRuleContext } from "antlr4ng";
|
|
2
|
+
export class BaseError extends Error {
|
|
3
|
+
name = 'BaseError';
|
|
4
|
+
message;
|
|
5
|
+
startToken;
|
|
6
|
+
endToken;
|
|
7
|
+
filePath;
|
|
8
|
+
constructor(message, startTokenOrCtx, endToken, filePath, options) {
|
|
9
|
+
super(message, options);
|
|
10
|
+
this.message = message;
|
|
11
|
+
if (startTokenOrCtx instanceof ParserRuleContext) {
|
|
12
|
+
this.startToken = startTokenOrCtx.start;
|
|
13
|
+
this.endToken = startTokenOrCtx.stop;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.startToken = startTokenOrCtx;
|
|
17
|
+
this.endToken = endToken;
|
|
18
|
+
}
|
|
19
|
+
this.filePath = filePath;
|
|
20
|
+
}
|
|
21
|
+
toString() {
|
|
22
|
+
const parts = [this.name];
|
|
23
|
+
const linePosition = getLinePositionAsString({
|
|
24
|
+
start: this.startToken,
|
|
25
|
+
stop: this.endToken
|
|
26
|
+
});
|
|
27
|
+
if (linePosition !== null) {
|
|
28
|
+
parts.push(linePosition);
|
|
29
|
+
}
|
|
30
|
+
parts.push(`: ${this.message}`);
|
|
31
|
+
return parts.join('');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function getLinePositionAsString(ctx) {
|
|
35
|
+
if (ctx === null || ctx === undefined) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const { start: startToken, stop: stopToken } = ctx;
|
|
39
|
+
let result = null;
|
|
40
|
+
if (startToken) {
|
|
41
|
+
const { line, column } = startToken;
|
|
42
|
+
let stopLine = 0;
|
|
43
|
+
let stopCol = 0;
|
|
44
|
+
if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
|
|
45
|
+
stopLine = stopToken.line;
|
|
46
|
+
stopCol = stopToken.column + (stopToken.stop - stopToken.start);
|
|
47
|
+
}
|
|
48
|
+
else if (startToken === stopToken || startToken) {
|
|
49
|
+
stopLine = line;
|
|
50
|
+
stopCol = column + 1 + (startToken.stop - startToken.start);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
stopCol = -1;
|
|
54
|
+
}
|
|
55
|
+
result = ` at ${line}:${column + 1}`;
|
|
56
|
+
if (stopCol !== -1) {
|
|
57
|
+
result += `-${stopLine}:${stopCol + 1}`;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
export function throwWithContext(context, messageOrError) {
|
|
63
|
+
if (messageOrError instanceof BaseError) {
|
|
64
|
+
throw messageOrError;
|
|
65
|
+
}
|
|
66
|
+
throwWithTokenRange(messageOrError, context.start, context.stop);
|
|
67
|
+
}
|
|
68
|
+
export function throwWithTokenRange(message, startToken, endToken) {
|
|
69
|
+
throw new ParseError(message, startToken, endToken);
|
|
70
|
+
}
|
|
71
|
+
export class RenderError extends Error {
|
|
72
|
+
stage;
|
|
73
|
+
constructor(message, stage, options) {
|
|
74
|
+
super(message, options);
|
|
75
|
+
this.name = 'RenderError';
|
|
76
|
+
this.stage = stage;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export class AutoWireFailedError_ extends Error {
|
|
80
|
+
name = 'AutoWireFailedError_';
|
|
81
|
+
wire;
|
|
82
|
+
constructor(message, wire) {
|
|
83
|
+
super(message);
|
|
84
|
+
this.wire = wire;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export class AutoWireFailedError extends BaseError {
|
|
88
|
+
name = 'AutoWireFailedError';
|
|
89
|
+
}
|
|
90
|
+
export class RuntimeExecutionError extends BaseError {
|
|
91
|
+
name = 'RuntimeExecutionError';
|
|
92
|
+
}
|
|
93
|
+
export class ParseSyntaxError extends BaseError {
|
|
94
|
+
name = 'ParseSyntaxError';
|
|
95
|
+
}
|
|
96
|
+
export class ParseError extends ParseSyntaxError {
|
|
97
|
+
name = 'ParseError';
|
|
98
|
+
}
|
|
99
|
+
export function collectErrorChain(error) {
|
|
100
|
+
const items = [];
|
|
101
|
+
let currentError = error;
|
|
102
|
+
for (let i = 0; i < 100; i++) {
|
|
103
|
+
if (currentError.cause) {
|
|
104
|
+
items.push(currentError.cause);
|
|
105
|
+
currentError = currentError.cause;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return items;
|
|
112
|
+
}
|
|
113
|
+
export function printErrorChain(error) {
|
|
114
|
+
const errors = collectErrorChain(error);
|
|
115
|
+
errors.reverse();
|
|
116
|
+
for (const err of errors) {
|
|
117
|
+
console.log(" " + err.toString());
|
|
118
|
+
}
|
|
119
|
+
}
|
package/dist/esm/execute.js
CHANGED
|
@@ -12,7 +12,8 @@ import { Frame } from './objects/Frame.js';
|
|
|
12
12
|
import { CalculatePinPositions } from './render/layout.js';
|
|
13
13
|
import { UnitDimension } from './helpers.js';
|
|
14
14
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
|
|
15
|
-
import { getBlockTypeString
|
|
15
|
+
import { getBlockTypeString } from './utils.js';
|
|
16
|
+
import { RuntimeExecutionError } from "./errors.js";
|
|
16
17
|
export class ExecutionContext {
|
|
17
18
|
name;
|
|
18
19
|
namespace;
|
|
@@ -489,7 +490,13 @@ export class ExecutionContext {
|
|
|
489
490
|
const { start_point: [component, pin,] } = stackRef;
|
|
490
491
|
this.atComponent(component, pin, { addSequence: true });
|
|
491
492
|
}
|
|
492
|
-
this.scope.blockStack.
|
|
493
|
+
const scopeLevels = Array.from(this.scope.blockStack.keys());
|
|
494
|
+
for (const level of scopeLevels) {
|
|
495
|
+
if (level >= scopeLevel) {
|
|
496
|
+
this.log(`blockstack delete level ${level}`);
|
|
497
|
+
this.scope.blockStack.delete(level);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
493
500
|
this.log('exit blocks');
|
|
494
501
|
}
|
|
495
502
|
closeOpenPathBlocks() {
|
|
@@ -906,7 +913,7 @@ export class ExecutionContext {
|
|
|
906
913
|
this.log('-- done merging scope --');
|
|
907
914
|
return mergedInstances;
|
|
908
915
|
}
|
|
909
|
-
addWire(segments) {
|
|
916
|
+
addWire(segments, ctx) {
|
|
910
917
|
if (this.scope.currentComponent === null) {
|
|
911
918
|
throw "No current component";
|
|
912
919
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from './parser.js';
|
|
|
15
15
|
export * from './utils.js';
|
|
16
16
|
export * from './visitor.js';
|
|
17
17
|
export * from './sizing.js';
|
|
18
|
+
export * from './errors.js';
|
|
18
19
|
export * from './objects/types.js';
|
|
19
20
|
export * from './builtinMethods.js';
|
|
20
21
|
export * from './validate/SymbolTable.js';
|
package/dist/esm/main.js
CHANGED
|
@@ -4,6 +4,7 @@ import figlet from 'figlet';
|
|
|
4
4
|
import { watch } from 'fs';
|
|
5
5
|
import { renderScript } from "./pipeline.js";
|
|
6
6
|
import { NodeScriptEnvironment } from "./environment/environment.js";
|
|
7
|
+
import { printErrorChain } from './errors.js';
|
|
7
8
|
export default async function main() {
|
|
8
9
|
const env = new NodeScriptEnvironment();
|
|
9
10
|
NodeScriptEnvironment.setInstance(env);
|
|
@@ -133,8 +134,8 @@ async function parseFile(scriptData, outputPath, scriptOptions) {
|
|
|
133
134
|
return output;
|
|
134
135
|
}
|
|
135
136
|
catch (error) {
|
|
136
|
-
console.error(`Unexpected Error
|
|
137
|
-
|
|
137
|
+
console.error(`Unexpected Error:`);
|
|
138
|
+
printErrorChain(error);
|
|
138
139
|
}
|
|
139
140
|
return null;
|
|
140
141
|
}
|
|
@@ -2,7 +2,7 @@ import { SymbolDrawingCommands } from '../render/draw_symbols.js';
|
|
|
2
2
|
import { PinDefinition, PinId, PinIdType } from './PinDefinition.js';
|
|
3
3
|
import { PinTypes } from './PinTypes.js';
|
|
4
4
|
import { DefaultComponentUnit, ParamKeys } from '../globals.js';
|
|
5
|
-
import { RuntimeExecutionError } from
|
|
5
|
+
import { RuntimeExecutionError } from "../errors.js";
|
|
6
6
|
export class ComponentUnit {
|
|
7
7
|
parent;
|
|
8
8
|
unitId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Property_key_exprContext } from '../antlr/CircuitScriptParser.js';
|
|
2
2
|
import { PinId } from './PinDefinition.js';
|
|
3
|
-
import { RuntimeExecutionError } from
|
|
3
|
+
import { RuntimeExecutionError } from "../errors.js";
|
|
4
4
|
export class ExecutionScope {
|
|
5
5
|
scopeId;
|
|
6
6
|
nets = [];
|