circuitscript 0.3.1 → 0.4.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 +394 -262
- package/dist/cjs/LexerDiagnosticListener.js +375 -0
- package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
- package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +10 -84
- package/dist/cjs/annotate/utils.js +70 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
- package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
- package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
- package/dist/cjs/cache/deserializer.js +34 -0
- package/dist/cjs/cache/hash.js +8 -0
- package/dist/cjs/cache/serializer.js +122 -0
- package/dist/cjs/cache/storage.js +45 -0
- package/dist/cjs/cache/types.js +4 -0
- package/dist/cjs/{environment.js → environment/environment.js} +18 -6
- package/dist/cjs/environment/esm-environment.js +21 -0
- package/dist/cjs/environment/helpers.js +8 -0
- package/dist/cjs/execute.js +49 -15
- package/dist/cjs/globals.js +9 -1
- package/dist/cjs/helpers.js +3 -467
- package/dist/cjs/importResolver.js +102 -0
- package/dist/cjs/index.js +7 -6
- package/dist/cjs/lexer.js +48 -12
- package/dist/cjs/main.js +14 -4
- package/dist/cjs/objects/ClassComponent.js +1 -1
- package/dist/cjs/objects/ExecutionScope.js +0 -1
- package/dist/cjs/objects/types.js +17 -1
- package/dist/cjs/parser.js +18 -4
- package/dist/cjs/pipeline.js +284 -0
- package/dist/cjs/regenerate-tests.js +4 -3
- package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
- package/dist/cjs/render/PaperSizes.js +46 -0
- package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/cjs/{export.js → render/export.js} +2 -2
- package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
- package/dist/cjs/{graph.js → render/graph.js} +7 -7
- package/dist/cjs/{layout.js → render/layout.js} +8 -8
- package/dist/cjs/{render.js → render/render.js} +9 -8
- package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/cjs/rules-check/unconnected-pins.js +1 -1
- package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
- package/dist/cjs/sizing.js +2 -2
- package/dist/cjs/utils.js +2 -2
- package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
- package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
- package/dist/cjs/validate/validateScript.js +54 -0
- package/dist/cjs/validate.js +5 -4
- package/dist/cjs/visitor.js +158 -212
- package/dist/esm/BaseVisitor.js +396 -264
- package/dist/esm/LexerDiagnosticListener.js +371 -0
- package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
- package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
- package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +10 -84
- package/dist/esm/annotate/utils.js +66 -0
- package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
- package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
- package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
- package/dist/esm/cache/deserializer.js +30 -0
- package/dist/esm/cache/hash.js +4 -0
- package/dist/esm/cache/serializer.js +118 -0
- package/dist/esm/cache/storage.js +39 -0
- package/dist/esm/cache/types.js +1 -0
- package/dist/esm/{environment.js → environment/environment.js} +18 -6
- package/dist/esm/environment/esm-environment.js +17 -0
- package/dist/esm/environment/helpers.js +4 -0
- package/dist/esm/execute.js +49 -15
- package/dist/esm/globals.js +8 -0
- package/dist/esm/helpers.js +5 -456
- package/dist/esm/importResolver.js +96 -0
- package/dist/esm/index.js +7 -6
- package/dist/esm/lexer.js +51 -12
- package/dist/esm/main.js +13 -3
- package/dist/esm/objects/ClassComponent.js +1 -1
- package/dist/esm/objects/ExecutionScope.js +0 -1
- package/dist/esm/objects/types.js +21 -1
- package/dist/esm/parser.js +19 -5
- package/dist/esm/pipeline.js +276 -0
- package/dist/esm/regenerate-tests.js +3 -2
- package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
- package/dist/esm/render/PaperSizes.js +41 -0
- package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
- package/dist/esm/{export.js → render/export.js} +2 -2
- package/dist/esm/{geometry.js → render/geometry.js} +5 -5
- package/dist/esm/{graph.js → render/graph.js} +7 -7
- package/dist/esm/{layout.js → render/layout.js} +8 -8
- package/dist/esm/{render.js → render/render.js} +8 -7
- package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
- package/dist/esm/rules-check/unconnected-pins.js +1 -1
- package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
- package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
- package/dist/esm/sizing.js +2 -2
- package/dist/esm/utils.js +2 -2
- package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
- package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
- package/dist/esm/validate/validateScript.js +50 -0
- package/dist/esm/validate.js +4 -3
- package/dist/esm/visitor.js +160 -214
- package/dist/libs/std.cst +15 -19
- package/dist/types/BaseVisitor.d.ts +25 -18
- package/dist/types/BomGeneration.d.ts +1 -1
- package/dist/types/LexerDiagnosticListener.d.ts +85 -0
- package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
- package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
- package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +7 -9
- package/dist/types/annotate/utils.d.ts +6 -0
- package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
- package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
- package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
- package/dist/types/cache/deserializer.d.ts +5 -0
- package/dist/types/cache/hash.d.ts +1 -0
- package/dist/types/cache/serializer.d.ts +3 -0
- package/dist/types/cache/storage.d.ts +4 -0
- package/dist/types/cache/types.d.ts +20 -0
- package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
- package/dist/types/environment/esm-environment.d.ts +4 -0
- package/dist/types/environment/helpers.d.ts +2 -0
- package/dist/types/execute.d.ts +3 -2
- package/dist/types/globals.d.ts +1 -0
- package/dist/types/helpers.d.ts +31 -36
- package/dist/types/importResolver.d.ts +4 -0
- package/dist/types/index.d.ts +7 -6
- package/dist/types/lexer.d.ts +9 -5
- package/dist/types/objects/ClassComponent.d.ts +1 -1
- package/dist/types/objects/ExecutionScope.d.ts +1 -4
- package/dist/types/objects/types.d.ts +16 -2
- package/dist/types/parser.d.ts +9 -2
- package/dist/types/pipeline.d.ts +9 -0
- package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
- package/dist/types/render/PaperSizes.d.ts +12 -0
- package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
- package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
- package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
- package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
- package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
- package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
- package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
- package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
- package/dist/types/sizing.d.ts +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
- package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
- package/dist/types/validate/validateScript.d.ts +3 -0
- package/dist/types/visitor.d.ts +8 -14
- package/libs/std.cst +15 -19
- package/package.json +3 -6
- package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { milsToMM } from "
|
|
2
|
-
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "
|
|
1
|
+
import { milsToMM } from "../helpers.js";
|
|
2
|
+
import { ColorScheme, CustomSymbolParamTextSize, CustomSymbolPinIdSize, CustomSymbolPinTextSize, CustomSymbolRefDesSize, PinTypesList, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical, ReferenceTypes, RenderFlags, SymbolPinSide, defaultFont, defaultPinIdTextSize, defaultPinNameTextSize, defaultSymbolLineWidth, fontDisplayScale } from "../globals.js";
|
|
3
3
|
import { Geometry, GeometryProp, HorizontalAlign, HorizontalAlignProp, Textbox, VerticalAlign, VerticalAlignProp } from "./geometry.js";
|
|
4
|
-
import { PinTypes } from "
|
|
5
|
-
import { roundValue, RuntimeExecutionError, throwWithContext } from "
|
|
6
|
-
import { DeclaredReference, UndeclaredReference } from "
|
|
7
|
-
import { numeric, NumericValue } from "
|
|
8
|
-
import { PinId } from "
|
|
4
|
+
import { PinTypes } from "../objects/PinTypes.js";
|
|
5
|
+
import { roundValue, RuntimeExecutionError, throwWithContext } from "../utils.js";
|
|
6
|
+
import { DeclaredReference, UndeclaredReference } from "../objects/types.js";
|
|
7
|
+
import { numeric, NumericValue } from "../objects/ParamDefinition.js";
|
|
8
|
+
import { PinId } from "../objects/PinDefinition.js";
|
|
9
9
|
export class SymbolGraphic {
|
|
10
10
|
drawPortsName = true;
|
|
11
11
|
displayBounds = false;
|
|
@@ -136,18 +136,19 @@ export class SymbolGraphic {
|
|
|
136
136
|
for (const label of labels) {
|
|
137
137
|
const tmpLabel = label;
|
|
138
138
|
const { fontSize = numeric(50), anchor = HorizontalAlign.Left, vanchor = VerticalAlign.Bottom, fontWeight = 'regular', angle: tmpLabelAngle = numeric(0), textColor = "#333", } = tmpLabel.style ?? {};
|
|
139
|
-
const labelAngle = tmpLabelAngle.toNumber();
|
|
140
139
|
let anchorStyle = 'start';
|
|
141
140
|
let dominantBaseline = 'auto';
|
|
142
141
|
let useAnchor = anchor;
|
|
143
142
|
let useDominantBaseline = vanchor;
|
|
144
|
-
const
|
|
143
|
+
const labelAngle = tmpLabelAngle.toNumber();
|
|
144
|
+
const finalLabelAngle = labelAngle + this.angle;
|
|
145
|
+
const isRotation180 = Math.abs(finalLabelAngle) === 180;
|
|
145
146
|
if (isRotation180) {
|
|
146
147
|
useAnchor = this.flipTextAnchor(anchor);
|
|
147
148
|
useDominantBaseline = this.flipDominantBaseline(vanchor);
|
|
148
149
|
}
|
|
149
|
-
const isHorizontalLabel =
|
|
150
|
-
const isVerticalLabel =
|
|
150
|
+
const isHorizontalLabel = finalLabelAngle === 0 || finalLabelAngle === 180;
|
|
151
|
+
const isVerticalLabel = finalLabelAngle === 90 || finalLabelAngle === -90;
|
|
151
152
|
if (useAnchor === HorizontalAlign.Middle) {
|
|
152
153
|
anchorStyle = HorizontalAlignProp.Middle;
|
|
153
154
|
}
|
|
@@ -187,16 +188,9 @@ export class SymbolGraphic {
|
|
|
187
188
|
const textContainer = group.group();
|
|
188
189
|
let translateX, translateY;
|
|
189
190
|
let useRotateAngle = 0;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
useRotateAngle = 0;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
translateX = position[0];
|
|
197
|
-
translateY = position[1];
|
|
198
|
-
useRotateAngle = this.angle;
|
|
199
|
-
}
|
|
191
|
+
translateX = position[0];
|
|
192
|
+
translateY = position[1];
|
|
193
|
+
useRotateAngle = this.angle;
|
|
200
194
|
translateX = roundValue(translateX);
|
|
201
195
|
translateY = roundValue(translateY);
|
|
202
196
|
const { portType = null } = tmpLabel.style;
|
|
@@ -291,6 +285,10 @@ export class SymbolGraphic {
|
|
|
291
285
|
}
|
|
292
286
|
textContainer.translate(translateX.toNumber(), translateY.toNumber())
|
|
293
287
|
.rotate(useRotateAngle, -translateX.toNumber(), -translateY.toNumber());
|
|
288
|
+
let useLabelAngle = labelAngle;
|
|
289
|
+
if (isRotation180) {
|
|
290
|
+
useLabelAngle = (labelAngle + 180) % 360;
|
|
291
|
+
}
|
|
294
292
|
textContainer.text(tmpLabel.text)
|
|
295
293
|
.fill(textColor)
|
|
296
294
|
.font({
|
|
@@ -301,7 +299,7 @@ export class SymbolGraphic {
|
|
|
301
299
|
weight: fontWeight,
|
|
302
300
|
})
|
|
303
301
|
.attr("xml:space", "preserve")
|
|
304
|
-
.rotate(
|
|
302
|
+
.rotate(useLabelAngle, 0, 0);
|
|
305
303
|
const { a, b, c, d, e, f } = textContainer.matrix();
|
|
306
304
|
const newMatrix = {
|
|
307
305
|
a: roundValue(numeric(a)).toNumber(),
|
|
@@ -512,16 +510,21 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
512
510
|
drawPinParams(drawing, commandName, keywordParams, positionParams, lineColor, pinNameColor) {
|
|
513
511
|
drawing.log('add pin', ...positionParams);
|
|
514
512
|
positionParams = [...positionParams];
|
|
515
|
-
const keywordDisplayPinId = '
|
|
513
|
+
const keywordDisplayPinId = 'display_id';
|
|
514
|
+
const keywordDisplayPinName = 'display_name';
|
|
516
515
|
let displayPinId = true;
|
|
516
|
+
let displayPinName = true;
|
|
517
517
|
if (keywordParams.has(keywordDisplayPinId)) {
|
|
518
518
|
const value = keywordParams.get(keywordDisplayPinId);
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
519
|
+
displayPinId = ((value instanceof NumericValue && value.toNumber() === 0)
|
|
520
|
+
|| (value === 0)
|
|
521
|
+
|| (value === false)) ? false : true;
|
|
522
|
+
}
|
|
523
|
+
if (keywordParams.has(keywordDisplayPinName)) {
|
|
524
|
+
const value = keywordParams.get(keywordDisplayPinName);
|
|
525
|
+
displayPinName = ((value instanceof NumericValue && value.toNumber() === 0)
|
|
526
|
+
|| (value === 0)
|
|
527
|
+
|| (value === false)) ? false : true;
|
|
525
528
|
}
|
|
526
529
|
let pinNameParam = null;
|
|
527
530
|
let pinType = PinTypes.Any;
|
|
@@ -529,6 +532,10 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
529
532
|
pinType = positionParams[1].value;
|
|
530
533
|
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
531
534
|
}
|
|
535
|
+
else if (typeof positionParams[1] === 'string' && PinTypesList.indexOf(positionParams[1]) !== -1) {
|
|
536
|
+
pinType = positionParams[1];
|
|
537
|
+
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
538
|
+
}
|
|
532
539
|
if (typeof positionParams[1] === 'string') {
|
|
533
540
|
pinNameParam = positionParams[1];
|
|
534
541
|
positionParams = [positionParams[0], ...positionParams.slice(2)];
|
|
@@ -578,12 +585,14 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
578
585
|
let pinNameAlignment = HorizontalAlign.Left;
|
|
579
586
|
const offset1 = 15;
|
|
580
587
|
const offset2 = 15;
|
|
581
|
-
let pinNameOffsetX = milsToMM(
|
|
588
|
+
let pinNameOffsetX = milsToMM(0);
|
|
589
|
+
let pinNameOffsetY = milsToMM(0);
|
|
582
590
|
let pinIdOffsetX = numeric(0);
|
|
583
591
|
let pinIdAlignment = HorizontalAlign.Left;
|
|
584
592
|
let pinIdVAlignment = VerticalAlign.Bottom;
|
|
585
593
|
let pinIdOffsetY = milsToMM(-offset2);
|
|
586
594
|
const angleValue = angle.toNumber();
|
|
595
|
+
let usePinIdAngle = 0;
|
|
587
596
|
switch (angleValue) {
|
|
588
597
|
case 0:
|
|
589
598
|
pinNameAlignment = HorizontalAlign.Left;
|
|
@@ -592,6 +601,15 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
592
601
|
pinIdOffsetX = milsToMM(-offset2);
|
|
593
602
|
break;
|
|
594
603
|
case 90:
|
|
604
|
+
pinNameAlignment = HorizontalAlign.Right;
|
|
605
|
+
pinNameOffsetX = milsToMM(0);
|
|
606
|
+
pinNameOffsetY = milsToMM(offset1);
|
|
607
|
+
pinIdAlignment = HorizontalAlign.Left;
|
|
608
|
+
pinIdOffsetX = milsToMM(-offset2);
|
|
609
|
+
pinIdOffsetY = milsToMM(-offset2);
|
|
610
|
+
pinIdVAlignment = VerticalAlign.Bottom;
|
|
611
|
+
usePinIdAngle = -90;
|
|
612
|
+
break;
|
|
595
613
|
case 180:
|
|
596
614
|
pinNameAlignment = HorizontalAlign.Right;
|
|
597
615
|
pinNameOffsetX = milsToMM(-offset1);
|
|
@@ -600,27 +618,31 @@ export class SymbolPlaceholder extends SymbolGraphic {
|
|
|
600
618
|
break;
|
|
601
619
|
case 270:
|
|
602
620
|
pinNameAlignment = HorizontalAlign.Left;
|
|
603
|
-
pinNameOffsetX = milsToMM(
|
|
604
|
-
|
|
605
|
-
|
|
621
|
+
pinNameOffsetX = milsToMM(0);
|
|
622
|
+
pinNameOffsetY = milsToMM(-offset1);
|
|
623
|
+
pinIdAlignment = HorizontalAlign.Right;
|
|
624
|
+
pinIdOffsetX = milsToMM(-offset2);
|
|
606
625
|
pinIdOffsetY = milsToMM(offset2);
|
|
607
|
-
pinIdVAlignment = VerticalAlign.
|
|
626
|
+
pinIdVAlignment = VerticalAlign.Bottom;
|
|
627
|
+
usePinIdAngle = -90;
|
|
608
628
|
break;
|
|
609
629
|
}
|
|
610
630
|
if (angleValue === 0 || angleValue === 90 || angleValue === 180 || angleValue === 270) {
|
|
611
631
|
const usePinName = pinNameParam ?? "";
|
|
612
|
-
usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY, usePinName, {
|
|
632
|
+
displayPinName && usePinName !== "" && drawing.addLabel(endX.add(pinNameOffsetX), endY.add(pinNameOffsetY), usePinName, {
|
|
613
633
|
fontSize: numeric(defaultPinNameTextSize),
|
|
614
634
|
anchor: pinNameAlignment,
|
|
615
635
|
vanchor: VerticalAlign.Middle,
|
|
616
636
|
textColor: pinNameColor,
|
|
637
|
+
angle: numeric(usePinIdAngle)
|
|
617
638
|
});
|
|
618
639
|
const pinDisplayText = pinId.toString();
|
|
619
640
|
displayPinId && drawing.addLabel(endX.add(pinIdOffsetX), endY.add(pinIdOffsetY), pinDisplayText, {
|
|
620
641
|
fontSize: numeric(defaultPinIdTextSize),
|
|
621
642
|
anchor: pinIdAlignment,
|
|
622
643
|
vanchor: pinIdVAlignment,
|
|
623
|
-
textColor: lineColor
|
|
644
|
+
textColor: lineColor,
|
|
645
|
+
angle: numeric(usePinIdAngle)
|
|
624
646
|
});
|
|
625
647
|
}
|
|
626
648
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NoNetText } from "
|
|
2
|
-
import { NumericValue } from "
|
|
1
|
+
import { NoNetText } from "../globals.js";
|
|
2
|
+
import { NumericValue } from "../objects/ParamDefinition.js";
|
|
3
3
|
export function generateKiCadNetList(netlist) {
|
|
4
4
|
const componentsList = [];
|
|
5
5
|
const nets = {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Flatten from '@flatten-js/core';
|
|
2
|
-
import { measureTextSize2 } from '
|
|
3
|
-
import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from '
|
|
4
|
-
import { numeric, NumericValue } from '
|
|
5
|
-
import { AllPinTypes, PinTypes } from '
|
|
6
|
-
import { roundValue } from '
|
|
2
|
+
import { measureTextSize2 } from '../sizing.js';
|
|
3
|
+
import { defaultFont, fontDisplayScale, PortArrowSize, PortPaddingHorizontal, PortPaddingVertical } from '../globals.js';
|
|
4
|
+
import { numeric, NumericValue } from '../objects/ParamDefinition.js';
|
|
5
|
+
import { AllPinTypes, PinTypes } from '../objects/PinTypes.js';
|
|
6
|
+
import { roundValue } from '../utils.js';
|
|
7
7
|
export class Textbox extends Flatten.Polygon {
|
|
8
8
|
id;
|
|
9
9
|
text;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Graph } from "@dagrejs/graphlib";
|
|
2
2
|
import { SymbolDrawing, SymbolPlaceholder, SymbolCustomModule, SymbolCustom } from "./draw_symbols.js";
|
|
3
|
-
import { ComponentTypes } from "
|
|
4
|
-
import { milsToMM } from "
|
|
3
|
+
import { ComponentTypes } from "../globals.js";
|
|
4
|
+
import { milsToMM } from "../helpers.js";
|
|
5
5
|
import { RenderFrame, RenderComponent, applyComponentParamsToSymbol, RenderWire } from "./layout.js";
|
|
6
|
-
import { SequenceAction, FrameAction } from "
|
|
7
|
-
import { Frame, FixedFrameIds, FrameParamKeys } from "
|
|
8
|
-
import { numeric } from "
|
|
9
|
-
import { NetTypes } from "
|
|
6
|
+
import { SequenceAction, FrameAction } from "../objects/ExecutionScope.js";
|
|
7
|
+
import { Frame, FixedFrameIds, FrameParamKeys } from "../objects/Frame.js";
|
|
8
|
+
import { numeric } from "../objects/ParamDefinition.js";
|
|
9
|
+
import { NetTypes } from "../objects/types.js";
|
|
10
10
|
import Matrix, { solve } from "ml-matrix";
|
|
11
|
-
import { getPinDefinition, PinId } from "
|
|
11
|
+
import { getPinDefinition, PinId } from "../objects/PinDefinition.js";
|
|
12
12
|
export class NetGraph {
|
|
13
13
|
logger;
|
|
14
14
|
constructor(logger) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import graphlib from '@dagrejs/graphlib';
|
|
2
2
|
const { alg } = graphlib;
|
|
3
3
|
import { SymbolCustom, SymbolDrawing, SymbolPlaceholder, SymbolText, PlaceHolderCommands } from "./draw_symbols.js";
|
|
4
|
-
import { DefaultComponentUnit, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from '
|
|
4
|
+
import { DefaultComponentUnit, defaultFrameTitleTextSize, defaultGridSizeUnits, FrameType, NetGraphicsParams, ParamKeys, WireAutoDirection } from '../globals.js';
|
|
5
5
|
import { Geometry, HorizontalAlign, VerticalAlign } from './geometry.js';
|
|
6
|
-
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from '
|
|
7
|
-
import { areasOverlap, combineMaps, getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from '
|
|
8
|
-
import { Direction } from '
|
|
9
|
-
import { PinId } from '
|
|
10
|
-
import { milsToMM, UnitDimension } from '
|
|
11
|
-
import { numeric } from '
|
|
6
|
+
import { FixedFrameIds, Frame, FrameParamKeys, FramePlotDirection } from '../objects/Frame.js';
|
|
7
|
+
import { areasOverlap, combineMaps, getBoundsSize, printBounds, resizeBounds, resizeToNearestGrid, roundValue, toNearestGrid } from '../utils.js';
|
|
8
|
+
import { Direction } from '../objects/types.js';
|
|
9
|
+
import { PinId } from '../objects/PinDefinition.js';
|
|
10
|
+
import { milsToMM, UnitDimension } from '../helpers.js';
|
|
11
|
+
import { numeric } from '../objects/ParamDefinition.js';
|
|
12
12
|
import { generateLayoutPinDefinition, getWireName, RenderItemType } from './graph.js';
|
|
13
13
|
export class LayoutEngine {
|
|
14
14
|
logger;
|
|
@@ -1309,7 +1309,7 @@ export function CalculatePinPositions(unit) {
|
|
|
1309
1309
|
}
|
|
1310
1310
|
applyComponentParamsToSymbol(unit, tmpSymbol);
|
|
1311
1311
|
tmpSymbol.refreshDrawing();
|
|
1312
|
-
const pins = unit
|
|
1312
|
+
const { pins } = unit;
|
|
1313
1313
|
pins.forEach((value, key) => {
|
|
1314
1314
|
if (unit._unplacedPins.indexOf(key) === -1) {
|
|
1315
1315
|
pinPositionMapping.set(key, tmpSymbol.pinPosition(key));
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { SVG, registerWindow } from '@svgdotjs/svg.js';
|
|
2
2
|
import { ExtractDrawingRects, RenderFrameType, getBounds } from "./layout.js";
|
|
3
|
-
import { applyFontsToSVG } from '
|
|
4
|
-
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from '
|
|
5
|
-
import { numeric, NumericValue } from '
|
|
6
|
-
import { combineMaps, getBoundsSize } from '
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { applyFontsToSVG } from '../sizing.js';
|
|
4
|
+
import { ColorScheme, ComponentTypes, FrameType, MMToPt, MMToPx, MilsToMM, ParamKeys, RenderFlags, defaultGridSizeUnits, defaultPageSpacingMM, defaultWireLineWidth, fontDisplayScale, junctionSize } from '../globals.js';
|
|
5
|
+
import { numeric, NumericValue } from '../objects/ParamDefinition.js';
|
|
6
|
+
import { combineMaps, getBoundsSize } from '../utils.js';
|
|
7
|
+
import { milsToMM } from '../helpers.js';
|
|
8
|
+
import { getPaperSize } from "./PaperSizes.js";
|
|
9
|
+
import { NodeScriptEnvironment } from "../environment/environment.js";
|
|
9
10
|
import SVGtoPDF from 'svg-to-pdfkit';
|
|
10
|
-
import { FrameParamKeys } from '
|
|
11
|
+
import { FrameParamKeys } from '../objects/Frame.js';
|
|
11
12
|
import { SymbolPlaceholder } from './draw_symbols.js';
|
|
12
13
|
function createSvgCanvas() {
|
|
13
14
|
const env = NodeScriptEnvironment.getInstance();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Assignment_exprContext } from "
|
|
2
|
-
import { BaseVisitor } from "
|
|
3
|
-
import { buildInMethodNamesList } from "
|
|
4
|
-
import { SymbolValidatorContext } from "
|
|
1
|
+
import { Assignment_exprContext } from "../antlr/CircuitScriptParser.js";
|
|
2
|
+
import { BaseVisitor } from "../BaseVisitor.js";
|
|
3
|
+
import { buildInMethodNamesList } from "../builtinMethods.js";
|
|
4
|
+
import { SymbolValidatorContext } from "../globals.js";
|
|
5
5
|
export class SemanticTokensVisitor extends BaseVisitor {
|
|
6
6
|
parsedTokens = [];
|
|
7
7
|
lexer;
|
|
@@ -47,14 +47,16 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
47
47
|
this.runExpressions(newExecutor, ctx.function_expr());
|
|
48
48
|
this.executionStack.pop();
|
|
49
49
|
};
|
|
50
|
-
|
|
50
|
+
visitCreateExpr = (ctx) => {
|
|
51
51
|
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
52
|
+
this.visit(ctx.create_expr());
|
|
53
|
+
};
|
|
54
|
+
visitCreate_component_expr = (ctx) => {
|
|
52
55
|
ctx.property_expr().forEach(property_expr => {
|
|
53
56
|
this.visit(property_expr);
|
|
54
57
|
});
|
|
55
58
|
};
|
|
56
59
|
visitCreate_graphic_expr = (ctx) => {
|
|
57
|
-
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
58
60
|
const graphicsExpressionsCtx = ctx.graphic_expressions_block();
|
|
59
61
|
this.visitResult(graphicsExpressionsCtx);
|
|
60
62
|
};
|
|
@@ -101,18 +103,14 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
101
103
|
}
|
|
102
104
|
};
|
|
103
105
|
visitAssignment_expr = (ctx) => {
|
|
104
|
-
this.visit(ctx.
|
|
106
|
+
this.visit(ctx.callable_expr());
|
|
105
107
|
this.visit(ctx.data_expr());
|
|
106
108
|
};
|
|
107
|
-
|
|
108
|
-
if (ctx.parent instanceof Assignment_exprContext && ctx.ID(
|
|
109
|
-
this.addSemanticToken(ctx.ID(
|
|
109
|
+
visitCallable_expr = (ctx) => {
|
|
110
|
+
if (ctx.parent instanceof Assignment_exprContext && ctx.ID()) {
|
|
111
|
+
this.addSemanticToken(ctx.ID(), [], 'variable');
|
|
110
112
|
}
|
|
111
113
|
};
|
|
112
|
-
visitOperator_assignment_expr = (ctx) => {
|
|
113
|
-
this.visit(ctx.atom_expr());
|
|
114
|
-
this.visit(ctx.data_expr());
|
|
115
|
-
};
|
|
116
114
|
visitImport_expr = (ctx) => {
|
|
117
115
|
this.addSemanticToken(ctx.ID(), [], 'namespace');
|
|
118
116
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { prepareFile } from "../helpers.js";
|
|
2
|
+
import { prepareTokens, SemanticTokensVisitor } from "./SemanticTokenVisitor.js";
|
|
3
|
+
import { ParseError } from "../utils.js";
|
|
4
|
+
export async function getSemanticTokens(filePath, scriptData, options) {
|
|
5
|
+
const { parser, lexer, tokens } = prepareFile(scriptData);
|
|
6
|
+
const tree = parser.script();
|
|
7
|
+
const visitor = new SemanticTokensVisitor(true, null, options.environment, lexer, scriptData);
|
|
8
|
+
parser.removeErrorListeners();
|
|
9
|
+
visitor.onImportFile = async (visitor, filePath, textData) => {
|
|
10
|
+
let hasError = false;
|
|
11
|
+
let hasParseError = false;
|
|
12
|
+
if (textData !== null) {
|
|
13
|
+
const { parser } = prepareFile(textData);
|
|
14
|
+
const tree = parser.script();
|
|
15
|
+
try {
|
|
16
|
+
visitor.visit(tree);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.log('Error while parsing: ', err);
|
|
20
|
+
hasParseError = true;
|
|
21
|
+
hasError = true;
|
|
22
|
+
throw new ParseError(`Error parsing semantic tokens in imported file: ${err}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
console.log('File does not exist');
|
|
27
|
+
hasError = true;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
hasError, hasParseError
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
await visitor.resolveImportsAndLoad(filePath, scriptData);
|
|
34
|
+
visitor.visit(tree);
|
|
35
|
+
const semanticTokens = visitor.getTokens();
|
|
36
|
+
const parsedTokens = prepareTokens(tokens.getTokens(), lexer, scriptData);
|
|
37
|
+
const finalParsedTokens = [];
|
|
38
|
+
parsedTokens.forEach(token => {
|
|
39
|
+
const location = `${token.line}_${token.column}_${token.length}`;
|
|
40
|
+
if (semanticTokens.has(location)) {
|
|
41
|
+
finalParsedTokens.push(semanticTokens.get(location));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
finalParsedTokens.push(token);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
visitor,
|
|
49
|
+
parsedTokens: finalParsedTokens
|
|
50
|
+
};
|
|
51
|
+
}
|
package/dist/esm/sizing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Big } from 'big.js';
|
|
2
|
-
import { HorizontalAlign, HorizontalAlignProp, VerticalAlign, VerticalAlignProp } from './geometry.js';
|
|
2
|
+
import { HorizontalAlign, HorizontalAlignProp, VerticalAlign, VerticalAlignProp } from './render/geometry.js';
|
|
3
3
|
import { defaultFont } from './globals.js';
|
|
4
|
-
import { NodeScriptEnvironment } from "./environment.js";
|
|
4
|
+
import { NodeScriptEnvironment } from "./environment/environment.js";
|
|
5
5
|
export function applyFontsToSVG(canvas) {
|
|
6
6
|
}
|
|
7
7
|
const measureTextSizeCache = {};
|
package/dist/esm/utils.js
CHANGED
|
@@ -8,10 +8,10 @@ import { DeclaredReference, AnyReference } from './objects/types.js';
|
|
|
8
8
|
export class SimpleStopwatch {
|
|
9
9
|
startTime;
|
|
10
10
|
constructor() {
|
|
11
|
-
this.startTime =
|
|
11
|
+
this.startTime = performance.now();
|
|
12
12
|
}
|
|
13
13
|
lap() {
|
|
14
|
-
return
|
|
14
|
+
return performance.now() - this.startTime;
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
export function resizeBounds(bounds, value) {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { SymbolValidatorVisitor } from "./SymbolValidatorVisitor.js";
|
|
2
2
|
export class SymbolValidatorResolveVisitor extends SymbolValidatorVisitor {
|
|
3
|
+
enableCacheImports = false;
|
|
4
|
+
enableCachedImportsRead = false;
|
|
5
|
+
enableCachedImportsWrite = false;
|
|
3
6
|
addSymbolVariable(token, name, value) {
|
|
4
7
|
}
|
|
5
8
|
addSymbolFunction(token, functionName, funcDefinedParameters) {
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Import_specific_or_allContext } from "../antlr/CircuitScriptParser.js";
|
|
2
2
|
import { buildInMethodNamesList } from "../builtinMethods.js";
|
|
3
3
|
import { ImportFunctionHandling, ParseSymbolType } from "../objects/types.js";
|
|
4
4
|
import { cloneSymbol } from "./SymbolTable.js";
|
|
5
5
|
import { SymbolTable } from "./SymbolTable.js";
|
|
6
6
|
import { BaseVisitor } from "../BaseVisitor.js";
|
|
7
|
-
import { BaseNamespace, SymbolValidatorContext } from "../globals.js";
|
|
7
|
+
import { BaseNamespace, PinTypesList, SymbolValidatorContext } from "../globals.js";
|
|
8
8
|
export class SymbolValidatorVisitor extends BaseVisitor {
|
|
9
|
+
enableCacheImports = false;
|
|
10
|
+
enableCachedImportsRead = false;
|
|
11
|
+
enableCachedImportsWrite = false;
|
|
9
12
|
symbolTable = new SymbolTable();
|
|
10
13
|
addSymbolVariable(token, name, value, executor = null) {
|
|
11
14
|
const useExecutor = executor === null ? this.getExecutor() : executor;
|
|
@@ -54,16 +57,16 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
54
57
|
setSymbols(symbolTable) {
|
|
55
58
|
this.symbolTable = symbolTable;
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
importCommon(ctx, handling) {
|
|
58
61
|
const specifiedImports = [];
|
|
59
|
-
if (ctx instanceof
|
|
62
|
+
if (ctx instanceof Import_specific_or_allContext) {
|
|
60
63
|
const tmpImports = ctx._funcNames.map(item => {
|
|
61
64
|
return item.text;
|
|
62
65
|
});
|
|
63
66
|
specifiedImports.push(...tmpImports);
|
|
64
67
|
}
|
|
65
|
-
const id = ctx._libraryName.text;
|
|
66
|
-
const { pathExists, importedLibrary } =
|
|
68
|
+
const id = ctx._libraryName.text.slice(1, -1);
|
|
69
|
+
const { pathExists, importedLibrary } = this.handleImportFile(id, handling, true, ctx, specifiedImports);
|
|
67
70
|
if (!pathExists) {
|
|
68
71
|
this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._libraryName);
|
|
69
72
|
}
|
|
@@ -71,14 +74,15 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
71
74
|
this.applyLibraryImports(importedLibrary);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
|
-
visitImport_simple =
|
|
75
|
-
|
|
77
|
+
visitImport_simple = (ctx) => {
|
|
78
|
+
this.importCommon(ctx, ImportFunctionHandling.AllWithNamespace);
|
|
76
79
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
visitImport_specific_or_all = (ctx) => {
|
|
81
|
+
let importType = ImportFunctionHandling.SpecificMergeIntoNamespace;
|
|
82
|
+
if (ctx._all) {
|
|
83
|
+
importType = ImportFunctionHandling.AllMergeIntoNamespace;
|
|
84
|
+
}
|
|
85
|
+
this.importCommon(ctx, importType);
|
|
82
86
|
};
|
|
83
87
|
applyLibraryImports(library) {
|
|
84
88
|
const { importHandlingFlag: importHandling, specifiedImports } = library;
|
|
@@ -110,7 +114,7 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
110
114
|
const ctxDataExpr = ctx.data_expr();
|
|
111
115
|
this.visit(ctxDataExpr);
|
|
112
116
|
const value = this.getResult(ctxDataExpr);
|
|
113
|
-
const atomId = ctx.
|
|
117
|
+
const atomId = ctx.callable_expr().ID();
|
|
114
118
|
const atomText = atomId.getText();
|
|
115
119
|
const executor = this.getExecutor();
|
|
116
120
|
if (!this.symbolTable.exists(executor, atomText)) {
|
|
@@ -122,37 +126,25 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
122
126
|
}
|
|
123
127
|
return null;
|
|
124
128
|
};
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
129
|
+
visitCallableExpr = (ctx) => {
|
|
130
|
+
const innerCtx = ctx.callable_expr();
|
|
131
|
+
const innerCtxID = innerCtx.ID();
|
|
132
|
+
if (PinTypesList.indexOf(innerCtxID.getText()) !== -1 && innerCtx.trailer().length === 0) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
const tmpSymbol = this.handleAtomSymbol(innerCtxID);
|
|
137
|
+
innerCtx.trailer().forEach(trailer => {
|
|
138
|
+
if (trailer.LParen() && trailer.RParen()) {
|
|
139
|
+
const params = trailer.parameters();
|
|
135
140
|
if (params) {
|
|
136
141
|
this.visit(params);
|
|
137
142
|
}
|
|
138
143
|
}
|
|
139
144
|
});
|
|
145
|
+
this.setResult(ctx, tmpSymbol);
|
|
140
146
|
}
|
|
141
147
|
};
|
|
142
|
-
visitValueAtomExpr = (ctx) => {
|
|
143
|
-
let value = null;
|
|
144
|
-
const ctxValueExpr = ctx.value_expr();
|
|
145
|
-
const cxtAtomExpr = ctx.atom_expr();
|
|
146
|
-
if (ctxValueExpr) {
|
|
147
|
-
this.visit(ctxValueExpr);
|
|
148
|
-
value = this.getResult(ctxValueExpr);
|
|
149
|
-
}
|
|
150
|
-
else if (cxtAtomExpr) {
|
|
151
|
-
this.visit(cxtAtomExpr);
|
|
152
|
-
value = this.getResult(cxtAtomExpr);
|
|
153
|
-
}
|
|
154
|
-
this.setResult(ctx, value);
|
|
155
|
-
};
|
|
156
148
|
visitUnaryOperatorExpr = (ctx) => {
|
|
157
149
|
this.visit(ctx.data_expr());
|
|
158
150
|
};
|
|
@@ -168,9 +160,6 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
168
160
|
this.visit(ctx.data_expr(0));
|
|
169
161
|
this.visit(ctx.data_expr(1));
|
|
170
162
|
};
|
|
171
|
-
visitDataExpr = (ctx) => {
|
|
172
|
-
return;
|
|
173
|
-
};
|
|
174
163
|
visitFunction_def_expr = (ctx) => {
|
|
175
164
|
const functionName = ctx.ID().getText();
|
|
176
165
|
let funcDefinedParameters = [];
|
|
@@ -196,6 +185,12 @@ export class SymbolValidatorVisitor extends BaseVisitor {
|
|
|
196
185
|
this.addSymbolVariable(item.getSymbol(), item.getText(), null);
|
|
197
186
|
});
|
|
198
187
|
};
|
|
188
|
+
visitCreate_graphic_expr = (ctx) => {
|
|
189
|
+
const ctxID = ctx.ID();
|
|
190
|
+
if (ctxID) {
|
|
191
|
+
this.addSymbolVariable(ctxID.getSymbol(), ctxID.getText(), null);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
199
194
|
getSymbols() {
|
|
200
195
|
return this.symbolTable;
|
|
201
196
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { prepareFile, ParseErrorStrategy, TokenErrorListener } from "../helpers.js";
|
|
2
|
+
import { ParseError } from "../utils.js";
|
|
3
|
+
import { SymbolValidatorResolveVisitor } from "./SymbolValidatorResolveVisitor.js";
|
|
4
|
+
import { SymbolValidatorVisitor } from "./SymbolValidatorVisitor.js";
|
|
5
|
+
export async function validateScript(filePath, scriptData, options) {
|
|
6
|
+
const { parser } = prepareFile(scriptData);
|
|
7
|
+
parser.removeErrorListeners();
|
|
8
|
+
parser.errorHandler = new ParseErrorStrategy();
|
|
9
|
+
parser.addErrorListener(new TokenErrorListener());
|
|
10
|
+
const tree = parser.script();
|
|
11
|
+
const visitor = new SymbolValidatorVisitor(true, null, options.environment);
|
|
12
|
+
await visitor.resolveImportsAndLoad(filePath, scriptData);
|
|
13
|
+
visitor.enterFile(filePath);
|
|
14
|
+
visitor.onImportFile = (visitor, filePath, textData) => {
|
|
15
|
+
visitor.enterFile(filePath);
|
|
16
|
+
let hasError = false;
|
|
17
|
+
let hasParseError = false;
|
|
18
|
+
if (textData !== null) {
|
|
19
|
+
const { parser } = prepareFile(textData);
|
|
20
|
+
const tree = parser.script();
|
|
21
|
+
try {
|
|
22
|
+
visitor.visit(tree);
|
|
23
|
+
visitor.exitFile();
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
console.log('got an error while parsing tree: ', err);
|
|
27
|
+
hasParseError = true;
|
|
28
|
+
hasError = true;
|
|
29
|
+
throw new ParseError(`Error parsing validation in imported file: ${err}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
console.log('file does not exist!');
|
|
34
|
+
hasError = true;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
hasError, hasParseError
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
visitor.visit(tree);
|
|
41
|
+
const symbolTable = visitor.getSymbols();
|
|
42
|
+
symbolTable.clearUndefined();
|
|
43
|
+
const visitorResolver = new SymbolValidatorResolveVisitor(true, null, options.environment);
|
|
44
|
+
visitorResolver.loadedFiles = visitor.loadedFiles;
|
|
45
|
+
visitorResolver.enterFile(filePath);
|
|
46
|
+
visitorResolver.setSymbols(visitor.getSymbols());
|
|
47
|
+
visitorResolver.onImportFile = visitor.onImportFile;
|
|
48
|
+
visitorResolver.visit(tree);
|
|
49
|
+
return visitorResolver;
|
|
50
|
+
}
|