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
@@ -1,8 +1,9 @@
1
1
  #! /usr/bin/env node
2
2
  import { program } from 'commander';
3
3
  import { readFileSync, existsSync } from 'fs';
4
- import { getSemanticTokens, validateScript } from './helpers.js';
5
- import { NodeScriptEnvironment } from "./environment.js";
4
+ import { getSemanticTokens } from "./semantic-tokens/getSemanticTokens.js";
5
+ import { validateScript } from "./validate/validateScript.js";
6
+ import { NodeScriptEnvironment } from "./environment/environment.js";
6
7
  import { ParseSymbolType } from './objects/types.js';
7
8
  export default async function validate() {
8
9
  const env = new NodeScriptEnvironment();
@@ -83,7 +84,7 @@ export default async function validate() {
83
84
  }
84
85
  });
85
86
  console.log('----- tokens -----');
86
- const { parsedTokens } = await getSemanticTokens(scriptData, scriptOptions);
87
+ const { parsedTokens } = await getSemanticTokens(inputFilePath, scriptData, scriptOptions);
87
88
  console.log('----- dump tokens -----');
88
89
  parsedTokens.forEach(item => {
89
90
  const { line, column, tokenType, tokenModifiers, textValue } = item;
@@ -2,15 +2,15 @@ import { ClassComponent } from './objects/ClassComponent.js';
2
2
  import { NumberOperator, numeric, NumericValue, ParamDefinition } from './objects/ParamDefinition.js';
3
3
  import { PinDefinition, PinId, PinIdType } from './objects/PinDefinition.js';
4
4
  import { PinTypes } from './objects/PinTypes.js';
5
- import { AnyReference, DeclaredReference, UndeclaredReference } from './objects/types.js';
5
+ import { DeclaredReference, UndeclaredReference } from './objects/types.js';
6
6
  import { BlockTypes, ComponentTypes, Delimiter1, FrameType, GlobalDocumentName, ModuleContainsKeyword, NoNetText, ParamKeys, RefdesFileSuffix, ReferenceTypes, SymbolPinSide, ValidPinSides, WireAutoDirection } from './globals.js';
7
7
  import { unwrapValue } from "./utils.js";
8
- import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
8
+ import { PlaceHolderCommands, SymbolDrawingCommands } from './render/draw_symbols.js';
9
9
  import { BaseVisitor } from './BaseVisitor.js';
10
10
  import { getPortType, RuntimeExecutionError } from './utils.js';
11
11
  import { UnitDimension } from './helpers.js';
12
12
  import { FrameParamKeys } from './objects/Frame.js';
13
- import { ComponentAnnotater } from './ComponentAnnotater.js';
13
+ import { ComponentAnnotater } from './annotate/ComponentAnnotater.js';
14
14
  import { applyPartConditions, extractPartConditions, flattenConditionNodes } from './ComponentMatchConditions.js';
15
15
  export class ParserVisitor extends BaseVisitor {
16
16
  constructor(silent = false, onErrorHandler = null, environment) {
@@ -25,11 +25,6 @@ export class ParserVisitor extends BaseVisitor {
25
25
  }
26
26
  componentCreationIndex = 0;
27
27
  creationCtx = new Map();
28
- visitKeyword_assignment_expr = (ctx) => {
29
- const id = ctx.ID().getText();
30
- const value = this.visitResult(ctx.data_expr());
31
- this.setResult(ctx, [id, value]);
32
- };
33
28
  visitPin_select_expr = (ctx) => {
34
29
  let pinId = null;
35
30
  const ctxData = ctx.data_expr();
@@ -164,22 +159,19 @@ export class ParserVisitor extends BaseVisitor {
164
159
  if (ctx.path_block() === null) {
165
160
  this.getExecutor().closeOpenPathBlocks();
166
161
  }
167
- const ctxPathBlock = ctx.path_block();
168
- const ctxNotPathBlock = ctx.graph_linear_expression();
169
- if (ctxPathBlock) {
170
- this.visit(ctxPathBlock);
171
- }
172
- if (ctxNotPathBlock) {
173
- this.visit(ctxNotPathBlock);
174
- }
162
+ this.visitChildren(ctx);
175
163
  if (ctx.start && ctx.stop) {
176
164
  const startToken = ctx.start;
177
165
  const stopToken = ctx.stop;
178
- const annotationKey = this.getRefdesFileAnnotation(this.getCurrentFile(), startToken.line, startToken.column, stopToken.line, stopToken.column);
179
- if (this.refdesFileAnnotations.has(annotationKey)) {
180
- let refdesValue = this.refdesFileAnnotations.get(annotationKey);
181
- refdesValue = refdesValue.split(',')[0];
182
- this.setCurrentComponentRefdes(refdesValue, true);
166
+ if (this.filePathStack.length > 0) {
167
+ const useFilePath = this.getCurrentFile();
168
+ const annotationKey = this.getRefdesFileAnnotationKey(useFilePath, startToken.line, startToken.column, stopToken.line, stopToken.column);
169
+ if (this.refdesFileAnnotations.has(annotationKey)) {
170
+ this.log(`refdes annotation key matched: ${annotationKey}`);
171
+ let refdesValue = this.refdesFileAnnotations.get(annotationKey);
172
+ refdesValue = refdesValue.split(',')[0];
173
+ this.setCurrentComponentRefdes(refdesValue, true);
174
+ }
183
175
  }
184
176
  }
185
177
  };
@@ -187,12 +179,10 @@ export class ParserVisitor extends BaseVisitor {
187
179
  const scope = this.getScope();
188
180
  scope.setOnPropertyHandler(this.createComponentPropertyValidator());
189
181
  scope.enterContext(ctx);
190
- ctx.property_expr().forEach(item => {
191
- this.visitResult(item);
192
- });
182
+ const ctxPropertiesBlock = ctx.properties_block();
183
+ const properties = this.visitResult(ctxPropertiesBlock);
193
184
  scope.exitContext();
194
185
  scope.popOnPropertyHandler();
195
- const properties = this.getPropertyExprList(ctx.property_expr());
196
186
  let instanceName = this.getExecutor().getUniqueInstanceName();
197
187
  const propParams = properties.get('params');
198
188
  const params = this.parseCreateComponentParams(propParams);
@@ -479,9 +469,9 @@ export class ParserVisitor extends BaseVisitor {
479
469
  throw "Invalid command!";
480
470
  }
481
471
  let parameters = [];
482
- const ctxNestedProperties = ctx.nested_properties_inner();
483
- if (ctxNestedProperties) {
484
- const nestedKeyValues = this.visitResult(ctxNestedProperties);
472
+ const ctxPropertiesBlock = ctx.properties_block();
473
+ if (ctxPropertiesBlock) {
474
+ const nestedKeyValues = this.visitResult(ctxPropertiesBlock);
485
475
  nestedKeyValues.forEach((value, key) => {
486
476
  parameters.push(['keyword', key, unwrapValue(value)]);
487
477
  });
@@ -576,10 +566,6 @@ export class ParserVisitor extends BaseVisitor {
576
566
  visitProperty_expr = (ctx) => {
577
567
  const ctxKey = ctx.property_key_expr();
578
568
  const ctxValue = ctx.property_value_expr();
579
- const extraValue = ctx._extra;
580
- if (extraValue) {
581
- console.log('extra', extraValue.text);
582
- }
583
569
  const scope = this.getScope();
584
570
  this.getScope().enterContext(ctxKey);
585
571
  this.getScope().enterContext(ctxValue);
@@ -614,18 +600,25 @@ export class ParserVisitor extends BaseVisitor {
614
600
  this.getScope().exitContext();
615
601
  this.setResult(ctx, value);
616
602
  };
617
- visitNested_properties_inner = (ctx) => {
603
+ visitProperties_block = (ctx) => {
618
604
  const result = new Map();
619
- ctx.property_expr().forEach((item) => {
605
+ const keyCounter = new Map();
606
+ ctx.property_expr().forEach(item => {
620
607
  const property = this.visitResult(item);
621
608
  for (const [key, value] of property) {
622
- result.set(key, value);
609
+ let useKey = key;
610
+ const counterValue = keyCounter.get(key) ?? 0;
611
+ keyCounter.set(key, counterValue + 1);
612
+ if (counterValue > 0) {
613
+ useKey = key + ':' + counterValue;
614
+ }
615
+ result.set(useKey, value);
623
616
  }
624
617
  });
625
618
  this.setResult(ctx, result);
626
619
  };
627
620
  visitNested_properties = (ctx) => {
628
- this.setResult(ctx, this.visitResult(ctx.nested_properties_inner()));
621
+ this.passResult(ctx, ctx.children[0]);
629
622
  };
630
623
  visitProperty_key_expr = (ctx) => {
631
624
  const ctxID = ctx.ID();
@@ -649,22 +642,25 @@ export class ParserVisitor extends BaseVisitor {
649
642
  const ctxDataExpr = ctx.data_expr();
650
643
  const ctxAssignmentExpr = ctx.assignment_expr();
651
644
  if (ctxDataExpr) {
652
- dataResult = this.visitResult(ctxDataExpr);
653
645
  componentCtx = ctxDataExpr;
646
+ this.setResult(ctxDataExpr, { keepReference: true });
647
+ const reference = this.visitResult(ctxDataExpr);
648
+ if (reference.found) {
649
+ dataResult = unwrapValue(reference);
650
+ }
651
+ else {
652
+ const { trailers = [], rootValue = null } = reference;
653
+ if (rootValue instanceof ClassComponent && trailers.length > 0
654
+ && trailers[0] === ModuleContainsKeyword) {
655
+ dataResult = rootValue;
656
+ this.placeModuleContains(dataResult);
657
+ }
658
+ }
654
659
  }
655
660
  else if (ctxAssignmentExpr) {
656
661
  dataResult = this.visitResult(ctxAssignmentExpr);
657
662
  componentCtx = ctxAssignmentExpr;
658
663
  }
659
- if (dataResult instanceof AnyReference) {
660
- const { trailers = [], rootValue = null } = dataResult;
661
- if (rootValue instanceof ClassComponent
662
- && trailers.length > 0
663
- && trailers[0] === ModuleContainsKeyword) {
664
- dataResult = rootValue;
665
- this.placeModuleContains(dataResult);
666
- }
667
- }
668
664
  dataResult = unwrapValue(dataResult);
669
665
  if (dataResult === null || dataResult === undefined) {
670
666
  this.throwWithContext(componentCtx, "Could not find component: " + componentCtx.getText());
@@ -678,18 +674,12 @@ export class ParserVisitor extends BaseVisitor {
678
674
  const modifiers = ctx.component_modifier_expr();
679
675
  modifiers.forEach(modifier => {
680
676
  const modifierText = modifier.ID(0).getText();
681
- const ctxValueExpr = modifier.value_expr();
682
- const ctxID2 = modifier.ID(1);
683
- let result = null;
684
- if (ctxValueExpr) {
685
- result = this.visitResult(ctxValueExpr);
686
- }
687
- else if (ctxID2) {
688
- result = ctxID2.getText();
689
- }
677
+ const ctxDataExpr = modifier.data_expr();
678
+ this.setResult(ctxDataExpr, { keepReference: true });
679
+ const result = this.visitResult(ctxDataExpr);
690
680
  let shouldIgnoreWireOrientation = false;
691
681
  if (modifierText === ParamKeys.flip) {
692
- const flipValue = result;
682
+ const flipValue = result.name;
693
683
  if (flipValue.indexOf('x') !== -1) {
694
684
  defaultUnit.setParam(ParamKeys.flipX, numeric(1));
695
685
  shouldIgnoreWireOrientation = true;
@@ -704,7 +694,7 @@ export class ParserVisitor extends BaseVisitor {
704
694
  shouldIgnoreWireOrientation = true;
705
695
  }
706
696
  else if (modifierText === 'anchor') {
707
- dataResult.setParam('anchor', result);
697
+ dataResult.setParam('anchor', result.name);
708
698
  }
709
699
  if (shouldIgnoreWireOrientation) {
710
700
  defaultUnit.useWireOrientationAngle = false;
@@ -777,31 +767,28 @@ export class ParserVisitor extends BaseVisitor {
777
767
  }
778
768
  visitUnaryOperatorExpr = (ctx) => {
779
769
  let value = this.visitResult(ctx.data_expr());
780
- const unaryOp = ctx.unary_operator();
781
- if (unaryOp) {
782
- if (unaryOp.Not()) {
783
- if (typeof value === "boolean") {
784
- value = !value;
785
- }
786
- else if (value instanceof NumericValue) {
787
- value = (value.toNumber() === 0) ? true : false;
788
- }
789
- else {
790
- throw "Failed to do Not operator";
791
- }
770
+ if (ctx.Not()) {
771
+ if (typeof value === "boolean") {
772
+ value = !value;
792
773
  }
793
- else if (unaryOp.Minus()) {
794
- if (value instanceof NumericValue) {
795
- value = value.neg();
796
- }
797
- else {
798
- throw "Failed to do Negation operator";
799
- }
774
+ else if (value instanceof NumericValue) {
775
+ value = (value.toNumber() === 0) ? true : false;
776
+ }
777
+ else {
778
+ throw "Failed to do Not operator";
779
+ }
780
+ }
781
+ else if (ctx.Minus()) {
782
+ if (value instanceof NumericValue) {
783
+ value = value.neg();
784
+ }
785
+ else {
786
+ throw "Failed to do Negation operator";
800
787
  }
801
788
  }
802
789
  this.setResult(ctx, value);
803
790
  };
804
- visitDataExpr = (ctx) => {
791
+ visitCreate_expr = (ctx) => {
805
792
  let value;
806
793
  const ctxCreateComponentExpr = ctx.create_component_expr();
807
794
  const ctxCreateGraphicExpr = ctx.create_graphic_expr();
@@ -820,6 +807,10 @@ export class ParserVisitor extends BaseVisitor {
820
807
  }
821
808
  this.setResult(ctx, value);
822
809
  };
810
+ visitCreateExpr = (ctx) => {
811
+ const result = this.visitResult(ctx.create_expr());
812
+ this.setResult(ctx, result);
813
+ };
823
814
  visitBinaryOperatorExpr = (ctx) => {
824
815
  const ctx0 = ctx.data_expr(0);
825
816
  const ctx1 = ctx.data_expr(1);
@@ -831,24 +822,23 @@ export class ParserVisitor extends BaseVisitor {
831
822
  if (value2 instanceof NumericValue) {
832
823
  value2 = value2.toNumber();
833
824
  }
834
- const binaryOperatorType = ctx.binary_operator();
835
825
  let result = null;
836
- if (binaryOperatorType.Equals()) {
826
+ if (ctx.Equals()) {
837
827
  result = value1 == value2;
838
828
  }
839
- else if (binaryOperatorType.NotEquals()) {
829
+ else if (ctx.NotEquals()) {
840
830
  result = value1 != value2;
841
831
  }
842
- else if (binaryOperatorType.GreaterThan()) {
832
+ else if (ctx.GreaterThan()) {
843
833
  result = value1 > value2;
844
834
  }
845
- else if (binaryOperatorType.GreatOrEqualThan()) {
835
+ else if (ctx.GreatOrEqualThan()) {
846
836
  result = value1 >= value2;
847
837
  }
848
- else if (binaryOperatorType.LessThan()) {
838
+ else if (ctx.LessThan()) {
849
839
  result = value1 < value2;
850
840
  }
851
- else if (binaryOperatorType.LessOrEqualThan()) {
841
+ else if (ctx.LessOrEqualThan()) {
852
842
  result = value1 <= value2;
853
843
  }
854
844
  this.setResult(ctx, result);
@@ -942,8 +932,8 @@ export class ParserVisitor extends BaseVisitor {
942
932
  }
943
933
  const executionStack = this.executionStack;
944
934
  const functionCounter = { counter: 0 };
945
- const resolveNet = this.createNetResolver(this.executionStack);
946
- const resolveComponentPinNet = this.createComponentPinNetResolver(this.executionStack);
935
+ const resolveNet = this.createNetResolver(executionStack);
936
+ const resolveComponentPinNet = this.createComponentPinNetResolver(executionStack);
947
937
  const __runFunc = (passedInParameters, options) => {
948
938
  const executor = this.getExecutor();
949
939
  const functionCounterIndex = functionCounter['counter'];
@@ -958,41 +948,23 @@ export class ParserVisitor extends BaseVisitor {
958
948
  };
959
949
  this.getExecutor().createFunction(this.getExecutor().namespace, functionName, __runFunc, ctx, uniqueFunctionID);
960
950
  };
961
- visitPin_select_expr2 = (ctx) => {
962
- const ctxStringValue = ctx.STRING_VALUE();
963
- const ctxIntegerValue = ctx.INTEGER_VALUE();
964
- let pinIdValue;
965
- let pinId = null;
966
- if (ctxStringValue) {
967
- pinIdValue = this.prepareStringValue(ctxStringValue.getText());
968
- }
969
- else if (ctxIntegerValue) {
970
- pinIdValue = Number(ctxIntegerValue.getText());
971
- }
972
- if (pinIdValue !== undefined) {
973
- pinId = new PinId(pinIdValue);
974
- }
975
- else {
976
- throw new RuntimeExecutionError("Invalid select pin", ctx);
977
- }
978
- this.setResult(ctx, pinId);
979
- };
980
951
  visitAt_block_pin_expr = (ctx) => {
981
952
  const executor = this.getExecutor();
982
953
  const [currentComponent, currentPin] = executor.getCurrentPoint();
983
954
  executor.closeOpenPathBlocks();
984
- const atPin = this.visitResult(ctx.pin_select_expr2());
955
+ const propKey = this.visitResult(ctx.property_key_expr());
956
+ const atPin = new PinId(propKey);
985
957
  executor.atComponent(currentComponent, atPin, {
986
958
  addSequence: true
987
959
  });
988
960
  executor.log('at block pin expressions');
989
- const ctxAtBlockSimple = ctx.at_block_pin_expression_simple();
990
- const ctxAtBlockComplex = ctx.at_block_pin_expression_complex();
991
- if (ctxAtBlockSimple) {
992
- this.visit(ctxAtBlockSimple);
961
+ const ctxExpression = ctx.expression();
962
+ const ctxExpressionsBlock = ctx.expressions_block();
963
+ if (ctxExpression) {
964
+ this.visit(ctxExpression);
993
965
  }
994
- else if (ctxAtBlockComplex) {
995
- this.visit(ctxAtBlockComplex);
966
+ else if (ctxExpressionsBlock) {
967
+ this.visit(ctxExpressionsBlock);
996
968
  }
997
969
  executor.log('end at block pin expressions');
998
970
  executor.atComponent(currentComponent, currentPin);
@@ -1021,63 +993,33 @@ export class ParserVisitor extends BaseVisitor {
1021
993
  executor.scope.setCurrent(currentComponent, currentPin);
1022
994
  executor.log('leaving at block');
1023
995
  };
1024
- visitAt_block_pin_expression_simple = (ctx) => {
1025
- const ctxExpression = ctx.expression();
1026
- if (ctxExpression) {
1027
- this.visit(ctxExpression);
1028
- }
1029
- else if (ctx.NOT_CONNECTED()) {
1030
- return;
1031
- }
1032
- };
1033
- visitAt_block_pin_expression_complex = (ctx) => {
1034
- this.visit(ctx.expressions_block());
1035
- };
1036
- visitWire_expr_direction_only = (ctx) => {
1037
- const value = ctx.ID().getText();
1038
- if (value === WireAutoDirection.Auto || value === WireAutoDirection.Auto_) {
1039
- this.setResult(ctx, [value]);
1040
- }
1041
- else {
1042
- throw 'Invalid direction for wire';
1043
- }
1044
- };
1045
- visitWire_expr_direction_value = (ctx) => {
1046
- const direction = ctx.ID().getText();
1047
- if (this.acceptedDirections.indexOf(direction) !== -1) {
1048
- let useValue = null;
1049
- const ctxIntegerValue = ctx.INTEGER_VALUE();
1050
- const ctxDataExpr = ctx.data_expr();
1051
- if (ctxIntegerValue) {
1052
- useValue = Number(ctxIntegerValue);
1053
- }
1054
- else if (ctxDataExpr) {
996
+ visitWire_expr = (ctx) => {
997
+ const segments = [];
998
+ ctx.ID().forEach((ctxId, index) => {
999
+ const value = ctxId.getText();
1000
+ const ctxDataExpr = ctx.data_expr(index);
1001
+ if ((value === WireAutoDirection.Auto || value === WireAutoDirection.Auto_) && ctxDataExpr === null) {
1002
+ segments.push([value]);
1003
+ }
1004
+ else if (this.acceptedDirections.indexOf(value) !== -1 && ctxDataExpr) {
1005
+ let useValue = null;
1055
1006
  useValue = this.visitResult(ctxDataExpr);
1056
1007
  if (useValue instanceof NumericValue) {
1057
1008
  useValue = useValue.toNumber();
1058
1009
  }
1010
+ segments.push([value, new UnitDimension(useValue)]);
1059
1011
  }
1060
- if (useValue !== null) {
1061
- this.setResult(ctx, [direction, new UnitDimension(useValue)]);
1062
- return;
1063
- }
1064
- }
1065
- throw "Invalid direction or value for wire";
1066
- };
1067
- visitWire_expr = (ctx) => {
1068
- const wireAtomExpr = ctx.wire_atom_expr();
1069
- const segments = wireAtomExpr.map(wireSegment => {
1070
- return this.visitResult(wireSegment);
1071
1012
  });
1072
1013
  const newWire = this.getExecutor().addWire(segments);
1073
1014
  this.creationCtx.set(newWire, ctx);
1074
1015
  };
1075
1016
  visitPoint_expr = (ctx) => {
1076
- const ID = ctx.ID();
1077
- const ctxData = ctx.data_expr();
1017
+ const ctxDataExpr = ctx.data_expr();
1018
+ this.setResult(ctxDataExpr, { keepReference: true });
1019
+ const result = this.visitResult(ctxDataExpr);
1078
1020
  let pointValue;
1079
- if (ctxData) {
1080
- const resultValue = this.visitResult(ctxData);
1021
+ if (result.found) {
1022
+ const resultValue = unwrapValue(result);
1081
1023
  if (typeof resultValue === 'string') {
1082
1024
  pointValue = resultValue;
1083
1025
  }
@@ -1085,16 +1027,11 @@ export class ParserVisitor extends BaseVisitor {
1085
1027
  throw new RuntimeExecutionError('Invalid value for point');
1086
1028
  }
1087
1029
  }
1088
- else if (ID) {
1089
- pointValue = ID.getText();
1030
+ else {
1031
+ pointValue = result.name;
1090
1032
  }
1091
1033
  return this.getExecutor().addPoint(pointValue);
1092
1034
  };
1093
- visitProperty_set_expr = (ctx) => {
1094
- const result = this.visitResult(ctx.data_expr());
1095
- const resolvedProperty = this.visitResult(ctx.atom_expr());
1096
- this.getExecutor().setProperty(resolvedProperty, result);
1097
- };
1098
1035
  visitDouble_dot_property_set_expr = (ctx) => {
1099
1036
  const result = this.visitResult(ctx.data_expr());
1100
1037
  const propertyName = ctx.ID().getText();
@@ -1113,14 +1050,15 @@ export class ParserVisitor extends BaseVisitor {
1113
1050
  this.getExecutor().exitFrame(frameId);
1114
1051
  };
1115
1052
  visitNet_namespace_expr = (ctx) => {
1116
- let dataValue = null;
1053
+ let dataValue;
1117
1054
  let netNamespace = null;
1118
1055
  const hasPlus = ctx.Addition();
1119
1056
  const ctxDataExpr = ctx.data_expr();
1120
1057
  if (ctxDataExpr) {
1058
+ this.setResult(ctxDataExpr, { keepReference: true });
1121
1059
  dataValue = this.visitResult(ctxDataExpr);
1122
- if (dataValue instanceof UndeclaredReference) {
1123
- netNamespace = "/" + dataValue.reference.name;
1060
+ if (!dataValue.found) {
1061
+ netNamespace = "/" + dataValue.name;
1124
1062
  }
1125
1063
  else if (typeof dataValue === "string") {
1126
1064
  netNamespace = "/" + dataValue;
@@ -1259,7 +1197,7 @@ export class ParserVisitor extends BaseVisitor {
1259
1197
  }
1260
1198
  }
1261
1199
  visitAnnotation_comment_expr = (ctx) => {
1262
- const refdesID = ctx.ID().getText();
1200
+ const refdesID = ctx.getText().replace('#=', '').trim();
1263
1201
  this.setCurrentComponentRefdes(refdesID);
1264
1202
  };
1265
1203
  visitPart_set_expr = (ctx) => {
@@ -1273,26 +1211,21 @@ export class ParserVisitor extends BaseVisitor {
1273
1211
  applyPartConditions(instances, paramKeys, partConditions);
1274
1212
  };
1275
1213
  visitPart_match_block = (ctx) => {
1276
- const results = ctx.part_sub_expr().map(ctxExpr => {
1277
- return this.visitResult(ctxExpr);
1278
- });
1214
+ const results = ctx.part_sub_expr().reduce((accum, ctxExpr) => {
1215
+ const result = this.visitResult(ctxExpr);
1216
+ if (result !== undefined) {
1217
+ accum.push(result);
1218
+ }
1219
+ return accum;
1220
+ }, []);
1279
1221
  this.setResult(ctx, results);
1280
1222
  };
1281
1223
  visitPart_sub_expr = (ctx) => {
1282
- const ctxForm1 = ctx.part_condition_expr();
1283
- const ctxForm2 = ctx.part_condition_key_only_expr();
1284
- const ctxForm3 = ctx.part_value_expr();
1285
- let result;
1286
- if (ctxForm1) {
1287
- result = this.visitResult(ctxForm1);
1288
- }
1289
- else if (ctxForm2) {
1290
- result = this.visitResult(ctxForm2);
1291
- }
1292
- else if (ctxForm3) {
1293
- result = this.visitResult(ctxForm3);
1224
+ this.visitChildren(ctx);
1225
+ const result = this.getResult(ctx.children[0]);
1226
+ if (result !== undefined) {
1227
+ this.setResult(ctx, result);
1294
1228
  }
1295
- this.setResult(ctx, result);
1296
1229
  };
1297
1230
  visitPart_set_key = (ctx) => {
1298
1231
  const ctxID = ctx.ID();
@@ -1324,10 +1257,17 @@ export class ParserVisitor extends BaseVisitor {
1324
1257
  };
1325
1258
  visitPart_value_expr = (ctx) => {
1326
1259
  const key = this.visitResult(ctx.part_set_key());
1327
- const values = ctx.data_expr().map(ctxData => {
1328
- return this.visitResult(ctxData);
1329
- });
1330
- this.setResult(ctx, { key, endValue: values });
1260
+ const ctxPartMatchBlock = ctx.part_match_block();
1261
+ if (ctxPartMatchBlock) {
1262
+ const children = this.visitResult(ctxPartMatchBlock);
1263
+ this.setResult(ctx, { key, children });
1264
+ }
1265
+ else {
1266
+ const values = ctx.data_expr().map(ctxData => {
1267
+ return this.visitResult(ctxData);
1268
+ });
1269
+ this.setResult(ctx, { key, endValue: values });
1270
+ }
1331
1271
  };
1332
1272
  visitPart_condition_expr = (ctx) => {
1333
1273
  const allKeys = ctx._key_id.map(ctx => {
@@ -1367,27 +1307,23 @@ export class ParserVisitor extends BaseVisitor {
1367
1307
  });
1368
1308
  this.setResult(ctx, tmpKeyValues);
1369
1309
  };
1370
- visitPart_condition_key_only_expr = (ctx) => {
1371
- const key = this.visitResult(ctx.part_set_key());
1372
- const children = this.visitResult(ctx.part_match_block());
1373
- this.setResult(ctx, {
1374
- key,
1375
- children,
1376
- });
1377
- };
1378
- async checkLibraryHasRefdesFile(filePath) {
1310
+ getPathRefdesFile(filePath) {
1311
+ const mainDir = this.environment.dirname(filePath);
1312
+ const mainExt = this.environment.extname(filePath);
1313
+ const mainBasename = this.environment.basename(filePath, mainExt);
1314
+ return this.environment.join(mainDir, `${mainBasename}${RefdesFileSuffix}`);
1315
+ }
1316
+ checkLibraryInRefdesFile(filePath) {
1379
1317
  if (this.filePathStack.length === 0) {
1380
1318
  return;
1381
1319
  }
1382
- const mainFilePath = this.environment.getAbsolutePath(this.filePathStack[0]);
1383
- const mainDir = this.environment.dirname(mainFilePath);
1384
- const mainExt = this.environment.extname(mainFilePath);
1385
- const mainBasename = this.environment.basename(mainFilePath, mainExt);
1386
- const refdesFilePath = this.environment.join(mainDir, `${mainBasename}${RefdesFileSuffix}`);
1387
- const exists = await this.environment.exists(refdesFilePath);
1320
+ const [baseFile] = this.filePathStack;
1321
+ const mainDir = this.environment.dirname(baseFile);
1322
+ const refdesFilePath = this.getPathRefdesFile(baseFile);
1323
+ const exists = this.loadedFiles.has(refdesFilePath);
1388
1324
  if (exists) {
1389
1325
  this.log(`Main schematic has refdes file: ${refdesFilePath}`);
1390
- const fileData = await this.environment.readFile(refdesFilePath);
1326
+ const fileData = this.loadedFiles.get(refdesFilePath);
1391
1327
  const jsonData = JSON.parse(fileData);
1392
1328
  const relativeLibraryPath = this.environment.relative(mainDir, filePath);
1393
1329
  const { libraries = [] } = jsonData;
@@ -1399,7 +1335,7 @@ export class ParserVisitor extends BaseVisitor {
1399
1335
  for (const refdes in items) {
1400
1336
  const val = items[refdes];
1401
1337
  const parts = val.split(':');
1402
- const key = this.getRefdesFileAnnotation(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
1338
+ const key = this.getRefdesFileAnnotationKey(useFilePath, Number(parts[0]), Number(parts[1]), Number(parts[2]), Number(parts[3]));
1403
1339
  this.refdesFileAnnotations.set(key, refdes);
1404
1340
  }
1405
1341
  break;