circuitscript 0.3.2 → 0.4.1

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 (147) hide show
  1. package/dist/cjs/BaseVisitor.js +394 -262
  2. package/dist/cjs/LexerDiagnosticListener.js +375 -0
  3. package/dist/cjs/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
  4. package/dist/cjs/annotate/DefaultPostAnnotationCallback.js +126 -0
  5. package/dist/cjs/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
  6. package/dist/cjs/annotate/utils.js +70 -0
  7. package/dist/cjs/antlr/CircuitScriptLexer.js +279 -286
  8. package/dist/cjs/antlr/CircuitScriptParser.js +1954 -3535
  9. package/dist/cjs/antlr/CircuitScriptParserVisitor.js +7 -0
  10. package/dist/cjs/cache/deserializer.js +34 -0
  11. package/dist/cjs/cache/hash.js +8 -0
  12. package/dist/cjs/cache/serializer.js +122 -0
  13. package/dist/cjs/cache/storage.js +45 -0
  14. package/dist/cjs/cache/types.js +4 -0
  15. package/dist/cjs/{environment.js → environment/environment.js} +18 -6
  16. package/dist/cjs/environment/esm-environment.js +21 -0
  17. package/dist/cjs/environment/helpers.js +8 -0
  18. package/dist/cjs/execute.js +49 -15
  19. package/dist/cjs/globals.js +9 -1
  20. package/dist/cjs/helpers.js +3 -485
  21. package/dist/cjs/importResolver.js +102 -0
  22. package/dist/cjs/index.js +12 -7
  23. package/dist/cjs/lexer.js +48 -12
  24. package/dist/cjs/main.js +14 -4
  25. package/dist/cjs/objects/ClassComponent.js +1 -1
  26. package/dist/cjs/objects/ExecutionScope.js +0 -1
  27. package/dist/cjs/objects/types.js +17 -1
  28. package/dist/cjs/parser.js +18 -4
  29. package/dist/cjs/pipeline.js +284 -0
  30. package/dist/cjs/regenerate-tests.js +4 -3
  31. package/dist/cjs/render/KiCadNetListOutputHandler.js +30 -0
  32. package/dist/cjs/render/PaperSizes.js +46 -0
  33. package/dist/cjs/{draw_symbols.js → render/draw_symbols.js} +58 -36
  34. package/dist/cjs/{export.js → render/export.js} +2 -2
  35. package/dist/cjs/{geometry.js → render/geometry.js} +5 -5
  36. package/dist/cjs/{graph.js → render/graph.js} +7 -7
  37. package/dist/cjs/{layout.js → render/layout.js} +8 -8
  38. package/dist/cjs/{render.js → render/render.js} +9 -8
  39. package/dist/cjs/rules-check/no-connect-on-connected-pin.js +1 -1
  40. package/dist/cjs/rules-check/unconnected-pins.js +1 -1
  41. package/dist/cjs/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
  42. package/dist/cjs/semantic-tokens/getSemanticTokens.js +55 -0
  43. package/dist/cjs/sizing.js +2 -2
  44. package/dist/cjs/utils.js +2 -2
  45. package/dist/cjs/validate/SymbolValidatorResolveVisitor.js +6 -0
  46. package/dist/cjs/validate/SymbolValidatorVisitor.js +34 -39
  47. package/dist/cjs/validate/validateScript.js +54 -0
  48. package/dist/cjs/validate.js +5 -4
  49. package/dist/cjs/visitor.js +140 -204
  50. package/dist/esm/BaseVisitor.js +396 -264
  51. package/dist/esm/LexerDiagnosticListener.js +371 -0
  52. package/dist/esm/{ComponentAnnotater.js → annotate/ComponentAnnotater.js} +29 -15
  53. package/dist/esm/annotate/DefaultPostAnnotationCallback.js +122 -0
  54. package/dist/esm/{RefdesAnnotationVisitor.js → annotate/RefdesAnnotationVisitor.js} +8 -82
  55. package/dist/esm/annotate/utils.js +66 -0
  56. package/dist/esm/antlr/CircuitScriptLexer.js +279 -286
  57. package/dist/esm/antlr/CircuitScriptParser.js +1962 -3522
  58. package/dist/esm/antlr/{CircuitScriptVisitor.js → CircuitScriptParserVisitor.js} +14 -35
  59. package/dist/esm/cache/deserializer.js +30 -0
  60. package/dist/esm/cache/hash.js +4 -0
  61. package/dist/esm/cache/serializer.js +118 -0
  62. package/dist/esm/cache/storage.js +39 -0
  63. package/dist/esm/cache/types.js +1 -0
  64. package/dist/esm/{environment.js → environment/environment.js} +18 -6
  65. package/dist/esm/environment/esm-environment.js +17 -0
  66. package/dist/esm/environment/helpers.js +4 -0
  67. package/dist/esm/execute.js +49 -15
  68. package/dist/esm/globals.js +8 -0
  69. package/dist/esm/helpers.js +5 -474
  70. package/dist/esm/importResolver.js +96 -0
  71. package/dist/esm/index.js +12 -7
  72. package/dist/esm/lexer.js +51 -12
  73. package/dist/esm/main.js +13 -3
  74. package/dist/esm/objects/ClassComponent.js +1 -1
  75. package/dist/esm/objects/ExecutionScope.js +0 -1
  76. package/dist/esm/objects/types.js +21 -1
  77. package/dist/esm/parser.js +19 -5
  78. package/dist/esm/pipeline.js +276 -0
  79. package/dist/esm/regenerate-tests.js +3 -2
  80. package/dist/esm/render/KiCadNetListOutputHandler.js +20 -0
  81. package/dist/esm/render/PaperSizes.js +41 -0
  82. package/dist/esm/{draw_symbols.js → render/draw_symbols.js} +58 -36
  83. package/dist/esm/{export.js → render/export.js} +2 -2
  84. package/dist/esm/{geometry.js → render/geometry.js} +5 -5
  85. package/dist/esm/{graph.js → render/graph.js} +7 -7
  86. package/dist/esm/{layout.js → render/layout.js} +8 -8
  87. package/dist/esm/{render.js → render/render.js} +8 -7
  88. package/dist/esm/rules-check/no-connect-on-connected-pin.js +1 -1
  89. package/dist/esm/rules-check/unconnected-pins.js +1 -1
  90. package/dist/esm/{SemanticTokenVisitor.js → semantic-tokens/SemanticTokenVisitor.js} +12 -14
  91. package/dist/esm/semantic-tokens/getSemanticTokens.js +51 -0
  92. package/dist/esm/sizing.js +2 -2
  93. package/dist/esm/utils.js +2 -2
  94. package/dist/esm/validate/SymbolValidatorResolveVisitor.js +3 -0
  95. package/dist/esm/validate/SymbolValidatorVisitor.js +36 -41
  96. package/dist/esm/validate/validateScript.js +50 -0
  97. package/dist/esm/validate.js +4 -3
  98. package/dist/esm/visitor.js +142 -206
  99. package/dist/libs/std.cst +15 -19
  100. package/dist/types/BaseVisitor.d.ts +25 -18
  101. package/dist/types/BomGeneration.d.ts +1 -1
  102. package/dist/types/LexerDiagnosticListener.d.ts +85 -0
  103. package/dist/types/{ComponentAnnotater.d.ts → annotate/ComponentAnnotater.d.ts} +1 -1
  104. package/dist/types/annotate/DefaultPostAnnotationCallback.d.ts +7 -0
  105. package/dist/types/{RefdesAnnotationVisitor.d.ts → annotate/RefdesAnnotationVisitor.d.ts} +6 -8
  106. package/dist/types/annotate/utils.d.ts +6 -0
  107. package/dist/types/antlr/CircuitScriptLexer.d.ts +71 -70
  108. package/dist/types/antlr/CircuitScriptParser.d.ts +357 -515
  109. package/dist/types/antlr/{CircuitScriptVisitor.d.ts → CircuitScriptParserVisitor.d.ts} +27 -69
  110. package/dist/types/cache/deserializer.d.ts +5 -0
  111. package/dist/types/cache/hash.d.ts +1 -0
  112. package/dist/types/cache/serializer.d.ts +3 -0
  113. package/dist/types/cache/storage.d.ts +4 -0
  114. package/dist/types/cache/types.d.ts +20 -0
  115. package/dist/types/{environment.d.ts → environment/environment.d.ts} +5 -4
  116. package/dist/types/environment/esm-environment.d.ts +4 -0
  117. package/dist/types/environment/helpers.d.ts +2 -0
  118. package/dist/types/execute.d.ts +3 -2
  119. package/dist/types/globals.d.ts +1 -0
  120. package/dist/types/helpers.d.ts +31 -36
  121. package/dist/types/importResolver.d.ts +4 -0
  122. package/dist/types/index.d.ts +12 -7
  123. package/dist/types/lexer.d.ts +9 -5
  124. package/dist/types/objects/ClassComponent.d.ts +1 -1
  125. package/dist/types/objects/ExecutionScope.d.ts +1 -4
  126. package/dist/types/objects/types.d.ts +16 -2
  127. package/dist/types/parser.d.ts +9 -2
  128. package/dist/types/pipeline.d.ts +9 -0
  129. package/dist/types/render/KiCadNetListOutputHandler.d.ts +10 -0
  130. package/dist/types/render/PaperSizes.d.ts +12 -0
  131. package/dist/types/{draw_symbols.d.ts → render/draw_symbols.d.ts} +4 -4
  132. package/dist/types/{export.d.ts → render/export.d.ts} +1 -1
  133. package/dist/types/{geometry.d.ts → render/geometry.d.ts} +2 -2
  134. package/dist/types/{graph.d.ts → render/graph.d.ts} +6 -6
  135. package/dist/types/{layout.d.ts → render/layout.d.ts} +10 -10
  136. package/dist/types/{render.d.ts → render/render.d.ts} +1 -1
  137. package/dist/types/{SemanticTokenVisitor.d.ts → semantic-tokens/SemanticTokenVisitor.d.ts} +6 -6
  138. package/dist/types/semantic-tokens/getSemanticTokens.d.ts +6 -0
  139. package/dist/types/sizing.d.ts +1 -1
  140. package/dist/types/utils.d.ts +1 -1
  141. package/dist/types/validate/SymbolValidatorResolveVisitor.d.ts +3 -0
  142. package/dist/types/validate/SymbolValidatorVisitor.d.ts +8 -8
  143. package/dist/types/validate/validateScript.d.ts +3 -0
  144. package/dist/types/visitor.d.ts +8 -14
  145. package/libs/std.cst +15 -19
  146. package/package.json +3 -6
  147. package/dist/cjs/antlr/CircuitScriptVisitor.js +0 -7
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateScript = void 0;
4
+ const helpers_js_1 = require("../helpers.js");
5
+ const utils_js_1 = require("../utils.js");
6
+ const SymbolValidatorResolveVisitor_js_1 = require("./SymbolValidatorResolveVisitor.js");
7
+ const SymbolValidatorVisitor_js_1 = require("./SymbolValidatorVisitor.js");
8
+ async function validateScript(filePath, scriptData, options) {
9
+ const { parser } = (0, helpers_js_1.prepareFile)(scriptData);
10
+ parser.removeErrorListeners();
11
+ parser.errorHandler = new helpers_js_1.ParseErrorStrategy();
12
+ parser.addErrorListener(new helpers_js_1.TokenErrorListener());
13
+ const tree = parser.script();
14
+ const visitor = new SymbolValidatorVisitor_js_1.SymbolValidatorVisitor(true, null, options.environment);
15
+ await visitor.resolveImportsAndLoad(filePath, scriptData);
16
+ visitor.enterFile(filePath);
17
+ visitor.onImportFile = (visitor, filePath, textData) => {
18
+ visitor.enterFile(filePath);
19
+ let hasError = false;
20
+ let hasParseError = false;
21
+ if (textData !== null) {
22
+ const { parser } = (0, helpers_js_1.prepareFile)(textData);
23
+ const tree = parser.script();
24
+ try {
25
+ visitor.visit(tree);
26
+ visitor.exitFile();
27
+ }
28
+ catch (err) {
29
+ console.log('got an error while parsing tree: ', err);
30
+ hasParseError = true;
31
+ hasError = true;
32
+ throw new utils_js_1.ParseError(`Error parsing validation in imported file: ${err}`);
33
+ }
34
+ }
35
+ else {
36
+ console.log('file does not exist!');
37
+ hasError = true;
38
+ }
39
+ return {
40
+ hasError, hasParseError
41
+ };
42
+ };
43
+ visitor.visit(tree);
44
+ const symbolTable = visitor.getSymbols();
45
+ symbolTable.clearUndefined();
46
+ const visitorResolver = new SymbolValidatorResolveVisitor_js_1.SymbolValidatorResolveVisitor(true, null, options.environment);
47
+ visitorResolver.loadedFiles = visitor.loadedFiles;
48
+ visitorResolver.enterFile(filePath);
49
+ visitorResolver.setSymbols(visitor.getSymbols());
50
+ visitorResolver.onImportFile = visitor.onImportFile;
51
+ visitorResolver.visit(tree);
52
+ return visitorResolver;
53
+ }
54
+ exports.validateScript = validateScript;
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const commander_1 = require("commander");
5
5
  const fs_1 = require("fs");
