circuitscript 0.0.25 → 0.0.27
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/LICENSE +1 -1
- package/dist/cjs/BaseVisitor.js +16 -12
- package/dist/cjs/SemanticTokenVisitor.js +3 -3
- package/dist/cjs/antlr/CircuitScriptLexer.js +189 -166
- package/dist/cjs/antlr/CircuitScriptParser.js +1295 -719
- package/dist/cjs/draw_symbols.js +42 -14
- package/dist/cjs/execute.js +91 -30
- package/dist/cjs/export.js +91 -5
- package/dist/cjs/geometry.js +45 -26
- package/dist/cjs/globals.js +1 -2
- package/dist/cjs/helpers.js +6 -2
- package/dist/cjs/layout.js +37 -17
- package/dist/cjs/main.js +21 -9
- package/dist/cjs/objects/ClassComponent.js +8 -0
- package/dist/cjs/objects/types.js +8 -1
- package/dist/cjs/render.js +1 -1
- package/dist/cjs/visitor.js +131 -23
- package/dist/esm/BaseVisitor.mjs +17 -13
- package/dist/esm/SemanticTokenVisitor.mjs +3 -3
- package/dist/esm/antlr/CircuitScriptLexer.mjs +189 -166
- package/dist/esm/antlr/CircuitScriptParser.mjs +1287 -716
- package/dist/esm/antlr/CircuitScriptVisitor.mjs +6 -1
- package/dist/esm/draw_symbols.mjs +44 -16
- package/dist/esm/execute.mjs +90 -26
- package/dist/esm/export.mjs +89 -6
- package/dist/esm/geometry.mjs +44 -25
- package/dist/esm/globals.mjs +1 -2
- package/dist/esm/helpers.mjs +7 -3
- package/dist/esm/layout.mjs +35 -16
- package/dist/esm/main.mjs +21 -9
- package/dist/esm/objects/ClassComponent.mjs +8 -0
- package/dist/esm/objects/types.mjs +7 -0
- package/dist/esm/render.mjs +2 -2
- package/dist/esm/visitor.mjs +133 -25
- package/dist/types/BaseVisitor.d.ts +2 -5
- package/dist/types/SemanticTokenVisitor.d.ts +2 -2
- package/dist/types/antlr/CircuitScriptLexer.d.ts +29 -22
- package/dist/types/antlr/CircuitScriptParser.d.ts +121 -44
- package/dist/types/antlr/CircuitScriptVisitor.d.ts +12 -2
- package/dist/types/draw_symbols.d.ts +11 -6
- package/dist/types/execute.d.ts +6 -4
- package/dist/types/export.d.ts +27 -1
- package/dist/types/geometry.d.ts +12 -9
- package/dist/types/globals.d.ts +2 -3
- package/dist/types/layout.d.ts +5 -0
- package/dist/types/objects/ClassComponent.d.ts +5 -0
- package/dist/types/objects/Wire.d.ts +2 -1
- package/dist/types/objects/types.d.ts +6 -0
- package/dist/types/visitor.d.ts +7 -3
- package/libs/lib.cst +28 -10
- package/package.json +1 -1
package/dist/cjs/layout.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.LayoutEngine = void 0;
|
|
3
|
+
exports.CalculatePinPositions = exports.RenderJunction = exports.RenderFrameType = exports.RenderFrame = exports.RenderText = exports.RenderComponent = exports.RenderWire = exports.RenderObject = exports.getBounds = exports.LayoutEngine = void 0;
|
|
4
4
|
const graphlib_1 = require("@dagrejs/graphlib");
|
|
5
5
|
const draw_symbols_js_1 = require("./draw_symbols.js");
|
|
6
6
|
const ExecutionScope_js_1 = require("./objects/ExecutionScope.js");
|
|
@@ -10,6 +10,7 @@ const geometry_js_1 = require("./geometry.js");
|
|
|
10
10
|
const logger_js_1 = require("./logger.js");
|
|
11
11
|
const Frame_js_1 = require("./objects/Frame.js");
|
|
12
12
|
const utils_js_1 = require("./utils.js");
|
|
13
|
+
const types_js_1 = require("./objects/types.js");
|
|
13
14
|
class LayoutEngine {
|
|
14
15
|
constructor() {
|
|
15
16
|
this.placeSubgraphVersion = 2;
|
|
@@ -938,16 +939,16 @@ function applyComponentParamsToSymbol(typeProp, component, symbol) {
|
|
|
938
939
|
function calculateSymbolAngle(symbol, pin, direction) {
|
|
939
940
|
let directionVector = 0;
|
|
940
941
|
switch (direction) {
|
|
941
|
-
case
|
|
942
|
+
case types_js_1.Direction.Right:
|
|
942
943
|
directionVector = 0;
|
|
943
944
|
break;
|
|
944
|
-
case
|
|
945
|
+
case types_js_1.Direction.Down:
|
|
945
946
|
directionVector = 90;
|
|
946
947
|
break;
|
|
947
|
-
case
|
|
948
|
+
case types_js_1.Direction.Left:
|
|
948
949
|
directionVector = 180;
|
|
949
950
|
break;
|
|
950
|
-
case
|
|
951
|
+
case types_js_1.Direction.Up:
|
|
951
952
|
directionVector = 270;
|
|
952
953
|
break;
|
|
953
954
|
}
|
|
@@ -1017,16 +1018,16 @@ class RenderWire extends RenderObject {
|
|
|
1017
1018
|
this.segments.forEach(segment => {
|
|
1018
1019
|
const { direction, value } = segment;
|
|
1019
1020
|
let didAddPoint = false;
|
|
1020
|
-
if (direction ===
|
|
1021
|
+
if (direction === types_js_1.Direction.Down) {
|
|
1021
1022
|
tmpY += value;
|
|
1022
1023
|
}
|
|
1023
|
-
else if (direction ===
|
|
1024
|
+
else if (direction === types_js_1.Direction.Up) {
|
|
1024
1025
|
tmpY -= value;
|
|
1025
1026
|
}
|
|
1026
|
-
else if (direction ===
|
|
1027
|
+
else if (direction === types_js_1.Direction.Left) {
|
|
1027
1028
|
tmpX -= value;
|
|
1028
1029
|
}
|
|
1029
|
-
else if (direction ===
|
|
1030
|
+
else if (direction === types_js_1.Direction.Right) {
|
|
1030
1031
|
tmpX += value;
|
|
1031
1032
|
}
|
|
1032
1033
|
else if (direction === 'auto' || direction === "auto_") {
|
|
@@ -1095,16 +1096,16 @@ class RenderWire extends RenderObject {
|
|
|
1095
1096
|
let tmpY = this.y;
|
|
1096
1097
|
excludeLastSegment.forEach(segment => {
|
|
1097
1098
|
const { direction, value } = segment;
|
|
1098
|
-
if (direction ===
|
|
1099
|
+
if (direction === types_js_1.Direction.Down) {
|
|
1099
1100
|
tmpY += value;
|
|
1100
1101
|
}
|
|
1101
|
-
else if (direction ===
|
|
1102
|
+
else if (direction === types_js_1.Direction.Up) {
|
|
1102
1103
|
tmpY -= value;
|
|
1103
1104
|
}
|
|
1104
|
-
else if (direction ===
|
|
1105
|
+
else if (direction === types_js_1.Direction.Left) {
|
|
1105
1106
|
tmpX -= value;
|
|
1106
1107
|
}
|
|
1107
|
-
else if (direction ===
|
|
1108
|
+
else if (direction === types_js_1.Direction.Right) {
|
|
1108
1109
|
tmpX += value;
|
|
1109
1110
|
}
|
|
1110
1111
|
});
|
|
@@ -1112,16 +1113,16 @@ class RenderWire extends RenderObject {
|
|
|
1112
1113
|
let valueXY = null;
|
|
1113
1114
|
const lastSegment = this.segments[this.segments.length - 1];
|
|
1114
1115
|
switch (lastSegment.direction) {
|
|
1115
|
-
case
|
|
1116
|
+
case types_js_1.Direction.Left:
|
|
1116
1117
|
useValue = tmpX - untilX;
|
|
1117
1118
|
break;
|
|
1118
|
-
case
|
|
1119
|
+
case types_js_1.Direction.Right:
|
|
1119
1120
|
useValue = untilX - tmpX;
|
|
1120
1121
|
break;
|
|
1121
|
-
case
|
|
1122
|
+
case types_js_1.Direction.Up:
|
|
1122
1123
|
useValue = untilY - tmpY;
|
|
1123
1124
|
break;
|
|
1124
|
-
case
|
|
1125
|
+
case types_js_1.Direction.Down:
|
|
1125
1126
|
useValue = tmpY - untilY;
|
|
1126
1127
|
break;
|
|
1127
1128
|
case 'auto':
|
|
@@ -1225,6 +1226,25 @@ class RenderJunction {
|
|
|
1225
1226
|
}
|
|
1226
1227
|
}
|
|
1227
1228
|
exports.RenderJunction = RenderJunction;
|
|
1229
|
+
function CalculatePinPositions(component) {
|
|
1230
|
+
const pinPositionMapping = new Map();
|
|
1231
|
+
let tmpSymbol;
|
|
1232
|
+
if (component.displayProp !== null
|
|
1233
|
+
&& component.displayProp instanceof draw_symbols_js_1.SymbolDrawing) {
|
|
1234
|
+
tmpSymbol = new draw_symbols_js_1.SymbolPlaceholder(component.displayProp);
|
|
1235
|
+
}
|
|
1236
|
+
else {
|
|
1237
|
+
const symbolPinDefinitions = generateLayoutPinDefinition(component);
|
|
1238
|
+
tmpSymbol = new draw_symbols_js_1.SymbolCustom(symbolPinDefinitions);
|
|
1239
|
+
}
|
|
1240
|
+
tmpSymbol.refreshDrawing();
|
|
1241
|
+
const pins = component.pins;
|
|
1242
|
+
pins.forEach((value, key) => {
|
|
1243
|
+
pinPositionMapping.set(key, tmpSymbol.pinPosition(key));
|
|
1244
|
+
});
|
|
1245
|
+
return pinPositionMapping;
|
|
1246
|
+
}
|
|
1247
|
+
exports.CalculatePinPositions = CalculatePinPositions;
|
|
1228
1248
|
function isPointOverlap(x, y, other) {
|
|
1229
1249
|
return (x >= other.x && y >= other.y && x <= (other.x + other.width) && y <= (other.y + other.height));
|
|
1230
1250
|
}
|
package/dist/cjs/main.js
CHANGED
|
@@ -17,9 +17,9 @@ async function main() {
|
|
|
17
17
|
commander_1.program
|
|
18
18
|
.description('generate graphical output from circuitscript files')
|
|
19
19
|
.version(version)
|
|
20
|
+
.argument('[input path]', 'Input path')
|
|
21
|
+
.argument('[output path]', 'Output path')
|
|
20
22
|
.option('-i, --input text <input text>', 'Input text directly')
|
|
21
|
-
.option('-f, --input-file <path>', 'Input file')
|
|
22
|
-
.option('-o, --output <path>', 'Output path')
|
|
23
23
|
.option('-c, --current-directory <path>', 'Set current directory')
|
|
24
24
|
.option('-k, --kicad-netlist <filename>', 'Create KiCad netlist')
|
|
25
25
|
.option('-w, --watch', 'Watch for file changes')
|
|
@@ -34,8 +34,8 @@ async function main() {
|
|
|
34
34
|
}
|
|
35
35
|
commander_1.program.parse();
|
|
36
36
|
const options = commander_1.program.opts();
|
|
37
|
+
const args = commander_1.program.args;
|
|
37
38
|
const watchFileChanges = options.watch;
|
|
38
|
-
const outputPath = options.output ?? null;
|
|
39
39
|
const dumpNets = options.dumpNets;
|
|
40
40
|
const dumpData = options.dumpData;
|
|
41
41
|
const kicadNetlist = options.kicadNetlist;
|
|
@@ -44,18 +44,26 @@ async function main() {
|
|
|
44
44
|
console.log('watching for file changes...');
|
|
45
45
|
}
|
|
46
46
|
await (0, sizing_js_1.prepareSVGEnvironment)(fontsPath);
|
|
47
|
-
let inputFilePath =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
let inputFilePath = "";
|
|
48
|
+
if (args.length > 2) {
|
|
49
|
+
console.log("Error: Extra arguments passed");
|
|
50
|
+
return;
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let scriptData;
|
|
53
|
+
if (args.length > 0 && args[0]) {
|
|
54
|
+
inputFilePath = args[0];
|
|
54
55
|
scriptData = (0, fs_1.readFileSync)(inputFilePath, { encoding: 'utf-8' });
|
|
55
56
|
if (currentDirectory === null) {
|
|
56
57
|
currentDirectory = path_1.default.dirname(inputFilePath);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
60
|
+
else if (options.input) {
|
|
61
|
+
scriptData = options.input;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.log("Error: No input provided");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
59
67
|
const scriptOptions = {
|
|
60
68
|
currentDirectory,
|
|
61
69
|
defaultLibsPath,
|
|
@@ -64,6 +72,10 @@ async function main() {
|
|
|
64
72
|
kicadNetlistPath: kicadNetlist,
|
|
65
73
|
showStats: options.stats,
|
|
66
74
|
};
|
|
75
|
+
let outputPath = null;
|
|
76
|
+
if (args.length > 0 && args[1]) {
|
|
77
|
+
outputPath = args[1];
|
|
78
|
+
}
|
|
67
79
|
const output = (0, helpers_js_1.renderScript)(scriptData, outputPath, scriptOptions);
|
|
68
80
|
if (outputPath === null && output) {
|
|
69
81
|
console.log(output);
|
|
@@ -16,6 +16,11 @@ class ClassComponent {
|
|
|
16
16
|
this.displayProp = null;
|
|
17
17
|
this.widthProp = null;
|
|
18
18
|
this.typeProp = null;
|
|
19
|
+
this.copyProp = false;
|
|
20
|
+
this.angleProp = 0;
|
|
21
|
+
this.followWireOrientationProp = true;
|
|
22
|
+
this.wireOrientationAngle = 0;
|
|
23
|
+
this.useWireOrientationAngle = true;
|
|
19
24
|
this.styles = {};
|
|
20
25
|
this.assignedRefDes = null;
|
|
21
26
|
this.instanceName = instanceName;
|
|
@@ -117,6 +122,9 @@ class ClassComponent {
|
|
|
117
122
|
component.arrangeProps = this.arrangeProps;
|
|
118
123
|
component.widthProp = this.widthProp;
|
|
119
124
|
component.typeProp = this.typeProp;
|
|
125
|
+
component.angleProp = this.angleProp;
|
|
126
|
+
component.followWireOrientationProp = this.followWireOrientationProp;
|
|
127
|
+
component.useWireOrientationAngle = this.useWireOrientationAngle;
|
|
120
128
|
if (this.displayProp) {
|
|
121
129
|
if (typeof this.displayProp === "string") {
|
|
122
130
|
component.displayProp = this.displayProp;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
3
|
+
exports.Direction = exports.ParseSymbolType = exports.UndeclaredReference = void 0;
|
|
4
4
|
class UndeclaredReference {
|
|
5
5
|
constructor(reference) {
|
|
6
6
|
this.reference = reference;
|
|
@@ -13,3 +13,10 @@ var ParseSymbolType;
|
|
|
13
13
|
ParseSymbolType["Function"] = "function";
|
|
14
14
|
ParseSymbolType["Undefined"] = "undefined";
|
|
15
15
|
})(ParseSymbolType || (exports.ParseSymbolType = ParseSymbolType = {}));
|
|
16
|
+
var Direction;
|
|
17
|
+
(function (Direction) {
|
|
18
|
+
Direction["Left"] = "left";
|
|
19
|
+
Direction["Right"] = "right";
|
|
20
|
+
Direction["Down"] = "down";
|
|
21
|
+
Direction["Up"] = "up";
|
|
22
|
+
})(Direction || (exports.Direction = Direction = {}));
|
package/dist/cjs/render.js
CHANGED
|
@@ -40,7 +40,7 @@ function generateSVGChild(canvas, components, wires, junctions, mergedWires, fra
|
|
|
40
40
|
const { symbol = null } = item;
|
|
41
41
|
if (symbol !== null && symbol) {
|
|
42
42
|
const extra = {};
|
|
43
|
-
if (item.component.
|
|
43
|
+
if (item.component.typeProp === globals_js_1.ComponentTypes.net) {
|
|
44
44
|
extra.net_name = item.component.parameters.get(globals_js_1.ParamKeys.net_name);
|
|
45
45
|
}
|
|
46
46
|
else if (item.component.parameters.has('value')) {
|
package/dist/cjs/visitor.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VisitorExecutionException = exports.ParserVisitor = void 0;
|
|
4
|
-
const execute_js_1 = require("./execute.js");
|
|
5
4
|
const ClassComponent_js_1 = require("./objects/ClassComponent.js");
|
|
6
5
|
const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
|
|
7
6
|
const PinDefinition_js_1 = require("./objects/PinDefinition.js");
|
|
@@ -34,10 +33,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
34
33
|
};
|
|
35
34
|
this.visitAdd_component_expr = (ctx) => {
|
|
36
35
|
const ctxDataWithAssignmentExpr = ctx.data_expr_with_assignment();
|
|
37
|
-
this.setParam(ctxDataWithAssignmentExpr, { clone: false });
|
|
38
36
|
this.visit(ctxDataWithAssignmentExpr);
|
|
39
37
|
const [component, pinValue] = this.getResult(ctxDataWithAssignmentExpr);
|
|
40
|
-
|
|
38
|
+
this.getExecutor().addComponentExisting(component, pinValue);
|
|
41
39
|
};
|
|
42
40
|
this.visitAt_component_expr = (ctx) => {
|
|
43
41
|
if (ctx.Point()) {
|
|
@@ -140,18 +138,22 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
140
138
|
properties.get('display') : null;
|
|
141
139
|
const type = properties.has('type') ?
|
|
142
140
|
properties.get('type') : null;
|
|
141
|
+
const copy = properties.has('copy') ?
|
|
142
|
+
properties.get('copy') : false;
|
|
143
143
|
const width = properties.has('width') ?
|
|
144
144
|
properties.get('width') : null;
|
|
145
|
+
const angle = properties.has('angle') ?
|
|
146
|
+
properties.get('angle') : null;
|
|
147
|
+
const followWireOrientation = properties.has('followWireOrientation') ?
|
|
148
|
+
properties.get('followWireOrientation') : true;
|
|
145
149
|
const props = {
|
|
146
|
-
arrange,
|
|
147
|
-
|
|
148
|
-
type,
|
|
149
|
-
width,
|
|
150
|
+
arrange, display, type, width, copy,
|
|
151
|
+
angle, followWireOrientation
|
|
150
152
|
};
|
|
151
153
|
this.setResult(ctx, this.getExecutor().createComponent(instanceName, pins, params, props));
|
|
152
154
|
};
|
|
153
155
|
this.visitCreate_graphic_expr = (ctx) => {
|
|
154
|
-
const commands = ctx.
|
|
156
|
+
const commands = ctx.graphic_expr().reduce((accum, item) => {
|
|
155
157
|
this.visit(item);
|
|
156
158
|
const [commandName, parameters] = this.getResult(item);
|
|
157
159
|
const keywordParams = new Map();
|
|
@@ -171,7 +173,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
171
173
|
drawing.source = ctx.getText();
|
|
172
174
|
this.setResult(ctx, drawing);
|
|
173
175
|
};
|
|
174
|
-
this.
|
|
176
|
+
this.visitGraphic_expr = (ctx) => {
|
|
175
177
|
let commandName = null;
|
|
176
178
|
const command = ctx._command;
|
|
177
179
|
if (command) {
|
|
@@ -180,9 +182,20 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
180
182
|
else {
|
|
181
183
|
throw "Invalid command!";
|
|
182
184
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
let parameters = [];
|
|
186
|
+
const ctxNestedProperties = ctx.nested_properties_inner();
|
|
187
|
+
if (ctxNestedProperties) {
|
|
188
|
+
this.visit(ctxNestedProperties);
|
|
189
|
+
const nestedKeyValues = this.getResult(ctxNestedProperties);
|
|
190
|
+
nestedKeyValues.forEach((value, key) => {
|
|
191
|
+
parameters.push(['keyword', key, value]);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
const ctxParameters = ctx.parameters();
|
|
196
|
+
this.visit(ctxParameters);
|
|
197
|
+
parameters = this.getResult(ctxParameters);
|
|
198
|
+
}
|
|
186
199
|
this.setResult(ctx, [commandName, parameters]);
|
|
187
200
|
};
|
|
188
201
|
this.visitProperty_expr = (ctx) => {
|
|
@@ -211,7 +224,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
211
224
|
}
|
|
212
225
|
this.setResult(ctx, value);
|
|
213
226
|
};
|
|
214
|
-
this.
|
|
227
|
+
this.visitNested_properties_inner = (ctx) => {
|
|
215
228
|
const result = new Map();
|
|
216
229
|
ctx.property_expr().forEach((item) => {
|
|
217
230
|
this.visit(item);
|
|
@@ -222,6 +235,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
222
235
|
});
|
|
223
236
|
this.setResult(ctx, result);
|
|
224
237
|
};
|
|
238
|
+
this.visitNested_properties = (ctx) => {
|
|
239
|
+
const ctxNested = ctx.nested_properties_inner();
|
|
240
|
+
this.visit(ctxNested);
|
|
241
|
+
this.setResult(ctx, this.getResult(ctxNested));
|
|
242
|
+
};
|
|
225
243
|
this.visitProperty_key_expr = (ctx) => {
|
|
226
244
|
const ctxID = ctx.ID();
|
|
227
245
|
const ctxIntegerValue = ctx.INTEGER_VALUE();
|
|
@@ -253,14 +271,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
253
271
|
this.visit(ctxAssignmentExpr);
|
|
254
272
|
component = this.getResult(ctxAssignmentExpr);
|
|
255
273
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
allowClone = clone;
|
|
260
|
-
}
|
|
261
|
-
if (allowClone && component instanceof ClassComponent_js_1.ClassComponent
|
|
262
|
-
&& (0, execute_js_1.isNetOnlyComponent)(component)) {
|
|
263
|
-
component = this.getExecutor().cloneComponent(component);
|
|
274
|
+
if (component instanceof ClassComponent_js_1.ClassComponent
|
|
275
|
+
&& component.copyProp) {
|
|
276
|
+
component = this.getExecutor().copyComponent(component);
|
|
264
277
|
}
|
|
265
278
|
if (component && component instanceof ClassComponent_js_1.ClassComponent) {
|
|
266
279
|
const modifiers = ctx.component_modifier_expr();
|
|
@@ -276,18 +289,40 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
276
289
|
else if (ctxID2) {
|
|
277
290
|
result = ctxID2.getText();
|
|
278
291
|
}
|
|
292
|
+
let shouldIgnoreWireOrientation = false;
|
|
279
293
|
if (modifierText === 'flip') {
|
|
280
294
|
const flipValue = result;
|
|
281
295
|
if (flipValue.indexOf('x') !== -1) {
|
|
282
296
|
component.setParam('flipX', 1);
|
|
297
|
+
shouldIgnoreWireOrientation = true;
|
|
283
298
|
}
|
|
284
299
|
if (flipValue.indexOf('y') !== -1) {
|
|
285
300
|
component.setParam('flipY', 1);
|
|
301
|
+
shouldIgnoreWireOrientation = true;
|
|
286
302
|
}
|
|
287
303
|
}
|
|
288
304
|
else if (modifierText === 'angle') {
|
|
289
305
|
const angleValue = Number(result);
|
|
290
306
|
component.setParam('angle', angleValue);
|
|
307
|
+
shouldIgnoreWireOrientation = true;
|
|
308
|
+
}
|
|
309
|
+
else if (modifierText === 'anchor') {
|
|
310
|
+
if (component.displayProp
|
|
311
|
+
&& component.displayProp instanceof draw_symbols_js_1.SymbolDrawingCommands) {
|
|
312
|
+
const commands = (component.displayProp)
|
|
313
|
+
.getCommands();
|
|
314
|
+
commands.forEach(command => {
|
|
315
|
+
const positionParams = command[1];
|
|
316
|
+
const keywordParams = command[2];
|
|
317
|
+
if (command[0] === draw_symbols_js_1.PlaceHolderCommands.label
|
|
318
|
+
&& positionParams[0] === 'value') {
|
|
319
|
+
keywordParams.set('anchor', result);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (shouldIgnoreWireOrientation) {
|
|
325
|
+
component.useWireOrientationAngle = false;
|
|
291
326
|
}
|
|
292
327
|
});
|
|
293
328
|
}
|
|
@@ -358,6 +393,41 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
358
393
|
else if (binaryOperatorType.NotEquals()) {
|
|
359
394
|
result = value1 != value2;
|
|
360
395
|
}
|
|
396
|
+
else if (binaryOperatorType.GreaterThan()) {
|
|
397
|
+
result = value1 > value2;
|
|
398
|
+
}
|
|
399
|
+
else if (binaryOperatorType.GreatOrEqualThan()) {
|
|
400
|
+
result = value1 >= value2;
|
|
401
|
+
}
|
|
402
|
+
else if (binaryOperatorType.LessThan()) {
|
|
403
|
+
result = value1 < value2;
|
|
404
|
+
}
|
|
405
|
+
else if (binaryOperatorType.LessOrEqualThan()) {
|
|
406
|
+
result = value1 <= value2;
|
|
407
|
+
}
|
|
408
|
+
this.setResult(ctx, result);
|
|
409
|
+
};
|
|
410
|
+
this.visitLogicalOperatorExpr = (ctx) => {
|
|
411
|
+
const ctx0 = ctx.data_expr(0);
|
|
412
|
+
const ctx1 = ctx.data_expr(1);
|
|
413
|
+
this.visit(ctx0);
|
|
414
|
+
const value1 = this.getResult(ctx0);
|
|
415
|
+
let value2 = false;
|
|
416
|
+
let skipNext = false;
|
|
417
|
+
if (ctx.LogicalOr() && value1) {
|
|
418
|
+
skipNext = true;
|
|
419
|
+
}
|
|
420
|
+
if (!skipNext) {
|
|
421
|
+
this.visit(ctx1);
|
|
422
|
+
value2 = this.getResult(ctx1);
|
|
423
|
+
}
|
|
424
|
+
let result = null;
|
|
425
|
+
if (ctx.LogicalAnd()) {
|
|
426
|
+
result = value1 && value2;
|
|
427
|
+
}
|
|
428
|
+
else if (ctx.LogicalOr()) {
|
|
429
|
+
result = value1 || value2;
|
|
430
|
+
}
|
|
361
431
|
this.setResult(ctx, result);
|
|
362
432
|
};
|
|
363
433
|
this.visitMultiplyExpr = (ctx) => {
|
|
@@ -560,6 +630,42 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
560
630
|
}
|
|
561
631
|
this.setResult(ctx, (hasPlus ? "+" : "") + netNamespace);
|
|
562
632
|
};
|
|
633
|
+
this.visitIf_expr = (ctx) => {
|
|
634
|
+
const ctxDataExpr = ctx.data_expr();
|
|
635
|
+
this.visit(ctxDataExpr);
|
|
636
|
+
const result = this.getResult(ctxDataExpr);
|
|
637
|
+
if (result) {
|
|
638
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
const ctxInnerIfExprs = ctx.if_inner_expr();
|
|
642
|
+
let innerIfWasTrue = false;
|
|
643
|
+
for (let i = 0; i < ctxInnerIfExprs.length; i++) {
|
|
644
|
+
const tmpCtx = ctxInnerIfExprs[i];
|
|
645
|
+
this.visit(tmpCtx);
|
|
646
|
+
const innerResult = this.getResult(tmpCtx);
|
|
647
|
+
if (innerResult) {
|
|
648
|
+
innerIfWasTrue = true;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (!innerIfWasTrue) {
|
|
653
|
+
const elseCtx = ctx.else_expr();
|
|
654
|
+
if (elseCtx) {
|
|
655
|
+
this.visit(elseCtx);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
this.visitIf_inner_expr = (ctx) => {
|
|
661
|
+
const ctxDataExpr = ctx.data_expr();
|
|
662
|
+
this.visit(ctxDataExpr);
|
|
663
|
+
const result = this.getResult(ctxDataExpr);
|
|
664
|
+
if (result) {
|
|
665
|
+
this.runExpressions(this.getExecutor(), ctx.expression());
|
|
666
|
+
}
|
|
667
|
+
this.setResult(ctx, result);
|
|
668
|
+
};
|
|
563
669
|
this.pinTypes = [
|
|
564
670
|
PinTypes_js_1.PinTypes.Any,
|
|
565
671
|
PinTypes_js_1.PinTypes.IO,
|
|
@@ -588,8 +694,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
|
|
|
588
694
|
}
|
|
589
695
|
if (Array.isArray(pinDef)) {
|
|
590
696
|
const firstValue = pinDef[0];
|
|
591
|
-
if (
|
|
592
|
-
|
|
697
|
+
if (firstValue.type
|
|
698
|
+
&& firstValue.type === globals_js_1.ReferenceTypes.pinType
|
|
699
|
+
&& this.pinTypes.indexOf(firstValue.value) !== -1) {
|
|
700
|
+
pinType = firstValue.value;
|
|
593
701
|
pinName = pinDef[1];
|
|
594
702
|
if (pinDef.length > 2) {
|
|
595
703
|
altPinNames = pinDef.slice(2);
|
package/dist/esm/BaseVisitor.mjs
CHANGED
|
@@ -7,7 +7,8 @@ import { Logger } from "./logger";
|
|
|
7
7
|
import { ClassComponent } from "./objects/ClassComponent";
|
|
8
8
|
import { NumericValue, PercentageValue, PinBlankValue } from "./objects/ParamDefinition";
|
|
9
9
|
import { PinTypes } from "./objects/PinTypes";
|
|
10
|
-
import { UndeclaredReference } from "./objects/types";
|
|
10
|
+
import { Direction, UndeclaredReference } from "./objects/types";
|
|
11
|
+
import { ReferenceTypes } from './globals';
|
|
11
12
|
export class BaseVisitor extends CircuitScriptVisitor {
|
|
12
13
|
indentLevel = 0;
|
|
13
14
|
startingContext;
|
|
@@ -18,7 +19,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
18
19
|
defaultLibsPath;
|
|
19
20
|
printStream = [];
|
|
20
21
|
printToConsole = true;
|
|
21
|
-
acceptedDirections = [
|
|
22
|
+
acceptedDirections = [Direction.Up, Direction.Down,
|
|
23
|
+
Direction.Right, Direction.Left];
|
|
22
24
|
acceptedFlip = ['flipX', 'flipY'];
|
|
23
25
|
resultData = new Map;
|
|
24
26
|
paramData = new Map;
|
|
@@ -138,7 +140,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
138
140
|
if (this.pinTypesList.indexOf(atomId) !== -1) {
|
|
139
141
|
currentReference = {
|
|
140
142
|
found: true,
|
|
141
|
-
value: atomId
|
|
143
|
+
value: atomId,
|
|
144
|
+
type: ReferenceTypes.pinType,
|
|
142
145
|
};
|
|
143
146
|
}
|
|
144
147
|
else {
|
|
@@ -275,7 +278,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
275
278
|
value = new UndeclaredReference(reference);
|
|
276
279
|
}
|
|
277
280
|
else {
|
|
278
|
-
|
|
281
|
+
if (reference.type && reference.type === ReferenceTypes.pinType) {
|
|
282
|
+
value = reference;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
value = reference.value;
|
|
286
|
+
}
|
|
279
287
|
}
|
|
280
288
|
}
|
|
281
289
|
this.setResult(ctx, value);
|
|
@@ -340,15 +348,6 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
340
348
|
getResult(ctx) {
|
|
341
349
|
return this.resultData.get(ctx);
|
|
342
350
|
}
|
|
343
|
-
setParam(ctx, value) {
|
|
344
|
-
this.paramData.set(ctx, value);
|
|
345
|
-
}
|
|
346
|
-
getParam(ctx) {
|
|
347
|
-
return this.paramData.get(ctx);
|
|
348
|
-
}
|
|
349
|
-
hasParam(ctx) {
|
|
350
|
-
return this.paramData.has(ctx);
|
|
351
|
-
}
|
|
352
351
|
handleImportFile(name, throwErrors = true) {
|
|
353
352
|
let hasError = false;
|
|
354
353
|
let hasParseError = false;
|
|
@@ -420,6 +419,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
|
|
|
420
419
|
}
|
|
421
420
|
}
|
|
422
421
|
}
|
|
422
|
+
else if (tmpPassedInArgs[0] === 'keyword') {
|
|
423
|
+
const variableName = tmpPassedInArgs[1];
|
|
424
|
+
executor.log('set variable in scope, var name: ', variableName);
|
|
425
|
+
executor.scope.variables.set(variableName, tmpPassedInArgs[2]);
|
|
426
|
+
}
|
|
423
427
|
}
|
|
424
428
|
else if (tmpFuncArg.length === 2) {
|
|
425
429
|
const variableName = tmpFuncArg[0];
|
|
@@ -39,8 +39,8 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
39
39
|
};
|
|
40
40
|
visitCreate_graphic_expr = (ctx) => {
|
|
41
41
|
this.addSemanticToken(ctx.Create(), ['defaultLibrary'], 'function');
|
|
42
|
-
ctx.
|
|
43
|
-
this.visit(
|
|
42
|
+
ctx.graphic_expr().forEach(graphic_expr => {
|
|
43
|
+
this.visit(graphic_expr);
|
|
44
44
|
});
|
|
45
45
|
};
|
|
46
46
|
visitProperty_key_expr = (ctx) => {
|
|
@@ -61,7 +61,7 @@ export class SemanticTokensVisitor extends BaseVisitor {
|
|
|
61
61
|
this.addSemanticToken(useValue, [], 'property');
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
visitGraphic_expr = (ctx) => {
|
|
65
65
|
let useValue = null;
|
|
66
66
|
const ctxId = ctx.ID();
|
|
67
67
|
const ctxPin = ctx.Pin();
|