circuitscript 0.1.5 → 0.1.7

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.
Files changed (96) hide show
  1. package/dist/cjs/BaseVisitor.js +127 -73
  2. package/dist/cjs/SemanticTokenVisitor.js +19 -13
  3. package/dist/cjs/antlr/CircuitScriptParser.js +711 -671
  4. package/dist/cjs/builtinMethods.js +29 -25
  5. package/dist/cjs/environment.js +118 -0
  6. package/dist/cjs/execute.js +53 -12
  7. package/dist/cjs/geometry.js +1 -0
  8. package/dist/cjs/globals.js +11 -6
  9. package/dist/cjs/helpers.js +135 -127
  10. package/dist/cjs/index.js +5 -0
  11. package/dist/cjs/layout.js +37 -12
  12. package/dist/cjs/main.js +31 -19
  13. package/dist/cjs/objects/ExecutionScope.js +33 -0
  14. package/dist/cjs/objects/ParamDefinition.js +15 -15
  15. package/dist/cjs/parser.js +27 -21
  16. package/dist/cjs/regenerate-tests.js +9 -6
  17. package/dist/cjs/render.js +3 -1
  18. package/dist/cjs/sizing.js +5 -58
  19. package/dist/cjs/utils.js +85 -30
  20. package/dist/cjs/validate/SymbolTable.js +96 -0
  21. package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +14 -0
  22. package/dist/cjs/validate/SymbolValidatorVisitor.js +170 -0
  23. package/dist/cjs/validate.js +52 -44
  24. package/dist/cjs/visitor.js +140 -24
  25. package/dist/esm/{BaseVisitor.mjs → BaseVisitor.js} +98 -45
  26. package/dist/esm/{SemanticTokenVisitor.mjs → SemanticTokenVisitor.js} +17 -11
  27. package/dist/esm/antlr/{CircuitScriptParser.mjs → CircuitScriptParser.js} +711 -671
  28. package/dist/esm/{builtinMethods.mjs → builtinMethods.js} +20 -16
  29. package/dist/esm/{draw_symbols.mjs → draw_symbols.js} +7 -7
  30. package/dist/esm/environment.js +110 -0
  31. package/dist/esm/{execute.mjs → execute.js} +66 -25
  32. package/dist/esm/{export.mjs → export.js} +2 -2
  33. package/dist/esm/{geometry.mjs → geometry.js} +6 -5
  34. package/dist/esm/{globals.mjs → globals.js} +6 -1
  35. package/dist/esm/helpers.js +377 -0
  36. package/dist/esm/index.js +20 -0
  37. package/dist/esm/{layout.mjs → layout.js} +42 -20
  38. package/dist/esm/{lexer.mjs → lexer.js} +2 -2
  39. package/dist/esm/{main.mjs → main.js} +33 -21
  40. package/dist/esm/objects/{ClassComponent.mjs → ClassComponent.js} +5 -4
  41. package/dist/esm/objects/{ExecutionScope.mjs → ExecutionScope.js} +33 -0
  42. package/dist/esm/objects/{Frame.mjs → Frame.js} +1 -1
  43. package/dist/esm/objects/{ParamDefinition.mjs → ParamDefinition.js} +1 -1
  44. package/dist/esm/objects/{PinDefinition.mjs → PinDefinition.js} +1 -1
  45. package/dist/esm/parser.js +71 -0
  46. package/dist/esm/{regenerate-tests.mjs → regenerate-tests.js} +10 -7
  47. package/dist/esm/{render.mjs → render.js} +11 -9
  48. package/dist/esm/{sizing.mjs → sizing.js} +6 -34
  49. package/dist/esm/{utils.mjs → utils.js} +61 -17
  50. package/dist/esm/validate/SymbolTable.js +90 -0
  51. package/dist/esm/validate/SymbolValidatorResolveVisitor.js +10 -0
  52. package/dist/esm/validate/SymbolValidatorVisitor.js +163 -0
  53. package/dist/esm/validate.js +86 -0
  54. package/dist/esm/{visitor.mjs → visitor.js} +151 -35
  55. package/dist/fonts/Arial.ttf +0 -0
  56. package/dist/fonts/Inter-Bold.ttf +0 -0
  57. package/dist/fonts/Inter-Regular.ttf +0 -0
  58. package/dist/fonts/OpenSans-Regular.ttf +0 -0
  59. package/dist/fonts/Roboto-Regular.ttf +0 -0
  60. package/dist/libs/lib.cst +423 -0
  61. package/dist/types/BaseVisitor.d.ts +34 -21
  62. package/dist/types/SemanticTokenVisitor.d.ts +6 -5
  63. package/dist/types/antlr/CircuitScriptParser.d.ts +4 -2
  64. package/dist/types/builtinMethods.d.ts +3 -2
  65. package/dist/types/environment.d.ts +31 -0
  66. package/dist/types/globals.d.ts +4 -1
  67. package/dist/types/helpers.d.ts +12 -14
  68. package/dist/types/index.d.ts +5 -0
  69. package/dist/types/objects/ClassComponent.d.ts +1 -0
  70. package/dist/types/objects/ExecutionScope.d.ts +11 -0
  71. package/dist/types/objects/types.d.ts +6 -1
  72. package/dist/types/parser.d.ts +7 -11
  73. package/dist/types/sizing.d.ts +0 -3
  74. package/dist/types/utils.d.ts +30 -6
  75. package/dist/types/validate/SymbolTable.d.ts +40 -0
  76. package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +7 -0
  77. package/dist/types/validate/SymbolValidatorVisitor.d.ts +32 -0
  78. package/dist/types/validate.d.ts +1 -1
  79. package/package.json +14 -13
  80. package/dist/cjs/SymbolValidatorVisitor.js +0 -233
  81. package/dist/esm/SymbolValidatorVisitor.mjs +0 -222
  82. package/dist/esm/helpers.mjs +0 -364
  83. package/dist/esm/index.mjs +0 -15
  84. package/dist/esm/parser.mjs +0 -64
  85. package/dist/esm/validate.mjs +0 -74
  86. package/dist/types/SymbolValidatorVisitor.d.ts +0 -61
  87. package/dist/types/layout.d.ts +0 -148
  88. /package/dist/esm/antlr/{CircuitScriptLexer.mjs → CircuitScriptLexer.js} +0 -0
  89. /package/dist/esm/antlr/{CircuitScriptVisitor.mjs → CircuitScriptVisitor.js} +0 -0
  90. /package/dist/esm/{fonts.mjs → fonts.js} +0 -0
  91. /package/dist/esm/{logger.mjs → logger.js} +0 -0
  92. /package/dist/esm/objects/{Net.mjs → Net.js} +0 -0
  93. /package/dist/esm/objects/{PinTypes.mjs → PinTypes.js} +0 -0
  94. /package/dist/esm/objects/{Wire.mjs → Wire.js} +0 -0
  95. /package/dist/esm/objects/{types.mjs → types.js} +0 -0
  96. /package/dist/esm/{server.mjs → server.js} +0 -0