6
- const helpers_js_1 = require("./helpers.js");
7
- const environment_js_1 = require("./environment.js");
6
+ const getSemanticTokens_js_1 = require("./semantic-tokens/getSemanticTokens.js");
7
+ const validateScript_js_1 = require("./validate/validateScript.js");
8
+ const environment_js_1 = require("./environment/environment.js");
8
9
  const types_js_1 = require("./objects/types.js");
9
10
  async function validate() {
10
11
  const env = new environment_js_1.NodeScriptEnvironment();
@@ -67,7 +68,7 @@ async function validate() {
67
68
  showStats: options.stats,
68
69
  environment: env,
69
70
  };
70
- const visitor = await (0, helpers_js_1.validateScript)(inputFilePath, scriptData, scriptOptions);
71
+ const visitor = await (0, validateScript_js_1.validateScript)(inputFilePath, scriptData, scriptOptions);
71
72
  const symbols = visitor.getSymbols().getSymbols();
72
73
  const undefinedSymbols = [];
73
74
  console.log('----- symbols -----');
@@ -85,7 +86,7 @@ async function validate() {
85
86
  }
86
87
  });
87
88
  console.log('----- tokens -----');
88
- const { parsedTokens } = await (0, helpers_js_1.getSemanticTokens)(scriptData, scriptOptions);
89
+ const { parsedTokens } = await (0, getSemanticTokens_js_1.getSemanticTokens)(inputFilePath, scriptData, scriptOptions);
89
90
  console.log('----- dump tokens -----');
