circuitscript 0.4.0 → 0.5.0
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 +16 -10
- package/dist/cjs/BomGeneration.js +3 -3
- package/dist/cjs/ComponentMatchConditions.js +2 -2
- package/dist/cjs/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/cjs/builtinMethods.js +10 -10
- package/dist/cjs/execute.js +25 -23
- package/dist/cjs/globals.js +7 -14
- package/dist/cjs/helpers.js +4 -3
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/lexer.js +8 -4
- package/dist/cjs/objects/BlockTypes.js +10 -0
- package/dist/cjs/objects/NumericValue.js +196 -0
- package/dist/cjs/objects/ParamDefinition.js +1 -149
- package/dist/cjs/objects/PercentageValue.js +15 -0
- package/dist/cjs/objects/PinDefinition.js +2 -2
- package/dist/cjs/objects/WrappedNumber.js +15 -0
- package/dist/cjs/pipeline.js +2 -2
- package/dist/cjs/render/draw_symbols.js +78 -78
- package/dist/cjs/render/export.js +2 -2
- package/dist/cjs/render/geometry.js +11 -12
- package/dist/cjs/render/graph.js +2 -2
- package/dist/cjs/render/layout.js +46 -46
- package/dist/cjs/render/render.js +19 -19
- package/dist/cjs/semantic-tokens/SemanticTokenVisitor.js +59 -59
- package/dist/cjs/utils.js +21 -83
- package/dist/cjs/visitor.js +45 -31
- package/dist/esm/BaseVisitor.js +8 -2
- package/dist/esm/BomGeneration.js +1 -1
- package/dist/esm/ComponentMatchConditions.js +1 -1
- package/dist/esm/annotate/RefdesAnnotationVisitor.js +4 -0
- package/dist/esm/builtinMethods.js +2 -2
- package/dist/esm/execute.js +4 -2
- package/dist/esm/globals.js +1 -8
- package/dist/esm/helpers.js +3 -2
- package/dist/esm/index.js +6 -2
- package/dist/esm/lexer.js +8 -4
- package/dist/esm/objects/BlockTypes.js +7 -0
- package/dist/esm/objects/NumericValue.js +189 -0
- package/dist/esm/objects/ParamDefinition.js +0 -148
- package/dist/esm/objects/PercentageValue.js +12 -0
- package/dist/esm/objects/PinDefinition.js +1 -1
- package/dist/esm/objects/WrappedNumber.js +12 -0
- package/dist/esm/pipeline.js +2 -2
- package/dist/esm/render/draw_symbols.js +2 -2
- package/dist/esm/render/export.js +1 -1
- package/dist/esm/render/geometry.js +1 -2
- package/dist/esm/render/graph.js +1 -1
- package/dist/esm/render/layout.js +2 -2
- package/dist/esm/render/render.js +1 -1
- package/dist/esm/semantic-tokens/SemanticTokenVisitor.js +58 -58
- package/dist/esm/utils.js +16 -74
- package/dist/esm/visitor.js +17 -3
- package/dist/types/ComponentMatchConditions.d.ts +1 -1
- package/dist/types/annotate/RefdesAnnotationVisitor.d.ts +3 -1
- package/dist/types/execute.d.ts +4 -2
- package/dist/types/globals.d.ts +1 -7
- package/dist/types/helpers.d.ts +2 -2
- package/dist/types/index.d.ts +6 -2
- package/dist/types/lexer.d.ts +1 -0
- package/dist/types/objects/BlockTypes.d.ts +6 -0
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +2 -1
- package/dist/types/objects/NumericValue.d.ts +35 -0
- package/dist/types/objects/ParamDefinition.d.ts +0 -41
- package/dist/types/objects/PercentageValue.d.ts +6 -0
- package/dist/types/objects/PinDefinition.d.ts +1 -1
- package/dist/types/objects/WrappedNumber.d.ts +6 -0
- package/dist/types/objects/types.d.ts +2 -1
- package/dist/types/render/draw_symbols.d.ts +1 -1
- package/dist/types/render/geometry.d.ts +1 -1
- package/dist/types/render/layout.d.ts +1 -1
- package/dist/types/semantic-tokens/SemanticTokenVisitor.d.ts +3 -4
- package/dist/types/utils.d.ts +1 -7
- package/package.json +1 -1
package/dist/cjs/utils.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isReference = exports.unwrapValue = exports.printWarnings = exports.RenderError = exports.RuntimeExecutionError = exports.ParseError = exports.ParseSyntaxError = exports.getLinePositionAsString = exports.BaseError = exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.
|
|
4
|
-
const big_js_1 = require("big.js");
|
|
3
|
+
exports.isReference = exports.unwrapValue = exports.printWarnings = exports.RenderError = exports.RuntimeExecutionError = exports.ParseError = exports.ParseSyntaxError = exports.getLinePositionAsString = exports.BaseError = exports.getBlockTypeString = exports.generateDebugSequenceAction = exports.sequenceActionString = exports.areasOverlap = exports.isPointWithinArea = exports.combineMaps = exports.throwWithTokenRange = exports.throwWithToken = exports.throwWithContext = exports.getPortType = exports.getBoundsSize = exports.toNearestGrid = exports.resizeToNearestGrid = exports.printBounds = exports.resizeBounds = exports.SimpleStopwatch = void 0;
|
|
5
4
|
const antlr4ng_1 = require("antlr4ng");
|
|
6
5
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
7
|
-
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
8
6
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
9
|
-
const
|
|
7
|
+
const BlockTypes_js_1 = require("./objects/BlockTypes.js");
|
|
10
8
|
const types_js_1 = require("./objects/types.js");
|
|
11
9
|
class SimpleStopwatch {
|
|
12
10
|
constructor() {
|
|
@@ -80,10 +78,6 @@ function getPortType(component) {
|
|
|
80
78
|
return foundPinType;
|
|
81
79
|
}
|
|
82
80
|
exports.getPortType = getPortType;
|
|
83
|
-
function roundValue(value) {
|
|
84
|
-
return resolveToNumericValue(new big_js_1.Big(value.toBigNumber().toFixed(7)));
|
|
85
|
-
}
|
|
86
|
-
exports.roundValue = roundValue;
|
|
87
81
|
function throwWithContext(context, messageOrError) {
|
|
88
82
|
if (messageOrError instanceof BaseError) {
|
|
89
83
|
throw messageOrError;
|
|
@@ -107,70 +101,6 @@ function combineMaps(map1, map2) {
|
|
|
107
101
|
return newMap;
|
|
108
102
|
}
|
|
109
103
|
exports.combineMaps = combineMaps;
|
|
110
|
-
function getNumberExponential(value) {
|
|
111
|
-
value = value.trim();
|
|
112
|
-
switch (value) {
|
|
113
|
-
case 'G':
|
|
114
|
-
return 9;
|
|
115
|
-
case 'M':
|
|
116
|
-
return 6;
|
|
117
|
-
case 'k':
|
|
118
|
-
case 'K':
|
|
119
|
-
return 3;
|
|
120
|
-
case 'm':
|
|
121
|
-
return -3;
|
|
122
|
-
case 'u':
|
|
123
|
-
return -6;
|
|
124
|
-
case 'n':
|
|
125
|
-
return -9;
|
|
126
|
-
case 'p':
|
|
127
|
-
return -12;
|
|
128
|
-
case 'f':
|
|
129
|
-
return -15;
|
|
130
|
-
default:
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.getNumberExponential = getNumberExponential;
|
|
135
|
-
function getNumberExponentialText(value) {
|
|
136
|
-
switch (value) {
|
|
137
|
-
case -15:
|
|
138
|
-
return 'f';
|
|
139
|
-
case -12:
|
|
140
|
-
return 'p';
|
|
141
|
-
case -9:
|
|
142
|
-
return 'n';
|
|
143
|
-
case -6:
|
|
144
|
-
return 'u';
|
|
145
|
-
case -3:
|
|
146
|
-
return 'm';
|
|
147
|
-
case 3:
|
|
148
|
-
return 'k';
|
|
149
|
-
case 6:
|
|
150
|
-
return 'M';
|
|
151
|
-
case 9:
|
|
152
|
-
return 'G';
|
|
153
|
-
case 0:
|
|
154
|
-
default:
|
|
155
|
-
return '';
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.getNumberExponentialText = getNumberExponentialText;
|
|
159
|
-
function resolveToNumericValue(value) {
|
|
160
|
-
if (value.toNumber() === 0) {
|
|
161
|
-
return new ParamDefinition_js_1.NumericValue(0);
|
|
162
|
-
}
|
|
163
|
-
const isNeg = value.lt(0);
|
|
164
|
-
const positiveValue = isNeg ? value.neg() : value;
|
|
165
|
-
const prefixPart = Math.floor(Math.log10(positiveValue.toNumber()) / 3);
|
|
166
|
-
let useValue = value;
|
|
167
|
-
if (prefixPart !== 0) {
|
|
168
|
-
const tmpValue1 = positiveValue.div(Math.pow(10, prefixPart * 3));
|
|
169
|
-
useValue = isNeg ? tmpValue1.neg() : tmpValue1;
|
|
170
|
-
}
|
|
171
|
-
return new ParamDefinition_js_1.NumericValue(useValue, prefixPart * 3);
|
|
172
|
-
}
|
|
173
|
-
exports.resolveToNumericValue = resolveToNumericValue;
|
|
174
104
|
function isPointWithinArea(point, bounds) {
|
|
175
105
|
const [xPt, yPt] = point;
|
|
176
106
|
const [xmin, ymin, xmax, ymax] = bounds;
|
|
@@ -246,16 +176,16 @@ exports.generateDebugSequenceAction = generateDebugSequenceAction;
|
|
|
246
176
|
function getBlockTypeString(type) {
|
|
247
177
|
let returnValue = 'branch';
|
|
248
178
|
switch (type) {
|
|
249
|
-
case
|
|
179
|
+
case BlockTypes_js_1.BlockTypes.Branch:
|
|
250
180
|
returnValue = 'branch';
|
|
251
181
|
break;
|
|
252
|
-
case
|
|
182
|
+
case BlockTypes_js_1.BlockTypes.Join:
|
|
253
183
|
returnValue = 'join';
|
|
254
184
|
break;
|
|
255
|
-
case
|
|
185
|
+
case BlockTypes_js_1.BlockTypes.Parallel:
|
|
256
186
|
returnValue = 'parallel';
|
|
257
187
|
break;
|
|
258
|
-
case
|
|
188
|
+
case BlockTypes_js_1.BlockTypes.Point:
|
|
259
189
|
returnValue = 'point';
|
|
260
190
|
break;
|
|
261
191
|
}
|
|
@@ -295,18 +225,26 @@ function getLinePositionAsString(ctx) {
|
|
|
295
225
|
if (ctx === null || ctx === undefined) {
|
|
296
226
|
return null;
|
|
297
227
|
}
|
|
298
|
-
const startToken = ctx
|
|
299
|
-
const endToken = ctx.stop;
|
|
228
|
+
const { start: startToken, stop: stopToken } = ctx;
|
|
300
229
|
let result = null;
|
|
301
230
|
if (startToken) {
|
|
302
231
|
const { line, column } = startToken;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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);
|
|
307
241
|
}
|
|
308
242
|
else {
|
|
309
|
-
|
|
243
|
+
stopCol = -1;
|
|
244
|
+
}
|
|
245
|
+
result = ` at ${line}:${column + 1}`;
|
|
246
|
+
if (stopCol !== -1) {
|
|
247
|
+
result += `-${stopLine}:${stopCol + 1}`;
|
|
310
248
|
}
|
|
311
249
|
}
|
|
312
250
|
return result;
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VisitorExecutionException = exports.ComponentRefDesPrefixes = exports.ParserVisitor = void 0;
|
|
4
4
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
5
|
+
const NumericValue_js_1 = require("./objects/NumericValue.js");
|
|
5
6
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
7
|
+
const NumericValue_js_2 = require("./objects/NumericValue.js");
|
|
6
8
|
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
7
9
|
const PinTypes_js_1 = require("./objects/PinTypes.js");
|
|
8
10
|
const types_js_1 = require("./objects/types.js");
|
|
9
11
|
const globals_js_1 = require("./globals.js");
|
|
12
|
+
const BlockTypes_js_1 = require("./objects/BlockTypes.js");
|
|
10
13
|
const utils_js_1 = require("./utils.js");
|
|
11
14
|
const draw_symbols_js_1 = require("./render/draw_symbols.js");
|
|
12
15
|
const BaseVisitor_js_1 = require("./BaseVisitor.js");
|
|
@@ -25,7 +28,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
25
28
|
const ctxData = ctx.data_expr();
|
|
26
29
|
const result = this.visitResult(ctxData);
|
|
27
30
|
let pinValue;
|
|
28
|
-
if (result instanceof
|
|
31
|
+
if (result instanceof NumericValue_js_1.NumericValue) {
|
|
29
32
|
pinValue = result.toNumber();
|
|
30
33
|
}
|
|
31
34
|
else if (typeof result === 'string') {
|
|
@@ -117,18 +120,18 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
117
120
|
this.setResult(ctx, componentPin);
|
|
118
121
|
};
|
|
119
122
|
this.visitPath_block = (ctx) => {
|
|
120
|
-
let blockType =
|
|
123
|
+
let blockType = BlockTypes_js_1.BlockTypes.Branch;
|
|
121
124
|
if (ctx.Branch()) {
|
|
122
|
-
blockType =
|
|
125
|
+
blockType = BlockTypes_js_1.BlockTypes.Branch;
|
|
123
126
|
}
|
|
124
127
|
else if (ctx.Join()) {
|
|
125
|
-
blockType =
|
|
128
|
+
blockType = BlockTypes_js_1.BlockTypes.Join;
|
|
126
129
|
}
|
|
127
130
|
else if (ctx.Parallel()) {
|
|
128
|
-
blockType =
|
|
131
|
+
blockType = BlockTypes_js_1.BlockTypes.Parallel;
|
|
129
132
|
}
|
|
130
133
|
else if (ctx.Point()) {
|
|
131
|
-
blockType =
|
|
134
|
+
blockType = BlockTypes_js_1.BlockTypes.Point;
|
|
132
135
|
}
|
|
133
136
|
const scope = this.getScope();
|
|
134
137
|
const executor = this.getExecutor();
|
|
@@ -185,7 +188,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
185
188
|
const firstParam = params[0];
|
|
186
189
|
const paramValue = firstParam.paramValue;
|
|
187
190
|
let appendValue = paramValue.toString();
|
|
188
|
-
if (paramValue instanceof
|
|
191
|
+
if (paramValue instanceof NumericValue_js_1.NumericValue) {
|
|
189
192
|
appendValue = paramValue.value;
|
|
190
193
|
}
|
|
191
194
|
instanceName += `${globals_js_1.Delimiter1}${appendValue}`;
|
|
@@ -472,7 +475,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
472
475
|
}
|
|
473
476
|
dataResult = (0, utils_js_1.unwrapValue)(dataResult);
|
|
474
477
|
if (dataResult === null || dataResult === undefined) {
|
|
475
|
-
|
|
478
|
+
if (componentCtx) {
|
|
479
|
+
this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
this.throwWithContext(ctx, "Failed to parse");
|
|
483
|
+
}
|
|
476
484
|
}
|
|
477
485
|
if (dataResult instanceof ClassComponent_js_1.ClassComponent
|
|
478
486
|
&& dataResult.copyProp) {
|
|
@@ -490,11 +498,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
490
498
|
if (modifierText === globals_js_1.ParamKeys.flip) {
|
|
491
499
|
const flipValue = result.name;
|
|
492
500
|
if (flipValue.indexOf('x') !== -1) {
|
|
493
|
-
defaultUnit.setParam(globals_js_1.ParamKeys.flipX, (0,
|
|
501
|
+
defaultUnit.setParam(globals_js_1.ParamKeys.flipX, (0, NumericValue_js_2.numeric)(1));
|
|
494
502
|
shouldIgnoreWireOrientation = true;
|
|
495
503
|
}
|
|
496
504
|
if (flipValue.indexOf('y') !== -1) {
|
|
497
|
-
defaultUnit.setParam(globals_js_1.ParamKeys.flipY, (0,
|
|
505
|
+
defaultUnit.setParam(globals_js_1.ParamKeys.flipY, (0, NumericValue_js_2.numeric)(1));
|
|
498
506
|
shouldIgnoreWireOrientation = true;
|
|
499
507
|
}
|
|
500
508
|
}
|
|
@@ -532,7 +540,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
532
540
|
if (typeof value === "boolean") {
|
|
533
541
|
value = !value;
|
|
534
542
|
}
|
|
535
|
-
else if (value instanceof
|
|
543
|
+
else if (value instanceof NumericValue_js_1.NumericValue) {
|
|
536
544
|
value = (value.toNumber() === 0) ? true : false;
|
|
537
545
|
}
|
|
538
546
|
else {
|
|
@@ -540,7 +548,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
540
548
|
}
|
|
541
549
|
}
|
|
542
550
|
else if (ctx.Minus()) {
|
|
543
|
-
if (value instanceof
|
|
551
|
+
if (value instanceof NumericValue_js_1.NumericValue) {
|
|
544
552
|
value = value.neg();
|
|
545
553
|
}
|
|
546
554
|
else {
|
|
@@ -577,10 +585,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
577
585
|
const ctx1 = ctx.data_expr(1);
|
|
578
586
|
let value1 = this.visitResult(ctx0);
|
|
579
587
|
let value2 = this.visitResult(ctx1);
|
|
580
|
-
if (value1 instanceof
|
|
588
|
+
if (value1 instanceof NumericValue_js_1.NumericValue) {
|
|
581
589
|
value1 = value1.toNumber();
|
|
582
590
|
}
|
|
583
|
-
if (value2 instanceof
|
|
591
|
+
if (value2 instanceof NumericValue_js_1.NumericValue) {
|
|
584
592
|
value2 = value2.toNumber();
|
|
585
593
|
}
|
|
586
594
|
let result = null;
|
|
@@ -608,7 +616,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
608
616
|
const ctx0 = ctx.data_expr(0);
|
|
609
617
|
const ctx1 = ctx.data_expr(1);
|
|
610
618
|
let value1 = this.visitResult(ctx0);
|
|
611
|
-
if (value1 instanceof
|
|
619
|
+
if (value1 instanceof NumericValue_js_1.NumericValue) {
|
|
612
620
|
value1 = value1.toNumber();
|
|
613
621
|
}
|
|
614
622
|
let value2 = false;
|
|
@@ -619,7 +627,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
619
627
|
}
|
|
620
628
|
if (!skipNext) {
|
|
621
629
|
value2 = this.visitResult(ctx1);
|
|
622
|
-
if (value2 instanceof
|
|
630
|
+
if (value2 instanceof NumericValue_js_1.NumericValue) {
|
|
623
631
|
value2 = value2.toNumber();
|
|
624
632
|
}
|
|
625
633
|
}
|
|
@@ -631,14 +639,14 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
631
639
|
result = value1 || value2;
|
|
632
640
|
}
|
|
633
641
|
if (typeof result === "number") {
|
|
634
|
-
result = (0,
|
|
642
|
+
result = (0, NumericValue_js_2.numeric)(result);
|
|
635
643
|
}
|
|
636
644
|
this.setResult(ctx, result);
|
|
637
645
|
};
|
|
638
646
|
this.visitMultiplyExpr = (ctx) => {
|
|
639
647
|
const value1 = this.resolveDataExpr(ctx.data_expr(0));
|
|
640
648
|
const value2 = this.resolveDataExpr(ctx.data_expr(1));
|
|
641
|
-
const operator = new
|
|
649
|
+
const operator = new NumericValue_js_1.NumberOperator();
|
|
642
650
|
const tmpValue1 = operator.prepare(value1);
|
|
643
651
|
const tmpValue2 = operator.prepare(value2);
|
|
644
652
|
let result = null;
|
|
@@ -658,18 +666,18 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
658
666
|
const value2 = (0, utils_js_1.unwrapValue)(this.resolveDataExpr(ctx.data_expr(1)));
|
|
659
667
|
if (ctx.Addition() && (typeof value1 === 'string' || typeof value2 === 'string')) {
|
|
660
668
|
let tmpValue1 = value1;
|
|
661
|
-
if (value1 instanceof
|
|
669
|
+
if (value1 instanceof NumericValue_js_1.NumericValue) {
|
|
662
670
|
tmpValue1 = value1.toDisplayString();
|
|
663
671
|
}
|
|
664
672
|
let tmpValue2 = value2;
|
|
665
|
-
if (value2 instanceof
|
|
673
|
+
if (value2 instanceof NumericValue_js_1.NumericValue) {
|
|
666
674
|
tmpValue2 = value2.toDisplayString();
|
|
667
675
|
}
|
|
668
676
|
const result = tmpValue1 + tmpValue2;
|
|
669
677
|
this.setResult(ctx, result);
|
|
670
678
|
}
|
|
671
679
|
else {
|
|
672
|
-
const operator = new
|
|
680
|
+
const operator = new NumericValue_js_1.NumberOperator();
|
|
673
681
|
const tmpValue1 = operator.prepare(value1);
|
|
674
682
|
const tmpValue2 = operator.prepare(value2);
|
|
675
683
|
let result = null;
|
|
@@ -765,12 +773,18 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
765
773
|
else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
|
|
766
774
|
let useValue = null;
|
|
767
775
|
useValue = this.visitResult(ctxDataExpr);
|
|
768
|
-
if (useValue instanceof
|
|
776
|
+
if (useValue instanceof NumericValue_js_1.NumericValue) {
|
|
769
777
|
useValue = useValue.toNumber();
|
|
770
778
|
}
|
|
771
779
|
segments.push([value, new helpers_js_1.UnitDimension(useValue)]);
|
|
772
780
|
}
|
|
781
|
+
else {
|
|
782
|
+
this.throwWithContext(ctx, "Invalid wire expression");
|
|
783
|
+
}
|
|
773
784
|
});
|
|
785
|
+
if (segments.length === 0) {
|
|
786
|
+
this.throwWithContext(ctx, "Invalid wire expression");
|
|
787
|
+
}
|
|
774
788
|
const newWire = this.getExecutor().addWire(segments);
|
|
775
789
|
this.creationCtx.set(newWire, ctx);
|
|
776
790
|
};
|
|
@@ -993,7 +1007,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
993
1007
|
}
|
|
994
1008
|
else if (ctxNumericValue) {
|
|
995
1009
|
useType = 'NUMERIC_VALUE';
|
|
996
|
-
useValue = (0,
|
|
1010
|
+
useValue = (0, NumericValue_js_2.numeric)(ctxNumericValue.getText());
|
|
997
1011
|
}
|
|
998
1012
|
else if (ctxStringValue) {
|
|
999
1013
|
useType = 'STRING_VALUE';
|
|
@@ -1180,7 +1194,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1180
1194
|
}
|
|
1181
1195
|
break;
|
|
1182
1196
|
case 'copy':
|
|
1183
|
-
if (value instanceof
|
|
1197
|
+
if (value instanceof NumericValue_js_1.NumericValue) {
|
|
1184
1198
|
this.validateNumeric(value, ctx);
|
|
1185
1199
|
}
|
|
1186
1200
|
else if (typeof value === 'boolean') {
|
|
@@ -1200,24 +1214,24 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1200
1214
|
throw new utils_js_2.RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx);
|
|
1201
1215
|
}
|
|
1202
1216
|
else {
|
|
1203
|
-
if (path.length === 2 && value instanceof
|
|
1217
|
+
if (path.length === 2 && value instanceof NumericValue_js_1.NumericValue) {
|
|
1204
1218
|
checkPinExistsAndNotDuplicated(value.toNumber(), ctx);
|
|
1205
1219
|
}
|
|
1206
1220
|
else if (path.length > 2 && path[2][0] === 'index') {
|
|
1207
1221
|
if (Array.isArray(value)) {
|
|
1208
1222
|
const goodBlank = value.length === 1 &&
|
|
1209
|
-
value[0] instanceof
|
|
1223
|
+
value[0] instanceof NumericValue_js_1.NumericValue;
|
|
1210
1224
|
if (!goodBlank) {
|
|
1211
1225
|
throw new utils_js_2.RuntimeExecutionError(`Invalid blank specifier`, ctx);
|
|
1212
1226
|
}
|
|
1213
1227
|
}
|
|
1214
1228
|
else {
|
|
1215
|
-
if (!(value instanceof
|
|
1229
|
+
if (!(value instanceof NumericValue_js_1.NumericValue) && !(typeof value === 'string')) {
|
|
1216
1230
|
throw new utils_js_2.RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx);
|
|
1217
1231
|
}
|
|
1218
1232
|
else {
|
|
1219
1233
|
let useValue;
|
|
1220
|
-
if (value instanceof
|
|
1234
|
+
if (value instanceof NumericValue_js_1.NumericValue) {
|
|
1221
1235
|
useValue = value.toNumber();
|
|
1222
1236
|
}
|
|
1223
1237
|
else if (typeof value === 'string') {
|
|
@@ -1365,7 +1379,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1365
1379
|
}
|
|
1366
1380
|
resolveDataValue(reference) {
|
|
1367
1381
|
const { value } = reference;
|
|
1368
|
-
if (value instanceof
|
|
1382
|
+
if (value instanceof NumericValue_js_1.NumericValue) {
|
|
1369
1383
|
return value.toDisplayString();
|
|
1370
1384
|
}
|
|
1371
1385
|
else {
|
|
@@ -1374,12 +1388,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
1374
1388
|
}
|
|
1375
1389
|
extractPinDefintion(pinData, lastNumericPinId = 0) {
|
|
1376
1390
|
const pins = [];
|
|
1377
|
-
if (pinData instanceof
|
|
1391
|
+
if (pinData instanceof NumericValue_js_1.NumericValue) {
|
|
1378
1392
|
const tmpMap = new Map();
|
|
1379
1393
|
const lastPin = pinData.toNumber();
|
|
1380
1394
|
for (let i = 0; i < lastPin; i++) {
|
|
1381
1395
|
const pinId = lastNumericPinId + i + 1;
|
|
1382
|
-
tmpMap.set(pinId, (0,
|
|
1396
|
+
tmpMap.set(pinId, (0, NumericValue_js_2.numeric)(pinId));
|
|
1383
1397
|
}
|
|
1384
1398
|
pinData = tmpMap;
|
|
1385
1399
|
}
|
package/dist/esm/BaseVisitor.js
CHANGED
|
@@ -4,12 +4,13 @@ import { CircuitScriptParserVisitor } from "./antlr/CircuitScriptParserVisitor.j
|
|
|
4
4
|
import { ExecutionContext } from "./execute.js";
|
|
5
5
|
import { Logger } from "./logger.js";
|
|
6
6
|
import { ClassComponent } from "./objects/ClassComponent.js";
|
|
7
|
-
import { NumberOperator, NumericValue,
|
|
7
|
+
import { NumberOperator, NumericValue, resolveToNumericValue } from "./objects/NumericValue.js";
|
|
8
|
+
import { PercentageValue } from "./objects/PercentageValue.js";
|
|
8
9
|
import { Direction, AnyReference, UndeclaredReference, ImportedLibrary, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
|
|
9
10
|
import { BaseNamespace, ComponentTypes, DoubleDelimiter1, GlobalDocumentName, PinTypesList, ReferenceTypes, TrailerArrayIndex } from './globals.js';
|
|
10
11
|
import { isReference, unwrapValue as unwrapValue } from "./utils.js";
|
|
11
12
|
import { linkBuiltInMethods } from './builtinMethods.js';
|
|
12
|
-
import {
|
|
13
|
+
import { RuntimeExecutionError, throwWithContext } from './utils.js';
|
|
13
14
|
import { SequenceAction } from './objects/ExecutionScope.js';
|
|
14
15
|
import { PinId } from './objects/PinDefinition.js';
|
|
15
16
|
import { computeContentHash } from './cache/hash.js';
|
|
@@ -223,6 +224,11 @@ export class BaseVisitor extends CircuitScriptParserVisitor {
|
|
|
223
224
|
currentReference = this.visitResult(ctxTrailer);
|
|
224
225
|
});
|
|
225
226
|
}
|
|
227
|
+
else {
|
|
228
|
+
if (ctx.trailer().length > 0 && ctx.trailer(0).LParen()) {
|
|
229
|
+
this.throwWithContext(ctx, `Function not found: ${ctx.getText()}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
226
232
|
let resultValue = currentReference;
|
|
227
233
|
if (!keepReference) {
|
|
228
234
|
if (currentReference.type !== ReferenceTypes.pinType) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ComponentTypes } from "./globals.js";
|
|
2
|
-
import { NumericValue } from "./objects/
|
|
2
|
+
import { NumericValue } from "./objects/NumericValue.js";
|
|
3
3
|
export function flattenConditionNodes(conditionNodes, level = 0) {
|
|
4
4
|
const conditionBranches = [];
|
|
5
5
|
conditionNodes.forEach(node => {
|
|
@@ -29,6 +29,10 @@ export class RefdesAnnotationVisitor extends BaseVisitor {
|
|
|
29
29
|
this.getExecutor().closeOpenPathBlocks();
|
|
30
30
|
this.resultText = generateModifiedSourceText(this.modifications, this.tokenStream.getTokens(), this.sourceText);
|
|
31
31
|
};
|
|
32
|
+
visitCallable_expr = (ctx) => {
|
|
33
|
+
};
|
|
34
|
+
visitAssignment_expr = (ctx) => {
|
|
35
|
+
};
|
|
32
36
|
visitAdd_component_expr = (ctx) => {
|
|
33
37
|
this.addRefdesAnnotationComment(ctx);
|
|
34
38
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Big from "big.js";
|
|
2
|
-
import { numeric,
|
|
2
|
+
import { NumericValue, numeric, resolveToNumericValue } from "./objects/NumericValue.js";
|
|
3
3
|
import { CFunctionEntry, ImportedLibrary } from "./objects/types.js";
|
|
4
|
-
import { unwrapValue,
|
|
4
|
+
import { unwrapValue, RuntimeExecutionError } from "./utils.js";
|
|
5
5
|
import { BaseNamespace } from "./globals.js";
|
|
6
6
|
const builtInMethods = [
|
|
7
7
|
['enumerate', enumerate],
|
package/dist/esm/execute.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentTypes, Delimiter1, GlobalNames, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide } from './globals.js';
|
|
2
|
+
import { BlockTypes } from "./objects/BlockTypes.js";
|
|
2
3
|
import { ClassComponent, ComponentUnit, ModuleComponent } from './objects/ClassComponent.js';
|
|
3
4
|
import { ActiveObject, ExecutionScope, FrameAction, SequenceAction } from './objects/ExecutionScope.js';
|
|
4
5
|
import { Net } from './objects/Net.js';
|
|
5
|
-
import {
|
|
6
|
+
import { NumericValue } from './objects/NumericValue.js';
|
|
7
|
+
import { numeric } from "./objects/NumericValue.js";
|
|
6
8
|
import { PinId, PortSide } from './objects/PinDefinition.js';
|
|
7
9
|
import { AnyReference, CFunctionEntry, DeclaredReference, Direction, ImportFunctionHandling, NetTypes } from './objects/types.js';
|
|
8
10
|
import { Wire } from './objects/Wire.js';
|
package/dist/esm/globals.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { numeric } from "./objects/
|
|
1
|
+
import { numeric } from "./objects/NumericValue.js";
|
|
2
2
|
import { PinTypes } from "./objects/PinTypes.js";
|
|
3
3
|
export const TOOL_VERSION = '0.1.5';
|
|
4
4
|
export const Delimiter1 = '-';
|
|
@@ -100,13 +100,6 @@ export var ReferenceTypes;
|
|
|
100
100
|
ReferenceTypes["library"] = "library";
|
|
101
101
|
ReferenceTypes["unknown"] = "unknown";
|
|
102
102
|
})(ReferenceTypes || (ReferenceTypes = {}));
|
|
103
|
-
export var BlockTypes;
|
|
104
|
-
(function (BlockTypes) {
|
|
105
|
-
BlockTypes[BlockTypes["Branch"] = 1] = "Branch";
|
|
106
|
-
BlockTypes[BlockTypes["Join"] = 2] = "Join";
|
|
107
|
-
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
108
|
-
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
109
|
-
})(BlockTypes || (BlockTypes = {}));
|
|
110
103
|
export var NetGraphicsParams;
|
|
111
104
|
(function (NetGraphicsParams) {
|
|
112
105
|
NetGraphicsParams["Color"] = "color";
|
package/dist/esm/helpers.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Big from "big.js";
|
|
2
|
+
import { SimpleStopwatch } from "./utils.js";
|
|
2
3
|
import { BaseErrorListener, CharStream, CommonTokenStream, DefaultErrorStrategy } from "antlr4ng";
|
|
3
4
|
import { MainLexer } from "./lexer.js";
|
|
4
5
|
import { CircuitScriptParser } from "./antlr/CircuitScriptParser.js";
|
|
5
6
|
import { LengthUnit, MilsToMM, PxToMM } from "./globals.js";
|
|
6
|
-
import
|
|
7
|
+
import { resolveToNumericValue } from "./objects/NumericValue.js";
|
|
7
8
|
export var JSModuleType;
|
|
8
9
|
(function (JSModuleType) {
|
|
9
10
|
JSModuleType["CommonJs"] = "cjs";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
export * from './render/draw_symbols.js';
|
|
2
2
|
export * from './execute.js';
|
|
3
|
-
export * from './export.js';
|
|
3
|
+
export * from './render/export.js';
|
|
4
4
|
export * from './render/geometry.js';
|
|
5
|
+
export * from './pipeline.js';
|
|
5
6
|
export * from './globals.js';
|
|
6
7
|
export * from './helpers.js';
|
|
7
8
|
export * from './render/layout.js';
|
|
9
|
+
export * from './render/render.js';
|
|
10
|
+
export * from './render/KiCadNetListOutputHandler.js';
|
|
8
11
|
export * from './lexer.js';
|
|
9
12
|
export * from './LexerDiagnosticListener.js';
|
|
10
13
|
export * from './logger.js';
|
|
11
14
|
export * from './parser.js';
|
|
12
|
-
export * from './render/render.js';
|
|
13
15
|
export * from './utils.js';
|
|
14
16
|
export * from './visitor.js';
|
|
15
17
|
export * from './sizing.js';
|
|
@@ -18,5 +20,7 @@ export * from './builtinMethods.js';
|
|
|
18
20
|
export * from './validate/SymbolTable.js';
|
|
19
21
|
export * from './validate/SymbolValidatorResolveVisitor.js';
|
|
20
22
|
export * from './validate/SymbolValidatorVisitor.js';
|
|
23
|
+
export * from './validate/validateScript.js';
|
|
21
24
|
export * from './environment/environment.js';
|
|
22
25
|
export * from './annotate/RefdesAnnotationVisitor.js';
|
|
26
|
+
export * from './semantic-tokens/getSemanticTokens.js';
|
package/dist/esm/lexer.js
CHANGED
|
@@ -9,6 +9,7 @@ export class MainLexer extends CircuitScriptLexer {
|
|
|
9
9
|
opened;
|
|
10
10
|
diagnosticCollector;
|
|
11
11
|
lineOffset;
|
|
12
|
+
enableDiagnostics = false;
|
|
12
13
|
constructor(input, enableDiagnostics = false) {
|
|
13
14
|
super(input);
|
|
14
15
|
this.tokens = [];
|
|
@@ -16,8 +17,11 @@ export class MainLexer extends CircuitScriptLexer {
|
|
|
16
17
|
this.indents = [];
|
|
17
18
|
this.opened = 0;
|
|
18
19
|
this.lineOffset = 0;
|
|
19
|
-
this.
|
|
20
|
-
this.
|
|
20
|
+
this.enableDiagnostics = enableDiagnostics;
|
|
21
|
+
if (this.enableDiagnostics) {
|
|
22
|
+
this.diagnosticCollector = new LexerDiagnosticCollector();
|
|
23
|
+
this.diagnosticCollector.setEnabled(enableDiagnostics);
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
reset() {
|
|
23
27
|
this.tokens = [];
|
|
@@ -27,10 +31,10 @@ export class MainLexer extends CircuitScriptLexer {
|
|
|
27
31
|
super.reset();
|
|
28
32
|
}
|
|
29
33
|
emitToken(token) {
|
|
30
|
-
this.diagnosticCollector.onTokenStart();
|
|
34
|
+
this.enableDiagnostics && this.diagnosticCollector.onTokenStart();
|
|
31
35
|
super.emitToken(token);
|
|
32
36
|
this.tokens.push(token);
|
|
33
|
-
this.diagnosticCollector.onTokenGenerated(token, this.tokens.length - this.tokensHead);
|
|
37
|
+
this.enableDiagnostics && this.diagnosticCollector.onTokenGenerated(token, this.tokens.length - this.tokensHead);
|
|
34
38
|
}
|
|
35
39
|
nextToken() {
|
|
36
40
|
if (this.inputStream.LA(1) === CircuitScriptParser.EOF && this.indents.length) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export var BlockTypes;
|
|
2
|
+
(function (BlockTypes) {
|
|
3
|
+
BlockTypes[BlockTypes["Branch"] = 1] = "Branch";
|
|
4
|
+
BlockTypes[BlockTypes["Join"] = 2] = "Join";
|
|
5
|
+
BlockTypes[BlockTypes["Parallel"] = 3] = "Parallel";
|
|
6
|
+
BlockTypes[BlockTypes["Point"] = 4] = "Point";
|
|
7
|
+
})(BlockTypes || (BlockTypes = {}));
|