@@ -1,14 +1,14 @@
1
- import { ClassComponent } from './objects/ClassComponent.mjs';
2
- import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.mjs';
3
- import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
4
- import { PinTypes } from './objects/PinTypes.mjs';
5
- import { DeclaredReference, UndeclaredReference } from './objects/types.mjs';
6
- import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, WireAutoDirection } from './globals.mjs';
7
- import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.mjs';
8
- import { BaseVisitor } from './BaseVisitor.mjs';
9
- import { getPortType } from './utils.mjs';
10
- import { UnitDimension } from './helpers.mjs';
11
- import { FrameParamKeys } from './objects/Frame.mjs';
1
+ import { ClassComponent } from './objects/ClassComponent.js';
2
+ import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
3
+ import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
4
+ import { PinTypes } from './objects/PinTypes.js';
5
+ import { DeclaredReference, UndeclaredReference } from './objects/types.js';
6
+ import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
7
+ import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
8
+ import { BaseVisitor } from './BaseVisitor.js';
9
+ import { getPortType, RuntimeExecutionError } from './utils.js';
10
+ import { UnitDimension } from './helpers.js';
11
+ import { FrameParamKeys } from './objects/Frame.js';
12
12
  export class ParserVisitor extends BaseVisitor {
13
13
  visitKeyword_assignment_expr = (ctx) => {
14
14
  const id = ctx.ID().getText();
@@ -41,9 +41,14 @@ export class ParserVisitor extends BaseVisitor {
41
41
  visitTo_component_expr = (ctx) => {
42
42
  ctx.component_select_expr().forEach(item => {
43
43
  const [component, pin] = this.visitResult(item);
44
- this.getExecutor().toComponent(component, pin, {
45
- addSequence: true
46
- });
44
+ try {
45
+ this.getExecutor().toComponent(component, pin, {
46
+ addSequence: true
47
+ });
48
+ }
49
+ catch (err) {
50
+ throw new RuntimeExecutionError(err.message, ctx.start, ctx.stop);
51
+ }
47
52
  });
48
53
  return this.getExecutor().getCurrentPoint();
49
54
  };
@@ -58,7 +63,10 @@ export class ParserVisitor extends BaseVisitor {
58
63
  componentPin = this.visitResult(ctxDataExprWithAssigment);
59
64
  }
60
65
  else {
61
- const component = this.getExecutor().scope.currentComponent;
66
+ let component = this.getScope().currentComponent;
67
+ if (component._pointLinkComponent) {
68
+ component = component._pointLinkComponent;
69
+ }
62
70
  let pinId = null;
63
71
  const ctxPinSelectExpr = ctx.pin_select_expr();
64
72
  if (ctxPinSelectExpr) {
@@ -106,6 +114,92 @@ export class ParserVisitor extends BaseVisitor {
106
114
  return this.getExecutor().getCurrentPoint();
107
115
  };
108
116
  visitCreate_component_expr = (ctx) => {
117
+ const scope = this.getScope();
118
+ scope.setOnPropertyHandler((path, value, ctx) => {
119
+ if (path.length === 1) {
120
+ const [, keyName] = path[0];
121
+ switch (keyName) {
122
+ case 'type':
123
+ this.validateString(value, ctx);
124
+ break;
125
+ case 'angle':
126
+ case 'width':
127
+ case 'height':
128
+ this.validateNumeric(value, ctx);
129
+ break;
130
+ case 'pins':
131
+ if (!(value instanceof Map)) {
132
+ this.validateNumeric(value, ctx);
133
+ }
134
+ break;
135
+ case 'copy':
136
+ if (value instanceof NumericValue) {
137
+ this.validateNumeric(value, ctx);
138
+ }
139
+ else if (typeof value === 'boolean') {
140
+ this.validateBoolean(value, ctx);
141
+ }
142
+ else {
143
+ throw new RuntimeExecutionError("Invalid value for 'copy' property", ctx.start, ctx.end);
144
+ }
145
+ break;
146
+ }
147
+ }
148
+ else {
149
+ const [, keyName] = path[0];
150
+ if (keyName === 'arrange') {
151
+ const [sideKeyCtx, sideKeyName] = path[1];
152
+ if (ValidPinSides.indexOf(sideKeyName) === -1) {
153
+ throw new RuntimeExecutionError(`Invalid side ${sideKeyName} in arrange`, sideKeyCtx.start, sideKeyCtx.stop);
154
+ }
155
+ else {
156
+ if (path.length > 2 && path[2][0] === 'index') {
157
+ if (Array.isArray(value)) {
158
+ const goodBlank = value.length === 1 &&
159
+ value[0] instanceof NumericValue;
160
+ if (!goodBlank) {
161
+ throw new RuntimeExecutionError(`Invalid blank specifier`, ctx.start, ctx.stop);
162
+ }
163
+ }
164
+ else {
165
+ if (!(value instanceof NumericValue)) {
166
+ throw new RuntimeExecutionError(`Invalid numeric value for arrange.${sideKeyName}`, ctx.start, ctx.stop);
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ else if (keyName === 'params') {
173
+ const [, subKeyName] = path[1];
174
+ switch (subKeyName) {
175
+ case 'mpn':
176
+ case 'refdes':
177
+ case 'footprint':
178
+ this.validateString(value, ctx);
179
+ break;
180
+ case 'place':
181
+ this.validateBoolean(value, ctx);
182
+ break;
183
+ }
184
+ }
185
+ else if (keyName === 'pins') {
186
+ if (path.length === 2) {
187
+ if (value.length === 2) {
188
+ const [pinType,] = value;
189
+ if (pinType instanceof UndeclaredReference) {
190
+ throw new RuntimeExecutionError(`Invalid pin type: ${pinType.reference.name}`, ctx.start, ctx.end);
191
+ }
192
+ }
193
+ }
194
+ }
195
+ }
196
+ });
197
+ scope.enterContext(ctx);
198
+ ctx.property_expr().forEach(item => {
199
+ this.visitResult(item);
200
+ });
201
+ scope.exitContext();
202
+ scope.popOnPropertyHandler();
109
203
  const properties = this.getPropertyExprList(ctx.property_expr());
110
204
  const pins = this.parseCreateComponentPins(properties.get('pins'));
111
205
  let instanceName = this.getExecutor().getUniqueInstanceName();
@@ -140,8 +234,13 @@ export class ParserVisitor extends BaseVisitor {
140
234
  arrange, display, type, width, height, copy,
141
235
  angle, followWireOrientation
142
236
  };
143
- const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
144
- this.setResult(ctx, createdComponent);
237
+ try {
238
+ const createdComponent = this.getExecutor().createComponent(instanceName, pins, params, props);
239
+ this.setResult(ctx, createdComponent);
240
+ }
241
+ catch (error) {
242
+ this.throwWithContext(ctx, error.message);
243
+ }
145
244
  };
146
245
  visitCreate_graphic_expr = (ctx) => {
147
246
  const ctxId = ctx.ID();
@@ -149,7 +248,7 @@ export class ParserVisitor extends BaseVisitor {
149
248
  if (ctxId !== null) {
150
249
  const varName = ctxId.getText();
151
250
  paramIds.push(varName);
152
- this.getExecutor().scope.variables.set(varName, {});
251
+ this.getScope().variables.set(varName, {});
153
252
  }
154
253
  const executor = this.getExecutor();
155
254
  const stack = [...this.executionStack];
@@ -251,7 +350,7 @@ export class ParserVisitor extends BaseVisitor {
251
350
  useValueArray = [useValueArray];
252
351
  }
253
352
  useValueArray.forEach((value, index) => {
254
- this.getExecutor().scope.variables.set(forVariableNames[index], value);
353
+ this.getScope().variables.set(forVariableNames[index], value);
255
354
  });
256
355
  const commands = this.visitResult(ctx.graphic_expressions_block());
257
356
  allCommands = allCommands.concat(commands);
@@ -310,8 +409,16 @@ export class ParserVisitor extends BaseVisitor {
310
409
  this.setResult(ctx, [keyName, expressionsBlock]);
311
410
  };
312
411
  visitProperty_expr = (ctx) => {
313
- const keyName = this.visitResult(ctx.property_key_expr());
314
- const value = this.visitResult(ctx.property_value_expr());
412
+ const ctxKey = ctx.property_key_expr();
413
+ const ctxValue = ctx.property_value_expr();
414
+ const scope = this.getScope();
415
+ this.getScope().enterContext(ctxKey);
416
+ this.getScope().enterContext(ctxValue);
417
+ const keyName = this.visitResult(ctxKey);
418
+ const value = this.visitResult(ctxValue);
419
+ scope.triggerPropertyHandler(value, ctxValue);
420
+ this.getScope().exitContext();
421
+ this.getScope().exitContext();
315
422
  if (value instanceof UndeclaredReference && (value.reference.parentValue === undefined
316
423
  && value.reference.value === undefined)) {
317
424
  throw value.throwMessage();
@@ -321,15 +428,21 @@ export class ParserVisitor extends BaseVisitor {
321
428
  this.setResult(ctx, map);
322
429
  };
323
430
  visitSingle_line_property = (ctx) => {
431
+ this.getScope().enterContext(ctx);
324
432
  let value;
325
433
  if (ctx.data_expr().length === 1) {
326
434
  value = this.visitResult(ctx.data_expr(0));
327
435
  }
328
436
  else {
329
- value = ctx.data_expr().map(item => {
330
- return this.visitResult(item);
437
+ value = ctx.data_expr().map((item, index) => {
438
+ this.getScope().enterContext(index);
439
+ const result = this.visitResult(item);
440
+ this.getScope().triggerPropertyHandler(result, item);
441
+ this.getScope().exitContext();
442
+ return result;
331
443
  });
332
444
  }
445
+ this.getScope().exitContext();
333
446
  this.setResult(ctx, value);
334
447
  };
335
448
  visitNested_properties_inner = (ctx) => {
@@ -752,6 +865,9 @@ export class ParserVisitor extends BaseVisitor {
752
865
  }
753
866
  else if (ctxDataExpr) {
754
867
  useValue = this.visitResult(ctxDataExpr);
868
+ if (useValue instanceof NumericValue) {
869
+ useValue = useValue.toNumber();
870
+ }
755
871
  }
756
872
  if (useValue !== null) {
757
873
  this.setResult(ctx, [direction, new UnitDimension(useValue)]);
@@ -893,7 +1009,7 @@ export class ParserVisitor extends BaseVisitor {
893
1009
  useValueArray = [useValueArray];
894
1010
  }
895
1011
  useValueArray.forEach((value, index) => {
896
- this.getExecutor().scope.variables.set(forVariableNames[index], value);
1012
+ this.getScope().variables.set(forVariableNames[index], value);
897
1013
  });
898
1014
  this.visit(ctx.expressions_block());
899
1015
  keepLooping = true;
@@ -1037,32 +1153,32 @@ export class ParserVisitor extends BaseVisitor {
1037
1153
  return result;
1038
1154
  }
1039
1155
  printNets() {
1040
- this.getExecutor().scope.printNets();
1156
+ this.getScope().printNets();
1041
1157
  }
1042
1158
  dumpNets() {
1043
- return this.getExecutor().scope.dumpNets();
1159
+ return this.getScope().dumpNets();
1044
1160
  }
1045
1161
  dumpUniqueNets() {
1046
- const nets = this.getExecutor().scope.getNets();
1162
+ const nets = this.getScope().getNets();
1047
1163
  return nets.reduce((accum, [, , net]) => {
1048
1164
  accum.push(net);
1049
1165
  return accum;
1050
1166
  }, []);
1051
1167
  }
1052
1168
  dumpVariables() {
1053
- return this.getExecutor().scope.variables;
1169
+ return this.getScope().variables;
1054
1170
  }
1055
1171
  dumpInstances() {
1056
- return this.getExecutor().scope.instances;
1172
+ return this.getScope().instances;
1057
1173
  }
1058
1174
  dump2() {
1059
- const instances = this.getExecutor().scope.instances;
1175
+ const instances = this.getScope().instances;
1060
1176
  const items = [];
1061
1177
  for (const [instanceName, instance] of instances) {
1062
1178
  if (instance.assignedRefDes === null) {
1063
1179
  continue;
1064
1180
  }
1065
- const pinNets = this.resolveNets(this.getExecutor().scope, instance);
1181
+ const pinNets = this.resolveNets(this.getScope(), instance);
1066
1182
  const componentItem = {
1067
1183
  name: instanceName,
1068
1184
  refdes: instance.assignedRefDes,
@@ -1077,9 +1193,9 @@ export class ParserVisitor extends BaseVisitor {
1077
1193
  }
1078
1194
  getNetList() {
1079
1195
  const netlist = [];
1080
- const instances = this.getExecutor().scope.instances;
1196
+ const instances = this.getScope().instances;
1081
1197
  for (const [instanceName, instance] of instances) {
1082
- const pinNets = this.resolveNets(this.getExecutor().scope, instance);
1198
+ const pinNets = this.resolveNets(this.getScope(), instance);
1083
1199
  const componentItem = {
1084
1200
  instanceName,
1085
1201
  instance,
@@ -1110,7 +1226,7 @@ export class ParserVisitor extends BaseVisitor {
1110
1226
  annotateComponents() {
1111
1227
  this.log('===== annotate components =====');
1112
1228
  const annotater = new ComponentAnnotater();
1113
- const instances = this.getExecutor().scope.instances;
1229
+ const instances = this.getScope().instances;
1114
1230
  const toAnnotate = [];
1115
1231
  for (const [, instance] of instances) {
1116
1232
  if (instance.typeProp === ComponentTypes.net
@@ -1147,7 +1263,7 @@ export class ParserVisitor extends BaseVisitor {
1147
1263
  this.log('');
1148
1264
  }
1149
1265
  applySheetFrameComponent() {
1150
- const baseScope = this.getExecutor().scope;
1266
+ const baseScope = this.getScope();
1151
1267
  const document = baseScope.variables.get(GlobalDocumentName);
1152
1268
  let frameComponent = null;
1153
1269
  if (document && document[FrameParamKeys.SheetType]) {
Binary file
Binary file
Binary file
Binary file
Binary file