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
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.js";
|
|
3
3
|
import { applyFontsToSVG } from '../sizing.js';
|
|
4
|
-
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM,
|
|
5
|
-
import { NumericValue, numeric } from '../objects/NumericValue.js';
|
|
4
|
+
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, fontDisplayScale, junctionSize } from '../globals.js';
|
|
5
|
+
import { NumericValue, numeric, roundValue } from '../objects/NumericValue.js';
|
|
6
6
|
import { combineMaps, getBoundsSize } from '../utils.js';
|
|
7
7
|
import { milsToMM } from '../helpers.js';
|
|
8
8
|
import { getPaperSize } from "./PaperSizes.js";
|
|
@@ -19,7 +19,7 @@ function createSvgCanvas() {
|
|
|
19
19
|
applyFontsToSVG(canvas);
|
|
20
20
|
return canvas;
|
|
21
21
|
}
|
|
22
|
-
export function renderSheetsToSVG(sheetFrames, logger, documentVariable) {
|
|
22
|
+
export function renderSheetsToSVG(sheetFrames, logger, documentVariable, styles) {
|
|
23
23
|
const canvas = createSvgCanvas();
|
|
24
24
|
sheetFrames.forEach((sheet, index) => {
|
|
25
25
|
const sheetGroup = canvas.group();
|
|
@@ -81,8 +81,9 @@ export function renderSheetsToSVG(sheetFrames, logger, documentVariable) {
|
|
|
81
81
|
extendGrid,
|
|
82
82
|
style: documentVariable[FrameParamKeys.GridStyle],
|
|
83
83
|
color: documentVariable[FrameParamKeys.GridColor],
|
|
84
|
+
backgroundColor: documentVariable[FrameParamKeys.BackgroundColor],
|
|
84
85
|
};
|
|
85
|
-
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridProperties, logger);
|
|
86
|
+
generateSVGChild(sheetElements, components, wires, junctions, mergedWires, allFrames, textObjects, gridProperties, styles, logger);
|
|
86
87
|
sheetElements.translate(xOffset, yOffset);
|
|
87
88
|
sheetGroup.translate(0, sheetYOffset.toNumber());
|
|
88
89
|
});
|
|
@@ -126,7 +127,7 @@ export function generatePdfOutput(doc, canvas, sheetSize, sheetSizeDefined, zoom
|
|
|
126
127
|
}
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
|
-
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridProperties, logger) {
|
|
130
|
+
function generateSVGChild(canvas, components, wires, junctions, mergedWires, frameObjects, textObjects, gridProperties, styles, logger) {
|
|
130
131
|
const displayWireId = false;
|
|
131
132
|
if (gridProperties.gridBounds === null) {
|
|
132
133
|
logger.add('get grid bounds');
|
|
@@ -180,17 +181,20 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
180
181
|
}
|
|
181
182
|
const mergedWireHighlightGroup = canvas.group();
|
|
182
183
|
const mergedWireGroup = canvas.group();
|
|
184
|
+
styles = styles ?? {};
|
|
185
|
+
const defaultWireColor = styles.wireColor;
|
|
186
|
+
const defaultWireLineWidth = milsToMM(styles.wireWidth).toNumber();
|
|
183
187
|
mergedWires.forEach(tmpItem => {
|
|
184
188
|
const { intersectPoints, net = null, lines = null } = tmpItem;
|
|
185
189
|
let useJunctionColor = ColorScheme.JunctionColor;
|
|
186
|
-
let useColor =
|
|
190
|
+
let useColor = defaultWireColor;
|
|
187
191
|
let useLineWidth = defaultWireLineWidth;
|
|
188
192
|
let displayHighlight = false;
|
|
189
193
|
let displayHighlightColor = null;
|
|
190
194
|
let displayHighlightOpacity = 0.3;
|
|
191
195
|
let displayHighlightWidth = 5 * MilsToMM;
|
|
192
196
|
if (net !== null) {
|
|
193
|
-
useColor = net.color ??
|
|
197
|
+
useColor = net.color ?? defaultWireColor;
|
|
194
198
|
useJunctionColor = net.color ?? ColorScheme.JunctionColor;
|
|
195
199
|
useLineWidth = net.lineWidth ?? defaultWireLineWidth;
|
|
196
200
|
if (net.highlight !== null) {
|
|
@@ -255,25 +259,25 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
255
259
|
frameObjects.forEach(item => {
|
|
256
260
|
const { bounds, borderWidth } = item;
|
|
257
261
|
const { width, height } = getBoundsSize(bounds);
|
|
258
|
-
|
|
262
|
+
const useWidth = roundValue(width).toNumber();
|
|
263
|
+
const useHeight = roundValue(height).toNumber();
|
|
264
|
+
const useBorderWidth = roundValue(borderWidth).toNumber();
|
|
265
|
+
let strokeColor = item.borderColor ?? '#111';
|
|
259
266
|
if (item.frame.frameType === FrameType.Sheet) {
|
|
260
267
|
drawSheetFrameBorder(frameGroup, item);
|
|
261
268
|
}
|
|
262
269
|
else {
|
|
263
|
-
if (
|
|
264
|
-
if (item.renderType === RenderFrameType.
|
|
265
|
-
strokeColor = '#111';
|
|
266
|
-
}
|
|
267
|
-
else if (item.renderType === RenderFrameType.Elements) {
|
|
270
|
+
if (useBorderWidth > 0) {
|
|
271
|
+
if (item.renderType === RenderFrameType.Elements) {
|
|
268
272
|
strokeColor = '#aaa';
|
|
269
273
|
if (!RenderFlags.ShowElementFrames) {
|
|
270
274
|
return;
|
|
271
275
|
}
|
|
272
276
|
}
|
|
273
|
-
const tmpRect = frameGroup.rect(
|
|
277
|
+
const tmpRect = frameGroup.rect(useWidth, useHeight)
|
|
274
278
|
.fill('none')
|
|
275
279
|
.stroke({
|
|
276
|
-
width: milsToMM(
|
|
280
|
+
width: milsToMM(useBorderWidth).toNumber(),
|
|
277
281
|
color: strokeColor
|
|
278
282
|
});
|
|
279
283
|
tmpRect.translate(item.x.toNumber(), item.y.toNumber());
|
|
@@ -293,19 +297,22 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
293
297
|
.stroke('none').fill('red');
|
|
294
298
|
}
|
|
295
299
|
function drawGrid(group, gridProperties, logger) {
|
|
296
|
-
const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000" } = gridProperties;
|
|
300
|
+
const { gridBounds: canvasSize, extendGrid, style: gridStyle = "dots", color: gridColor = "#000", backgroundColor = "", } = gridProperties;
|
|
297
301
|
const gridSize = defaultGridSizeUnits;
|
|
298
|
-
const { xmin, ymin, xmax, ymax } = canvasSize;
|
|
299
302
|
const extraValue = extendGrid ? 1 : 0;
|
|
300
|
-
const
|
|
301
|
-
const
|
|
303
|
+
const xmin = roundValue(canvasSize.xmin);
|
|
304
|
+
const ymin = roundValue(canvasSize.ymin);
|
|
305
|
+
const xmax = roundValue(canvasSize.xmax);
|
|
306
|
+
const ymax = roundValue(canvasSize.ymax);
|
|
307
|
+
const gridStartX = xmin.div(gridSize).floor().sub(extraValue).mul(gridSize);
|
|
308
|
+
const gridStartY = ymin.div(gridSize).floor().sub(extraValue).mul(gridSize);
|
|
302
309
|
const gridEndX = extendGrid
|
|
303
|
-
? (
|
|
304
|
-
:
|
|
310
|
+
? xmax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
311
|
+
: xmax;
|
|
305
312
|
const gridEndY = extendGrid
|
|
306
|
-
? (
|
|
307
|
-
:
|
|
308
|
-
const numCols =
|
|
313
|
+
? ymax.div(gridSize).ceil().add(extraValue).mul(gridSize)
|
|
314
|
+
: ymax;
|
|
315
|
+
const numCols = gridEndX.sub(gridStartX).div(gridSize).floor().toNumber()
|
|
309
316
|
+ (extendGrid ? 1 : 0);
|
|
310
317
|
const originSize = milsToMM(10).toNumber();
|
|
311
318
|
RenderFlags.ShowGridOrigin && group.circle(originSize)
|
|
@@ -321,6 +328,13 @@ function drawGrid(group, gridProperties, logger) {
|
|
|
321
328
|
const startX = gridStartX.add(numericGridSize.mul(i)).toNumber();
|
|
322
329
|
lines.push(`M ${startX} ${startY.toNumber()} L ${startX} ${endY.toNumber()}`);
|
|
323
330
|
}
|
|
331
|
+
if (backgroundColor !== "") {
|
|
332
|
+
const width = gridEndX.sub(gridStartX).roundDp().toNumber();
|
|
333
|
+
const height = gridEndY.sub(gridStartY).roundDp().toNumber();
|
|
334
|
+
group
|
|
335
|
+
.rect(width, height).fill(backgroundColor)
|
|
336
|
+
.translate(gridStartX.toNumber(), gridStartY.toNumber());
|
|
337
|
+
}
|
|
324
338
|
const strokeSize = milsToMM(3);
|
|
325
339
|
group.addClass('grid')
|
|
326
340
|
.path(lines.join(" "))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { prepareFile } from "../helpers.js";
|
|
2
2
|
import { prepareTokens, SemanticTokensVisitor } from "./SemanticTokenVisitor.js";
|
|
3
|
-
import { ParseError } from "../
|
|
3
|
+
import { ParseError } from "../errors.js";
|
|
4
4
|
export async function getSemanticTokens(filePath, scriptData, options) {
|
|
5
5
|
const { parser, lexer, tokens } = prepareFile(scriptData);
|
|
6
6
|
const tree = parser.script();
|
package/dist/esm/sizing.js
CHANGED
|
@@ -16,7 +16,7 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
|
|
|
16
16
|
case VerticalAlign.Top:
|
|
17
17
|
dominantBaseline = VerticalAlignProp.Hanging;
|
|
18
18
|
break;
|
|
19
|
-
case VerticalAlign.
|
|
19
|
+
case VerticalAlign.Center:
|
|
20
20
|
dominantBaseline = VerticalAlignProp.Central;
|
|
21
21
|
break;
|
|
22
22
|
case VerticalAlign.Bottom:
|
|
@@ -28,7 +28,7 @@ export function measureTextSize2(text, fontFamily, fontSize, fontWeight = 'regul
|
|
|
28
28
|
case HorizontalAlign.Left:
|
|
29
29
|
useAnchor = HorizontalAlignProp.Start;
|
|
30
30
|
break;
|
|
31
|
-
case HorizontalAlign.
|
|
31
|
+
case HorizontalAlign.Center:
|
|
32
32
|
useAnchor = HorizontalAlignProp.Middle;
|
|
33
33
|
break;
|
|
34
34
|
case HorizontalAlign.Right:
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ColorScheme, Defaults } from "./globals.js";
|
|
2
|
+
import { FrameParamKeys } from "./objects/Frame.js";
|
|
3
|
+
export class Styles {
|
|
4
|
+
lineColor;
|
|
5
|
+
lineWidth;
|
|
6
|
+
fillColor;
|
|
7
|
+
textColor;
|
|
8
|
+
wireColor;
|
|
9
|
+
wireWidth;
|
|
10
|
+
}
|
|
11
|
+
export function getStylesFromDocument(document) {
|
|
12
|
+
const styles = new Styles();
|
|
13
|
+
styles.lineColor = document[FrameParamKeys.LineColor] ?? ColorScheme.PinLineColor;
|
|
14
|
+
styles.lineWidth = document[FrameParamKeys.LineWidth] ?? Defaults.LineWidth;
|
|
15
|
+
styles.fillColor = document[FrameParamKeys.FillColor];
|
|
16
|
+
styles.textColor = document[FrameParamKeys.TextColor] ?? ColorScheme.PinNameColor;
|
|
17
|
+
styles.wireColor = document[FrameParamKeys.WireColor] ?? ColorScheme.WireColor;
|
|
18
|
+
styles.wireWidth = document[FrameParamKeys.WireWidth] ?? Defaults.WireLineWidth;
|
|
19
|
+
return styles;
|
|
20
|
+
}
|
package/dist/esm/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ParserRuleContext } from "antlr4ng";
|
|
2
1
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
3
2
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
4
3
|
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
5
4
|
import { DeclaredReference, AnyReference } from './objects/types.js';
|
|
5
|
+
import { getLinePositionAsString } from "./errors.js";
|
|
6
|
+
import { roundValue } from "./objects/NumericValue.js";
|
|
6
7
|
export class SimpleStopwatch {
|
|
7
8
|
startTime;
|
|
8
9
|
constructor() {
|
|
@@ -40,14 +41,17 @@ export function resizeToNearestGrid(bounds, gridSize = 20) {
|
|
|
40
41
|
const addXMax = hasRemainder(bounds.xmax, gridSize) === 0 ? 1 : 0;
|
|
41
42
|
const addYMax = hasRemainder(bounds.ymax, gridSize) === 0 ? 1 : 0;
|
|
42
43
|
return {
|
|
43
|
-
xmin: Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize,
|
|
44
|
-
ymin: Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize,
|
|
45
|
-
xmax: Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize,
|
|
46
|
-
ymax: Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize,
|
|
44
|
+
xmin: roundValue(Math.floor((bounds.xmin + addXMin) / gridSize) * gridSize).toNumber(),
|
|
45
|
+
ymin: roundValue(Math.floor((bounds.ymin + addYMin) / gridSize) * gridSize).toNumber(),
|
|
46
|
+
xmax: roundValue(Math.ceil((bounds.xmax + addXMax) / gridSize) * gridSize).toNumber(),
|
|
47
|
+
ymax: roundValue(Math.ceil((bounds.ymax + addYMax) / gridSize) * gridSize).toNumber(),
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
export function toNearestGrid(value, gridSize) {
|
|
50
|
-
return
|
|
51
|
+
return roundValue(value / gridSize).floor().mul(gridSize).toNumber();
|
|
52
|
+
}
|
|
53
|
+
export function toNearestGrid2(value, gridSize) {
|
|
54
|
+
return roundValue(value / gridSize).ceil().mul(gridSize).toNumber();
|
|
51
55
|
}
|
|
52
56
|
export function getBoundsSize(bounds) {
|
|
53
57
|
return {
|
|
@@ -69,18 +73,6 @@ export function getPortType(component) {
|
|
|
69
73
|
});
|
|
70
74
|
return foundPinType;
|
|
71
75
|
}
|
|
72
|
-
export function throwWithContext(context, messageOrError) {
|
|
73
|
-
if (messageOrError instanceof BaseError) {
|
|
74
|
-
throw messageOrError;
|
|
75
|
-
}
|
|
76
|
-
throwWithTokenRange(messageOrError, context.start, context.stop);
|
|
77
|
-
}
|
|
78
|
-
export function throwWithToken(message, token) {
|
|
79
|
-
throw new ParseError(message, token);
|
|
80
|
-
}
|
|
81
|
-
export function throwWithTokenRange(message, startToken, endToken) {
|
|
82
|
-
throw new ParseError(message, startToken, endToken);
|
|
83
|
-
}
|
|
84
76
|
export function combineMaps(map1, map2) {
|
|
85
77
|
const newMap = new Map(map1);
|
|
86
78
|
map2.forEach((value, key) => {
|
|
@@ -174,83 +166,6 @@ export function getBlockTypeString(type) {
|
|
|
174
166
|
}
|
|
175
167
|
return returnValue;
|
|
176
168
|
}
|
|
177
|
-
export class BaseError extends Error {
|
|
178
|
-
name = 'BaseError';
|
|
179
|
-
message;
|
|
180
|
-
startToken;
|
|
181
|
-
endToken;
|
|
182
|
-
filePath;
|
|
183
|
-
constructor(message, startTokenOrCtx, endToken, filePath) {
|
|
184
|
-
super(message);
|
|
185
|
-
this.message = message;
|
|
186
|
-
if (startTokenOrCtx instanceof ParserRuleContext) {
|
|
187
|
-
this.startToken = startTokenOrCtx.start;
|
|
188
|
-
this.endToken = startTokenOrCtx.stop;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
this.startToken = startTokenOrCtx;
|
|
192
|
-
this.endToken = endToken;
|
|
193
|
-
}
|
|
194
|
-
this.filePath = filePath;
|
|
195
|
-
}
|
|
196
|
-
toString() {
|
|
197
|
-
const parts = [this.name];
|
|
198
|
-
const linePosition = getLinePositionAsString({
|
|
199
|
-
start: this.startToken,
|
|
200
|
-
stop: this.endToken
|
|
201
|
-
});
|
|
202
|
-
if (linePosition !== null) {
|
|
203
|
-
parts.push(linePosition);
|
|
204
|
-
}
|
|
205
|
-
parts.push(`: ${this.message}`);
|
|
206
|
-
return parts.join('');
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
export function getLinePositionAsString(ctx) {
|
|
210
|
-
if (ctx === null || ctx === undefined) {
|
|
211
|
-
return null;
|
|
212
|
-
}
|
|
213
|
-
const { start: startToken, stop: stopToken } = ctx;
|
|
214
|
-
let result = null;
|
|
215
|
-
if (startToken) {
|
|
216
|
-
const { line, column } = startToken;
|
|
217
|
-
let stopLine = 0;
|
|
218
|
-
let stopCol = 0;
|
|
219
|
-
if (stopToken && (stopToken.line !== startToken.line || stopToken.column !== startToken.column)) {
|
|
220
|
-
stopLine = stopToken.line;
|
|
221
|
-
stopCol = stopToken.column + (stopToken.stop - stopToken.start);
|
|
222
|
-
}
|
|
223
|
-
else if (startToken === stopToken || startToken) {
|
|
224
|
-
stopLine = line;
|
|
225
|
-
stopCol = column + 1 + (startToken.stop - startToken.start);
|
|
226
|
-
}
|
|
227
|
-
else {
|
|
228
|
-
stopCol = -1;
|
|
229
|
-
}
|
|
230
|
-
result = ` at ${line}:${column + 1}`;
|
|
231
|
-
if (stopCol !== -1) {
|
|
232
|
-
result += `-${stopLine}:${stopCol + 1}`;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return result;
|
|
236
|
-
}
|
|
237
|
-
export class ParseSyntaxError extends BaseError {
|
|
238
|
-
name = 'ParseSyntaxError';
|
|
239
|
-
}
|
|
240
|
-
export class ParseError extends ParseSyntaxError {
|
|
241
|
-
name = 'ParseError';
|
|
242
|
-
}
|
|
243
|
-
export class RuntimeExecutionError extends BaseError {
|
|
244
|
-
name = 'RuntimeExecutionError';
|
|
245
|
-
}
|
|
246
|
-
export class RenderError extends Error {
|
|
247
|
-
stage;
|
|
248
|
-
constructor(message, stage) {
|
|
249
|
-
super(message);
|
|
250
|
-
this.name = 'RenderError';
|
|
251
|
-
this.stage = stage;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
169
|
export function printWarnings(warnings) {
|
|
255
170
|
const warningMessages = [];
|
|
256
171
|
warnings.forEach(item => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { prepareFile, ParseErrorStrategy, TokenErrorListener } from "../helpers.js";
|
|
2
|
-
import { ParseError } from "../
|
|
2
|
+
import { ParseError } from "../errors.js";
|
|
3
3
|
import { SymbolValidatorResolveVisitor } from "./SymbolValidatorResolveVisitor.js";
|
|
4
4
|
import { SymbolValidatorVisitor } from "./SymbolValidatorVisitor.js";
|
|
5
5
|
export async function validateScript(filePath, scriptData, options) {
|
package/dist/esm/visitor.js
CHANGED
|
@@ -10,7 +10,8 @@ import { BlockTypes } from "./objects/BlockTypes.js";
|
|
|
10
10
|
import { unwrapValue } from "./utils.js";
|
|
11
11
|
import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
|
|
12
12
|
import { BaseVisitor } from './BaseVisitor.js';
|
|
13
|
-
import { getPortType
|
|
13
|
+
import { getPortType } from './utils.js';
|
|
14
|
+
import { RuntimeExecutionError } from './errors.js';
|
|
14
15
|
import { UnitDimension } from './helpers.js';
|
|
15
16
|
import { FrameParamKeys } from './objects/Frame.js';
|
|
16
17
|
import { ComponentAnnotater } from './annotate/ComponentAnnotater.js';
|
|
@@ -1024,8 +1025,9 @@ export class ParserVisitor extends BaseVisitor {
|
|
|
1024
1025
|
if (segments.length === 0) {
|
|
1025
1026
|
this.throwWithContext(ctx, "Invalid wire expression");
|
|
1026
1027
|
}
|
|
1027
|
-
const newWire = this.getExecutor().addWire(segments);
|
|
1028
|
+
const newWire = this.getExecutor().addWire(segments, ctx);
|
|
1028
1029
|
this.creationCtx.set(newWire, ctx);
|
|
1030
|
+
this.wireCtxLinks.set(newWire, ctx);
|
|
1029
1031
|
};
|
|
1030
1032
|
visitPoint_expr = (ctx) => {
|
|
1031
1033
|
const ctxDataExpr = ctx.data_expr();
|
package/dist/libs/std.cst
CHANGED
|
@@ -7,7 +7,7 @@ def net(net_name, net_type = "any"):
|
|
|
7
7
|
display: create graphic (params):
|
|
8
8
|
hline: -50, 0, 100
|
|
9
9
|
vpin: 1, 0, 50, -50, display_id=false
|
|
10
|
-
label: params.net_name, 0, -15, fontSize=50, anchor="
|
|
10
|
+
label: params.net_name, 0, -15, fontSize=50, anchor="center"
|
|
11
11
|
type: "net"
|
|
12
12
|
params:
|
|
13
13
|
net_name: net_name
|
|
@@ -24,7 +24,7 @@ def label(value, anchor="left"):
|
|
|
24
24
|
copy: true
|
|
25
25
|
followWireOrientation: false
|
|
26
26
|
display: create graphic (params):
|
|
27
|
-
|
|
27
|
+
text_color: "#222"
|
|
28
28
|
label: params.value, 0, -10, fontSize=50, anchor=anchor
|
|
29
29
|
pin: 1, 0, 0, 0, 0, display_id=false
|
|
30
30
|
type: "net"
|
|
@@ -38,8 +38,8 @@ def port(value, portType="input"):
|
|
|
38
38
|
pins: 1
|
|
39
39
|
copy: true
|
|
40
40
|
display: create graphic (params):
|
|
41
|
-
|
|
42
|
-
label: params.value, 0, 0, fontSize=40, anchor="left", vanchor="
|
|
41
|
+
text_color: "#222"
|
|
42
|
+
label: params.value, 0, 0, fontSize=40, anchor="left", vanchor="center", portType=portType
|
|
43
43
|
pin: 1, 0, 0, 0, 0, display_id=false
|
|
44
44
|
type: "port"
|
|
45
45
|
params:
|
|
@@ -58,7 +58,7 @@ def res(value):
|
|
|
58
58
|
hpin: 1, -width/2 - 30, 0, 30, display_id=false
|
|
59
59
|
hpin: 2, width/2 + 30, 0, -30, display_id=false
|
|
60
60
|
label: params.refdes, -width/2, -height/2 - 20, fontSize=50, anchor="left"
|
|
61
|
-
label: params.value, 0, 0, fontSize=30, anchor="
|
|
61
|
+
label: params.value, 0, 0, fontSize=30, anchor="center", vanchor="center"
|
|
62
62
|
type: "res"
|
|
63
63
|
params:
|
|
64
64
|
value: value
|
|
@@ -73,13 +73,13 @@ def cap(value):
|
|
|
73
73
|
return create component:
|
|
74
74
|
pins: 2
|
|
75
75
|
display: create graphic (params):
|
|
76
|
-
|
|
76
|
+
line_width: 13
|
|
77
77
|
hline: -width/2, 20, width
|
|
78
78
|
hline: -width/2, -20, width
|
|
79
79
|
vpin: 1, 0, -100, 80, display_id=false
|
|
80
80
|
vpin: 2, 0, 100, -80, display_id=false
|
|
81
|
-
label: params.refdes, 80, -30, fontSize=50, anchor="left", vanchor="
|
|
82
|
-
label: params.value, 80, 30, fontSize=50, anchor = "left", vanchor="
|
|
81
|
+
label: params.refdes, 80, -30, fontSize=50, anchor="left", vanchor="center"
|
|
82
|
+
label: params.value, 80, 30, fontSize=50, anchor = "left", vanchor="center"
|
|
83
83
|
type: "cap"
|
|
84
84
|
params:
|
|
85
85
|
value: value
|
|
@@ -101,7 +101,7 @@ def ind(value):
|
|
|
101
101
|
hpin: 1, -width/2 - 100, 0, 100, display_id=false
|
|
102
102
|
hpin: 2, width/2 + 100, 0, -100, display_id=false
|
|
103
103
|
label: (params.refdes, -width/2, -height/2 - 25 , fontSize=50, anchor="left")
|
|
104
|
-
label: (params.value, 0, 50, fontSize=50, anchor="
|
|
104
|
+
label: (params.value, 0, 50, fontSize=50, anchor="center", vanchor="center")
|
|
105
105
|
params:
|
|
106
106
|
value: value
|
|
107
107
|
|
|
@@ -119,7 +119,7 @@ def diode():
|
|
|
119
119
|
vline: width/2, -height/2, height
|
|
120
120
|
hpin: 1, -width/2-100, 0, 100 # cathode
|
|
121
121
|
hpin: 2, width/2 + 100, 0, -100 # anode
|
|
122
|
-
label: params.refdes, 0, -100, fontSize=50, anchor="
|
|
122
|
+
label: params.refdes, 0, -100, fontSize=50, anchor="center", vanchor="top"
|
|
123
123
|
|
|
124
124
|
def led(color):
|
|
125
125
|
width = 100
|
|
@@ -140,8 +140,8 @@ def led(color):
|
|
|
140
140
|
"M", 180, 60, "L", 180, 90, "L", 150, 90)
|
|
141
141
|
hpin: 1, width/2 + 100, 0, -100 # cathode
|
|
142
142
|
hpin: 2, -width/2-100, 0, 100 # anode
|
|
143
|
-
label: params.refdes, 0, -100, fontSize=50, anchor="
|
|
144
|
-
label: params.color, 0, 100, fontSize=40, anchor="
|
|
143
|
+
label: params.refdes, 0, -100, fontSize=50, anchor="center", vanchor="top"
|
|
144
|
+
label: params.color, 0, 100, fontSize=40, anchor="center", vanchor="bottom"
|
|
145
145
|
params:
|
|
146
146
|
size: "0603"
|
|
147
147
|
color: color
|
|
@@ -159,7 +159,7 @@ def cgnd():
|
|
|
159
159
|
hline: -10, 5, 20
|
|
160
160
|
hline: -5, 10, 10
|
|
161
161
|
vpin: 1, 0, -10, 10, display_id=false
|
|
162
|
-
label: params.net_name, 0, 22, fontSize=50, anchor="
|
|
162
|
+
label: params.net_name, 0, 22, fontSize=50, anchor="center"
|
|
163
163
|
type: "net"
|
|
164
164
|
params:
|
|
165
165
|
net_name: net_name
|
|
@@ -175,7 +175,7 @@ def dgnd(net_name="GND"):
|
|
|
175
175
|
display: create graphic (params):
|
|
176
176
|
triangle: 0, 0, 0, height, width
|
|
177
177
|
vpin: 1, 0, -50, 50, display_id=false
|
|
178
|
-
label: params.net_name, 0, height + 50, fontSize=50, anchor="
|
|
178
|
+
label: params.net_name, 0, height + 50, fontSize=50, anchor="center", vanchor="center"
|
|
179
179
|
type: "net"
|
|
180
180
|
params:
|
|
181
181
|
net_name: net_name
|
|
@@ -208,7 +208,7 @@ def arrow_point():
|
|
|
208
208
|
pins: 1
|
|
209
209
|
followWireOrientation: false
|
|
210
210
|
display: create graphic:
|
|
211
|
-
|
|
211
|
+
line_width: 2
|
|
212
212
|
path: ("M", -10, -5, "L", -5, 0, "L", -10, 5)
|
|
213
213
|
path: ("M", -5, 0, "L", -20, 0)
|
|
214
214
|
hpin: 1, 0, 0, 0, display_id=false
|
|
@@ -269,12 +269,12 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
|
|
|
269
269
|
fill: "none"
|
|
270
270
|
|
|
271
271
|
# outer rect
|
|
272
|
-
|
|
272
|
+
line_color: "#cccccc"
|
|
273
273
|
crect: (paper_width/2, paper_height/2,
|
|
274
274
|
paper_width, paper_height, class="paper-area")
|
|
275
275
|
|
|
276
276
|
# inner rect
|
|
277
|
-
|
|
277
|
+
line_color: "#111111"
|
|
278
278
|
crect: (paper_width/2, paper_height/2,
|
|
279
279
|
inner_width, inner_height, class="plot-area")
|
|
280
280
|
|
|
@@ -296,30 +296,30 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
|
|
|
296
296
|
content: i
|
|
297
297
|
offset: tmp_x + tmp_width * ratio_x * (0.5 + (i-1)), tmp_y + inner_frame_margin * 0.5 + 2
|
|
298
298
|
fontSize: fontSize
|
|
299
|
-
anchor: "
|
|
300
|
-
vanchor: "
|
|
299
|
+
anchor: "center"
|
|
300
|
+
vanchor: "center"
|
|
301
301
|
|
|
302
302
|
text:
|
|
303
303
|
content: i
|
|
304
304
|
offset: tmp_x + tmp_width * ratio_x * (0.5 + (i-1)), tmp_y + tmp_height - inner_frame_margin * 0.5 + 2
|
|
305
305
|
fontSize: fontSize
|
|
306
|
-
anchor: "
|
|
307
|
-
vanchor: "
|
|
306
|
+
anchor: "center"
|
|
307
|
+
vanchor: "center"
|
|
308
308
|
|
|
309
309
|
for index, val in enumerate(row_display_value):
|
|
310
310
|
text:
|
|
311
311
|
content: val
|
|
312
312
|
offset: tmp_x + inner_frame_margin * 0.5, tmp_y + tmp_height * ratio_y * (0.5 + index)
|
|
313
313
|
fontSize: fontSize
|
|
314
|
-
anchor: "
|
|
315
|
-
vanchor: "
|
|
314
|
+
anchor: "center"
|
|
315
|
+
vanchor: "center"
|
|
316
316
|
|
|
317
317
|
text:
|
|
318
318
|
content: val
|
|
319
319
|
offset: tmp_x + tmp_width - inner_frame_margin * 0.5, tmp_y + tmp_height * ratio_y * (0.5 + index)
|
|
320
320
|
fontSize: fontSize
|
|
321
|
-
anchor: "
|
|
322
|
-
vanchor: "
|
|
321
|
+
anchor: "center"
|
|
322
|
+
vanchor: "center"
|
|
323
323
|
|
|
324
324
|
# Draw title frame
|
|
325
325
|
text:
|
|
@@ -375,47 +375,47 @@ def sheet_generator(paper_size_name, paper_width, paper_height, margin_x, margin
|
|
|
375
375
|
grid_height: paper_height - 2 * margin_y
|
|
376
376
|
|
|
377
377
|
def sheet_A1():
|
|
378
|
-
paper_width =
|
|
379
|
-
paper_height =
|
|
378
|
+
paper_width = to_mils(841)
|
|
379
|
+
paper_height = to_mils(594)
|
|
380
380
|
margin = 400
|
|
381
381
|
|
|
382
382
|
return sheet_generator("A1", paper_width, paper_height, margin, margin,
|
|
383
383
|
range(1, 17), ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"])
|
|
384
384
|
|
|
385
385
|
def sheet_A2():
|
|
386
|
-
paper_width =
|
|
387
|
-
paper_height =
|
|
386
|
+
paper_width = to_mils(594)
|
|
387
|
+
paper_height = to_mils(420)
|
|
388
388
|
margin = 400
|
|
389
389
|
|
|
390
390
|
return sheet_generator("A2", paper_width, paper_height, margin, margin,
|
|
391
391
|
range(1, 13), ["A", "B", "C", "D", "E", "F", "G", "H"])
|
|
392
392
|
|
|
393
393
|
def sheet_A3():
|
|
394
|
-
paper_width =
|
|
395
|
-
paper_height =
|
|
394
|
+
paper_width = to_mils(420)
|
|
395
|
+
paper_height = to_mils(297)
|
|
396
396
|
margin = 400
|
|
397
397
|
|
|
398
398
|
return sheet_generator("A3", paper_width, paper_height, margin, margin,
|
|
399
399
|
range(1, 9), ["A", "B", "C", "D", "E", "F"])
|
|
400
400
|
|
|
401
401
|
def sheet_A4():
|
|
402
|
-
paper_width =
|
|
403
|
-
paper_height =
|
|
402
|
+
paper_width = to_mils(297)
|
|
403
|
+
paper_height = to_mils(210)
|
|
404
404
|
margin = 400
|
|
405
405
|
|
|
406
406
|
return sheet_generator("A4", paper_width, paper_height, margin, margin,
|
|
407
407
|
range(1, 7), ["A", "B", "C", "D"])
|
|
408
408
|
|
|
409
409
|
def sheet_A5():
|
|
410
|
-
paper_width =
|
|
411
|
-
paper_height =
|
|
410
|
+
paper_width = to_mils(210)
|
|
411
|
+
paper_height = to_mils(148)
|
|
412
412
|
margin = 400
|
|
413
413
|
|
|
414
414
|
return sheet_generator("A5", paper_width, paper_height, margin, margin, range(1, 5), ["A", "B", "C"])
|
|
415
415
|
|
|
416
416
|
def sheet_A6(revision="V1"):
|
|
417
|
-
paper_width =
|
|
418
|
-
paper_height =
|
|
417
|
+
paper_width = to_mils(148)
|
|
418
|
+
paper_height = to_mils(105)
|
|
419
419
|
margin = 400
|
|
420
420
|
|
|
421
421
|
tmp_sheet = sheet_generator("A6", paper_width, paper_height, margin, margin, range(1, 4), ["A", "B"])
|
|
@@ -7,10 +7,11 @@ import { Net } from "./objects/Net.js";
|
|
|
7
7
|
import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference, ImportedLibrary, NewContextOptions, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
8
8
|
import { CommonTokenStream, ParserRuleContext } from 'antlr4ng';
|
|
9
9
|
import { ExecutionWarning } from "./utils.js";
|
|
10
|
-
import { BaseError } from './
|
|
10
|
+
import { BaseError } from './errors.js';
|
|
11
11
|
import { ExecutionScope } from './objects/ExecutionScope.js';
|
|
12
12
|
import { NodeScriptEnvironment } from "./environment/environment.js";
|
|
13
13
|
import { PinId } from './objects/PinDefinition.js';
|
|
14
|
+
import { Wire } from './objects/Wire.js';
|
|
14
15
|
export declare class BaseVisitor extends CircuitScriptParserVisitor<ComplexType | AnyReference | any> {
|
|
15
16
|
startingContext: ExecutionContext;
|
|
16
17
|
executionStack: ExecutionContext[];
|
|
@@ -23,6 +24,7 @@ export declare class BaseVisitor extends CircuitScriptParserVisitor<ComplexType
|
|
|
23
24
|
acceptedDirections: Direction[];
|
|
24
25
|
protected resultData: Map<ParserRuleContext, any>;
|
|
25
26
|
protected componentCtxLinks: Map<ParserRuleContext, ClassComponent>;
|
|
27
|
+
wireCtxLinks: Map<Wire, ParserRuleContext>;
|
|
26
28
|
onErrorHandler: OnErrorHandler | null;
|
|
27
29
|
environment: NodeScriptEnvironment;
|
|
28
30
|
protected importedFiles: ImportLibraryFile[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Token, ParserRuleContext } from "antlr4ng";
|
|
2
|
+
import { Wire } from "./objects/Wire.js";
|
|
3
|
+
export declare class BaseError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
message: string;
|
|
6
|
+
startToken?: Token;
|
|
7
|
+
endToken?: Token;
|
|
8
|
+
filePath?: string;
|
|
9
|
+
constructor(message: string, startTokenOrCtx?: Token | ParserRuleContext, endToken?: Token, filePath?: string, options?: ErrorOptions);
|
|
10
|
+
toString(): string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getLinePositionAsString(ctx: ParserRuleContext): string | null;
|
|
13
|
+
export declare function throwWithContext(context: ParserRuleContext, messageOrError: string | BaseError): void;
|
|
14
|
+
export declare function throwWithTokenRange(message: string, startToken: Token, endToken?: Token): void;
|
|
15
|
+
export declare class RenderError extends Error {
|
|
16
|
+
stage?: string;
|
|
17
|
+
constructor(message: string, stage?: string, options?: ErrorOptions);
|
|
18
|
+
}
|
|
19
|
+
export declare class AutoWireFailedError_ extends Error {
|
|
20
|
+
name: string;
|
|
21
|
+
wire: Wire;
|
|
22
|
+
constructor(message: string, wire: Wire);
|
|
23
|
+
}
|
|
24
|
+
export declare class AutoWireFailedError extends BaseError {
|
|
25
|
+
name: string;
|
|
26
|
+
}
|
|
27
|
+
export declare class RuntimeExecutionError extends BaseError {
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class ParseSyntaxError extends BaseError {
|
|
31
|
+
name: string;
|
|
32
|
+
}
|
|
33
|
+
export declare class ParseError extends ParseSyntaxError {
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function collectErrorChain(error: Error): Error[];
|
|
37
|
+
export declare function printErrorChain(error: Error): void;
|
package/dist/types/execute.d.ts
CHANGED
|
@@ -92,7 +92,7 @@ export declare class ExecutionContext {
|
|
|
92
92
|
resolveTrailers(type: ReferenceTypes, item: any, trailers?: string[]): AnyReference;
|
|
93
93
|
callFunction(functionReference: AnyReference, functionParams: CallableParameter[], executionStack: ExecutionContext[], netNamespace: string): CFunctionResult;
|
|
94
94
|
mergeScope(childScope: ExecutionScope, namespace: string): ClassComponent[];
|
|
95
|
-
addWire(segments: [string, (number | UnitDimension)?][]): Wire;
|
|
95
|
+
addWire(segments: [string, (number | UnitDimension)?][], ctx: ParserRuleContext): Wire;
|
|
96
96
|
addPoint(pointId: string, userDefined?: boolean): ComponentPin;
|
|
97
97
|
private getPointSymbol;
|
|
98
98
|
applyComponentAngleFromWire(component: ClassComponent, pin: number, opposite?: boolean): void;
|