90
91
  parsedTokens.forEach(item => {
91
92
  const { line, column, tokenType, tokenModifiers, textValue } = item;
@@ -8,23 +8,18 @@ const PinTypes_js_1 = require("./objects/PinTypes.js");
8
8
  const types_js_1 = require("./objects/types.js");
9
9
  const globals_js_1 = require("./globals.js");
10
10
  const utils_js_1 = require("./utils.js");
11
- const draw_symbols_js_1 = require("./draw_symbols.js");
11
+ const draw_symbols_js_1 = require("./render/draw_symbols.js");
12
12
  const BaseVisitor_js_1 = require("./BaseVisitor.js");
13
13
  const utils_js_2 = require("./utils.js");
14
14
  const helpers_js_1 = require("./helpers.js");
15
15
  const Frame_js_1 = require("./objects/Frame.js");
16
- const ComponentAnnotater_js_1 = require("./ComponentAnnotater.js");
16
+ const ComponentAnnotater_js_1 = require("./annotate/ComponentAnnotater.js");
17
17
  const ComponentMatchConditions_js_1 = require("./ComponentMatchConditions.js");
18
18
  class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
19
19
  constructor(silent = false, onErrorHandler = null, environment) {
20
20
  super(silent, onErrorHandler, environment);
21
21
  this.componentCreationIndex = 0;
22
22
  this.creationCtx = new Map();
23
- this.visitKeyword_assignment_expr = (ctx) => {
24
- const id = ctx.ID().getText();
25
- const value = this.visitResult(ctx.data_expr());
26
- this.setResult(ctx, [id, value]);
27
- };
28
23
  this.visitPin_select_expr = (ctx) => {
29
24
  let pinId = null;
30
25
  const ctxData = ctx.data_expr();
@@ -159,22 +154,19 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
159
154
  if (ctx.path_block() === null) {
160
155
  this.getExecutor().closeOpenPathBlocks();
161
156
  }
162
- const ctxPathBlock = ctx.path_block();
163
- const ctxNotPathBlock = ctx.graph_linear_expression();
164
- if (ctxPathBlock) {
165
- this.visit(ctxPathBlock);
166
- }
167
- if (ctxNotPathBlock) {
168
- this.visit(ctxNotPathBlock);
169
- }
157
+ this.visitChildren(ctx);
170
158
  if (ctx.start && ctx.stop) {
171
159
  const startToken = ctx.start;
172
160
  const stopToken = ctx.stop;
173
- const annotationKey = this.getRefdesFileAnnotation(this.getCurrentFile(), startToken.line, startToken.column, stopToken.line, stopToken.column);
174
- if (this.refdesFileAnnotations.has(annotationKey)) {
175
- let refdesValue = this.refdesFileAnnotations.get(annotationKey);
176
- refdesValue = refdesValue.split(',')[0];
177
- this.setCurrentComponentRefdes(refdesValue, true);
161
+ if (this.filePathStack.length > 0) {
162
+ const useFilePath = this.getCurrentFile();
163
+ const annotationKey = this.getRefdesFileAnnotationKey(useFilePath, startToken.line, startToken.column, stopToken.line, stopToken.column);
164
+ if (this.refdesFileAnnotations.has(annotationKey)) {
165
+ this.log(`refdes annotation key matched: ${annotationKey}`);
166
+ let refdesValue = this.refdesFileAnnotations.get(annotationKey);
167
+ refdesValue = refdesValue.split(',')[0];
168
+ this.setCurrentComponentRefdes(refdesValue, true);
169
+ }
178
170
  }
179
171
  }
180
172
  };
@@ -182,12 +174,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
182
174
  const scope = this.getScope();
183
175
  scope.setOnPropertyHandler(this.createComponentPropertyValidator());
184
176
  scope.enterContext(ctx);
185
- ctx.property_expr().forEach(item => {
186
- this.visitResult(item);
187
- });
177
+ const ctxPropertiesBlock = ctx.properties_block();
178
+ const properties = this.visitResult(ctxPropertiesBlock);
188
179
  scope.exitContext();
189
180
  scope.popOnPropertyHandler();
190
- const properties = this.getPropertyExprList(ctx.property_expr());
191
181
  let instanceName = this.getExecutor().getUniqueInstanceName();
192
182
  const propParams = properties.get('params');
193
183
  const params = this.parseCreateComponentParams(propParams);
@@ -288,9 +278,9 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
288
278
  throw "Invalid command!";
289
279
  }
290
280
  let parameters = [];
291
- const ctxNestedProperties = ctx.nested_properties_inner();
292
- if (ctxNestedProperties) {
293
- const nestedKeyValues = this.visitResult(ctxNestedProperties);
281
+ const ctxPropertiesBlock = ctx.properties_block();
282
+ if (ctxPropertiesBlock) {
283
+ const nestedKeyValues = this.visitResult(ctxPropertiesBlock);
294
284
  nestedKeyValues.forEach((value, key) => {
295
285
  parameters.push(['keyword', key, (0, utils_js_1.unwrapValue)(value)]);
296
286
  });
@@ -385,10 +375,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
385
375
  this.visitProperty_expr = (ctx) => {
386
376
  const ctxKey = ctx.property_key_expr();
387
377
  const ctxValue = ctx.property_value_expr();
388
- const extraValue = ctx._extra;
389
- if (extraValue) {
390
- console.log('extra', extraValue.text);
391
- }
392
378
  const scope = this.getScope();
393
379
  this.getScope().enterContext(ctxKey);
394
380
  this.getScope().enterContext(ctxValue);
@@ -423,18 +409,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
423
409
  this.getScope().exitContext();
424
410
  this.setResult(ctx, value);
425
411
  };
426
- this.visitNested_properties_inner = (ctx) => {
412
+ this.visitProperties_block = (ctx) => {
427
413
  const result = new Map();
428
- ctx.property_expr().forEach((item) => {
414
+ const keyCounter = new Map();
415
+ ctx.property_expr().forEach(item => {
429
416
  const property = this.visitResult(item);
430
417
  for (const [key, value] of property) {
431
- result.set(key, value);
418
+ let useKey = key;
419
+ const counterValue = keyCounter.get(key) ?? 0;
420
+ keyCounter.set(key, counterValue + 1);
421
+ if (counterValue > 0) {
422
+ useKey = key + ':' + counterValue;
423
+ }
424
+ result.set(useKey, value);
432
425
  }
433
426
  });
434
427
  this.setResult(ctx, result);
435
428
  };
436
429
  this.visitNested_properties = (ctx) => {
437
- this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
430
+ this.passResult(ctx, ctx.children[0]);
438
431
  };
439
432
  this.visitProperty_key_expr = (ctx) => {
440
433
  const ctxID = ctx.ID();
@@ -458,22 +451,25 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
458
451
  const ctxDataExpr = ctx.data_expr();
459
452
  const ctxAssignmentExpr = ctx.assignment_expr();
460
453
  if (ctxDataExpr) {
461
- dataResult = this.visitResult(ctxDataExpr);
462
454
  componentCtx = ctxDataExpr;
455
+ this.setResult(ctxDataExpr, { keepReference: true });
456
+ const reference = this.visitResult(ctxDataExpr);
457
+ if (reference.found) {
458
+ dataResult = (0, utils_js_1.unwrapValue)(reference);
459
+ }
460
+ else {
461
+ const { trailers = [], rootValue = null } = reference;
462
+ if (rootValue instanceof ClassComponent_js_1.ClassComponent && trailers.length > 0
463
+ && trailers[0] === globals_js_1.ModuleContainsKeyword) {
464
+ dataResult = rootValue;
465
+ this.placeModuleContains(dataResult);
466
+ }
467
+ }
463
468
  }
464
469
  else if (ctxAssignmentExpr) {
465
470
  dataResult = this.visitResult(ctxAssignmentExpr);
466
471
  componentCtx = ctxAssignmentExpr;
467
472
  }
468
- if (dataResult instanceof types_js_1.AnyReference) {
469
- const { trailers = [], rootValue = null } = dataResult;
470
- if (rootValue instanceof ClassComponent_js_1.ClassComponent
471
- && trailers.length > 0
472
- && trailers[0] === globals_js_1.ModuleContainsKeyword) {
473
- dataResult = rootValue;
474
- this.placeModuleContains(dataResult);
475
- }
476
- }
477
473
  dataResult = (0, utils_js_1.unwrapValue)(dataResult);
478
474
  if (dataResult === null || dataResult === undefined) {
479
475
  this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
@@ -487,18 +483,12 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
487
483
  const modifiers = ctx.component_modifier_expr();
488
484
  modifiers.forEach(modifier => {
489
485
  const modifierText = modifier.ID(0).getText();
490
- const ctxValueExpr = modifier.value_expr();
491
- const ctxID2 = modifier.ID(1);
492
- let result = null;
493
- if (ctxValueExpr) {
494
- result = this.visitResult(ctxValueExpr);
495
- }
496
- else if (ctxID2) {
497
- result = ctxID2.getText();
498
- }
486
+ const ctxDataExpr = modifier.data_expr();
487
+ this.setResult(ctxDataExpr, { keepReference: true });
488
+ const result = this.visitResult(ctxDataExpr);
499
489
  let shouldIgnoreWireOrientation = false;
500
490
  if (modifierText === globals_js_1.ParamKeys.flip) {
501
- const flipValue = result;
491
+ const flipValue = result.name;
502
492
  if (flipValue.indexOf('x') !== -1) {
503
493
  defaultUnit.setParam(globals_js_1.ParamKeys.flipX, (0, ParamDefinition_js_1.numeric)(1));
504
494
  shouldIgnoreWireOrientation = true;
@@ -513,7 +503,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
513
503
  shouldIgnoreWireOrientation = true;
514
504
  }
515
505
  else if (modifierText === 'anchor') {
516
- dataResult.setParam('anchor', result);
506
+ dataResult.setParam('anchor', result.name);
517
507
  }
518
508
  if (shouldIgnoreWireOrientation) {
519
509
  defaultUnit.useWireOrientationAngle = false;
@@ -538,31 +528,28 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
538
528
  };
539
529
  this.visitUnaryOperatorExpr = (ctx) => {
540
530
  let value = this.visitResult(ctx.data_expr());
541
- const unaryOp = ctx.unary_operator();
542
- if (unaryOp) {
543
- if (unaryOp.Not()) {
544
- if (typeof value === "boolean") {
545
- value = !value;
546
- }
547
- else if (value instanceof ParamDefinition_js_1.NumericValue) {
548
- value = (value.toNumber() === 0) ? true : false;
549
- }
550
- else {
551
- throw "Failed to do Not operator";
552
- }
531
+ if (ctx.Not()) {
532
+ if (typeof value === "boolean") {
533
+ value = !value;
553
534
  }
554
- else if (unaryOp.Minus()) {
555
- if (value instanceof ParamDefinition_js_1.NumericValue) {
556
- value = value.neg();
557
- }
558
- else {
559
- throw "Failed to do Negation operator";
560
- }
535
+ else if (value instanceof ParamDefinition_js_1.NumericValue) {
536
+ value = (value.toNumber() === 0) ? true : false;
537
+ }
538
+ else {
539
+ throw "Failed to do Not operator";
540
+ }
541
+ }
542
+ else if (ctx.Minus()) {
543
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
544
+ value = value.neg();
545
+ }
546
+ else {
547
+ throw "Failed to do Negation operator";
561
548
  }
562
549
  }
563
550
  this.setResult(ctx, value);
564
551
  };
565
- this.visitDataExpr = (ctx) => {
552
+ this.visitCreate_expr = (ctx) => {
566
553
  let value;
567
554
  const ctxCreateComponentExpr = ctx.create_component_expr();
568
555
  const ctxCreateGraphicExpr = ctx.create_graphic_expr();
@@ -581,6 +568,10 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
581
568
  }
582
569
  this.setResult(ctx, value);
583
570
  };
571
+ this.visitCreateExpr = (ctx) => {
572
+ const result = this.visitResult(ctx.create_expr());
573
+ this.setResult(ctx, result);
574
+ };
584
575
  this.visitBinaryOperatorExpr = (ctx) => {
585
576
  const ctx0 = ctx.data_expr(0);
586
577
  const ctx1 = ctx.data_expr(1);
@@ -592,24 +583,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
592
583
  if (value2 instanceof ParamDefinition_js_1.NumericValue) {
593
584
  value2 = value2.toNumber();
594
585
  }
595
- const binaryOperatorType = ctx.binary_operator();
596
586
  let result = null;
597
- if (binaryOperatorType.Equals()) {
587
+ if (ctx.Equals()) {
598
588
  result = value1 == value2;
599
589
  }
600
- else if (binaryOperatorType.NotEquals()) {
590
+ else if (ctx.NotEquals()) {
601
591
  result = value1 != value2;
602
592
  }
603
- else if (binaryOperatorType.GreaterThan()) {
593
+ else if (ctx.GreaterThan()) {
604
594
  result = value1 > value2;
605
595
  }
606
- else if (binaryOperatorType.GreatOrEqualThan()) {
596
+ else if (ctx.GreatOrEqualThan()) {
607
597
  result = value1 >= value2;
608
598
  }
609
- else if (binaryOperatorType.LessThan()) {
599
+ else if (ctx.LessThan()) {
610
600
  result = value1 < value2;
611
601
  }
612
- else if (binaryOperatorType.LessOrEqualThan()) {
602
+ else if (ctx.LessOrEqualThan()) {
613
603
  result = value1 <= value2;
614
604
  }
615
605
  this.setResult(ctx, result);
@@ -703,8 +693,8 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
703
693
  }
704
694
  const executionStack = this.executionStack;
705
695
  const functionCounter = { counter: 0 };
706
- const resolveNet = this.createNetResolver(this.executionStack);
707
- const resolveComponentPinNet = this.createComponentPinNetResolver(this.executionStack);
696
+ const resolveNet = this.createNetResolver(executionStack);
697
+ const resolveComponentPinNet = this.createComponentPinNetResolver(executionStack);
708
698
  const __runFunc = (passedInParameters, options) => {
709
699
  const executor = this.getExecutor();
710
700
  const functionCounterIndex = functionCounter['counter'];
@@ -719,41 +709,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
719
709
  };
720
710
  this.getExecutor().createFunction(this.getExecutor().namespace, functionName, __runFunc, ctx, uniqueFunctionID);
721
711
  };
722
- this.visitPin_select_expr2 = (ctx) => {
723
- const ctxStringValue = ctx.STRING_VALUE();
724
- const ctxIntegerValue = ctx.INTEGER_VALUE();
725
- let pinIdValue;
726
- let pinId = null;
727
- if (ctxStringValue) {
728
- pinIdValue = this.prepareStringValue(ctxStringValue.getText());
729
- }
730
- else if (ctxIntegerValue) {
731
- pinIdValue = Number(ctxIntegerValue.getText());
732
- }
733
- if (pinIdValue !== undefined) {
734
- pinId = new PinDefinition_js_1.PinId(pinIdValue);
735
- }
736
- else {
737
- throw new utils_js_2.RuntimeExecutionError("Invalid select pin", ctx);
738
- }
739
- this.setResult(ctx, pinId);
740
- };
741
712
  this.visitAt_block_pin_expr = (ctx) => {
742
713
  const executor = this.getExecutor();
743
714
  const [currentComponent, currentPin] = executor.getCurrentPoint();
744
715
  executor.closeOpenPathBlocks();
745
- const atPin = this.visitResult(ctx.pin_select_expr2());
716
+ const propKey = this.visitResult(ctx.property_key_expr());
717
+ const atPin = new PinDefinition_js_1.PinId(propKey);
746
718
  executor.atComponent(currentComponent, atPin, {
747
719
  addSequence: true
748
720
  });
749
721
  executor.log('at block pin expressions');
750
- const ctxAtBlockSimple = ctx.at_block_pin_expression_simple();
751
- const ctxAtBlockComplex = ctx.at_block_pin_expression_complex();
752
- if (ctxAtBlockSimple) {
753
- this.visit(ctxAtBlockSimple);
722
+ const ctxExpression = ctx.expression();
723
+ const ctxExpressionsBlock = ctx.expressions_block();
724
+ if (ctxExpression) {
725
+ this.visit(ctxExpression);
754
726
  }
755
- else if (ctxAtBlockComplex) {
756
- this.visit(ctxAtBlockComplex);
727
+ else if (ctxExpressionsBlock) {
728
+ this.visit(ctxExpressionsBlock);
757
729
  }
758
730
  executor.log('end at block pin expressions');
759
731
  executor.atComponent(currentComponent, currentPin);
@@ -782,63 +754,33 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
782
754
  executor.scope.setCurrent(currentComponent, currentPin);
783
755
  executor.log('leaving at block');
784
756
  };
785
- this.visitAt_block_pin_expression_simple = (ctx) => {
786
- const ctxExpression = ctx.expression();
787
- if (ctxExpression) {
788
- this.visit(ctxExpression);
789
- }
790
- else if (ctx.NOT_CONNECTED()) {
791
- return;
792
- }
793
- };
794
- this.visitAt_block_pin_expression_complex = (ctx) => {
795
- this.visit(ctx.expressions_block());
796
- };
797
- this.visitWire_expr_direction_only = (ctx) => {
798
- const value = ctx.ID().getText();
799
- if (value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) {
800
- this.setResult(ctx, [value]);
801
- }
802
- else {
803
- throw 'Invalid direction for wire';
804
- }
805
- };
806
- this.visitWire_expr_direction_value = (ctx) => {
807
- const direction = ctx.ID().getText();
808
- if (this.acceptedDirections.indexOf(direction) !== -1) {
809
- let useValue = null;
810
- const ctxIntegerValue = ctx.INTEGER_VALUE();
811
- const ctxDataExpr = ctx.data_expr();
812
- if (ctxIntegerValue) {
813
- useValue = Number(ctxIntegerValue);
757
+ this.visitWire_expr = (ctx) => {
758
+ const segments = [];
759
+ ctx.ID().forEach((ctxId, index) => {
760
+ const value = ctxId.getText();
761
+ const ctxDataExpr = ctx.data_expr(index);
762
+ if ((value === globals_js_1.WireAutoDirection.Auto || value === globals_js_1.WireAutoDirection.Auto_) && ctxDataExpr === null) {
763
+ segments.push([value]);
814
764
  }
815
- else if (ctxDataExpr) {
765
+ else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
766
+ let useValue = null;
816
767
  useValue = this.visitResult(ctxDataExpr);
817
768
  if (useValue instanceof ParamDefinition_js_1.NumericValue) {
818
769
  useValue = useValue.toNumber();
819
770
  }
771
+ segments.push([value, new helpers_js_1.UnitDimension(useValue)]);
820
772
  }
821
- if (useValue !== null) {
822
- this.setResult(ctx, [direction, new helpers_js_1.UnitDimension(useValue)]);
823
- return;
824
- }
825
- }
826
- throw "Invalid direction or value for wire";
827
- };
828
- this.visitWire_expr = (ctx) => {
829
- const wireAtomExpr = ctx.wire_atom_expr();
830
- const segments = wireAtomExpr.map(wireSegment => {
831
- return this.visitResult(wireSegment);
832
773
  });
833
774
  const newWire = this.getExecutor().addWire(segments);
834
775
  this.creationCtx.set(newWire, ctx);
835
776
  };
836
777
  this.visitPoint_expr = (ctx) => {
837
- const ID = ctx.ID();
838
- const ctxData = ctx.data_expr();
778
+ const ctxDataExpr = ctx.data_expr();
779
+ this.setResult(ctxDataExpr, { keepReference: true });
780
+ const result = this.visitResult(ctxDataExpr);
839
781
  let pointValue;
840
- if (ctxData) {
841
- const resultValue = this.visitResult(ctxData);
782
+ if (result.found) {
783
+ const resultValue = (0, utils_js_1.unwrapValue)(result);
842
784
  if (typeof resultValue === 'string') {
843
785
  pointValue = resultValue;
844
786
  }
@@ -846,16 +788,11 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
846
788
  throw new utils_js_2.RuntimeExecutionError('Invalid value for point');
847
789
  }
848
790
  }
849
- else if (ID) {
850
- pointValue = ID.getText();
791
+ else {
792
+ pointValue = result.name;
851
793
  }
852
794
  return this.getExecutor().addPoint(pointValue);
853
795
  };
854
- this.visitProperty_set_expr = (ctx) => {
855
- const result = this.visitResult(ctx.data_expr());
856
- const resolvedProperty = this.visitResult(ctx.atom_expr());
857
- this.getExecutor().setProperty(resolvedProperty, result);
858
- };
859
796
  this.visitDouble_dot_property_set_expr = (ctx) => {
860
797
  const result = this.visitResult(ctx.data_expr());
861
798
  const propertyName = ctx.ID().getText();
@@ -874,14 +811,15 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
874
811
  this.getExecutor().exitFrame(frameId);
875
812
  };
876
813
  this.visitNet_namespace_expr = (ctx) => {
877
- let dataValue = null;
814
+ let dataValue;
878
815
  let netNamespace = null;
879
816
  const hasPlus = ctx.Addition();
880
817
  const ctxDataExpr = ctx.data_expr();
881
818
  if (ctxDataExpr) {
819
+ this.setResult(ctxDataExpr, { keepReference: true });
882
820
  dataValue = this.visitResult(ctxDataExpr);
883
- if (dataValue instanceof types_js_1.UndeclaredReference) {
884
- netNamespace = "/" + dataValue.reference.name;
821
+ if (!dataValue.found) {
822
+ netNamespace = "/" + dataValue.name;
885
823
  }
886
824
  else if (typeof dataValue === "string") {
887
825
  netNamespace = "/" + dataValue;
@@ -1008,7 +946,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1008
946
  executor.popBreakContext();
1009
947
  };
1010
948
  this.visitAnnotation_comment_expr = (ctx) => {
1011
- const refdesID = ctx.ID().getText();
949
+ const refdesID = ctx.getText().replace('#=', '').trim();
1012
950
  this.setCurrentComponentRefdes(refdesID);
1013
951
  };
1014
952
  this.visitPart_set_expr = (ctx) => {
@@ -1022,26 +960,21 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1022
960
  (0, ComponentMatchConditions_js_1.applyPartConditions)(instances, paramKeys, partConditions);
1023
961
  };
1024
962
  this.visitPart_match_block = (ctx) => {
1025
- const results = ctx.part_sub_expr().map(ctxExpr => {
1026
- return this.visitResult(ctxExpr);
1027
- });
963
+ const results = ctx.part_sub_expr().reduce((accum, ctxExpr) => {
964
+ const result = this.visitResult(ctxExpr);
965
+ if (result !== undefined) {
966
+ accum.push(result);
967
+ }
968
+ return accum;
969
+ }, []);
1028
970
  this.setResult(ctx, results);
1029
971
  };
1030
972
  this.visitPart_sub_expr = (ctx) => {
1031
- const ctxForm1 = ctx.part_condition_expr();
1032
- const ctxForm2 = ctx.part_condition_key_only_expr();
1033
- const ctxForm3 = ctx.part_value_expr();
1034
- let result;
1035
- if (ctxForm1) {
1036
- result = this.visitResult(ctxForm1);
1037
- }
1038
- else if (ctxForm2) {
1039
- result = this.visitResult(ctxForm2);
1040
- }
1041
- else if (ctxForm3) {
1042
- result = this.visitResult(ctxForm3);
973
+ this.visitChildren(ctx);
974
+ const result = this.getResult(ctx.children[0]);
975
+ if (result !== undefined) {
976
+ this.setResult(ctx, result);
1043
977
  }
1044
- this.setResult(ctx, result);
1045
978
  };
1046
979
  this.visitPart_set_key = (ctx) => {
1047
980
  const ctxID = ctx.ID();
@@ -1073,10 +1006,17 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1073
1006
  };
1074
1007
  this.visitPart_value_expr = (ctx) => {
1075
1008
  const key = this.visitResult(ctx.part_set_key());
1076
- const values = ctx.data_expr().map(ctxData => {
1077
- return this.visitResult(ctxData);
1078
- });
1079
- this.setResult(ctx, { key, endValue: values });
1009
+ const ctxPartMatchBlock = ctx.part_match_block();
1010
+ if (ctxPartMatchBlock) {
1011
+ const children = this.visitResult(ctxPartMatchBlock);
1012
+ this.setResult(ctx, { key, children });
1013
+ }
1014
+ else {
1015
+ const values = ctx.data_expr().map(ctxData => {
1016
+ return this.visitResult(ctxData);
1017
+ });
1018
+ this.setResult(ctx, { key, endValue: values });
1019
+ }
1080
1020
  };
1081
1021
  this.visitPart_condition_expr = (ctx) => {
1082
1022
  const allKeys = ctx._key_id.map(ctx => {
@@ -1116,14 +1056,6 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1116
1056
  });
1117
1057
  this.setResult(ctx, tmpKeyValues);
1118
1058
  };
1119
- this.visitPart_condition_key_only_expr = (ctx) => {
1120
- const key = this.visitResult(ctx.part_set_key());
1121
- const children = this.visitResult(ctx.part_match_block());
1122
- this.setResult(ctx, {
1123
- key,
1124
- children,
1125
- });
1126
- };
1127
1059
  this.pinTypes = [
1128
1060
  PinTypes_js_1.PinTypes.Any,
1129
1061
  PinTypes_js_1.PinTypes.IO,
@@ -1385,19 +1317,23 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1385
1317
  currentComponent.forceSaveRefdesAnnotation = forceSave;
1386
1318
  }
1387
1319
  }
1388
- async checkLibraryHasRefdesFile(filePath) {
1320
+ getPathRefdesFile(filePath) {
1321
+ const mainDir = this.environment.dirname(filePath);
1322
+ const mainExt = this.environment.extname(filePath);
1323
+ const mainBasename = this.environment.basename(filePath, mainExt);
1324
+ return this.environment.join(mainDir, `${mainBasename}${globals_js_1.RefdesFileSuffix}`);
1325
+ }
1326
+ checkLibraryInRefdesFile(filePath) {
1389
1327
  if (this.filePathStack.length === 0) {
1390
1328
  return;
1391
1329
  }
1392
- const mainFilePath = this.environment.getAbsolutePath(this.filePathStack[0]);
1393
- const mainDir = this.environment.dirname(mainFilePath);
1394
- const mainExt = this.environment.extname(mainFilePath);
1395
- const mainBasename = this.environment.basename(mainFilePath, mainExt);
1396
- const refdesFilePath = this.environment.join(mainDir, `${mainBasename}${globals_js_1.RefdesFileSuffix}`);
1397
- const exists = await this.environment.exists(refdesFilePath);
1330
+ const [baseFile] = this.filePathStack;
1331
+ const mainDir = this.environment.dirname(baseFile);
1332
+ const refdesFilePath = this.getPathRefdesFile(baseFile);
1333
+ const exists = this.loadedFiles.has(refdesFilePath);
1398
1334
  if (exists) {
1399
1335
  this.log(`Main schematic has refdes file: ${refdesFilePath}`);
1400
- const fileData = await this.environment.readFile(refdesFilePath);
1336
+ const fileData = this.loadedFiles.get(refdesFilePath);
1401
1337
  const jsonData = JSON.parse(fileData);
1402
1338
  const relativeLibraryPath = this.environment.relative(mainDir, filePath);
1403
1339
  const { libraries = [] } = jsonData;
@@ -1409,7 +1345,7 @@ class ParserVisitor extends BaseVisitor_js_1.BaseVisitor {
1409
1345
  for (const refdes in items) {
1410
1346
  const val = items[refdes];
1411
1347
  const parts = val.split(':');
1412
- const key = this.getRefdesFileAnnotation(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
1348
+ const key = this.getRefdesFileAnnotationKey(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
1413
1349
  this.refdesFileAnnotations.set(key, refdes);
1414
1350
  }
1415
1351
  break;