circuitscript 0.2.0 → 0.3.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.
@@ -6,7 +6,7 @@ import { Logger } from "./logger.js";
6
6
  import { ClassComponent } from "./objects/ClassComponent.js";
7
7
  import { NumberOperator, NumericValue, PercentageValue } from "./objects/ParamDefinition.js";
8
8
  import { PinTypes } from "./objects/PinTypes.js";
9
- import { Direction, AnyReference, UndeclaredReference, ImportedModule, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
9
+ import { Direction, AnyReference, UndeclaredReference, ImportedLibrary, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
10
10
  import { BaseNamespace, ComponentTypes, DoubleDelimiter1, GlobalDocumentName, ReferenceTypes, TrailerArrayIndex } from './globals.js';
11
11
  import { isReference, unwrapValue as unwrapValue } from "./utils.js";
12
12
  import { linkBuiltInMethods } from './builtinMethods.js';
@@ -145,17 +145,17 @@ export class BaseVisitor extends CircuitScriptVisitor {
145
145
  });
146
146
  specificImports.push(...tmpSpecificImports);
147
147
  }
148
- const id = ctx._moduleName.text;
148
+ const id = ctx._libraryName.text;
149
149
  const importedFile = await this.handleImportFile(id, handling, true, ctx, specificImports);
150
150
  const ctxImportAnnotation = ctx.import_annotation_expr();
151
151
  if (ctxImportAnnotation) {
152
152
  const textValue = ctxImportAnnotation.getText().replace('#=', '');
153
- const { importedModule } = importedFile;
153
+ const { importedLibrary } = importedFile;
154
154
  if (textValue === 'annotate') {
155
- importedModule.enableRefdesAnnotation = true;
155
+ importedLibrary.enableRefdesAnnotation = true;
156
156
  }
157
157
  else if (textValue === 'annotate-external') {
158
- importedModule.enableRefdesAnnotationFile = true;
158
+ importedLibrary.enableRefdesAnnotationFile = true;
159
159
  }
160
160
  }
161
161
  }
@@ -417,23 +417,23 @@ export class BaseVisitor extends CircuitScriptVisitor {
417
417
  }
418
418
  const useNetNamespace = this.getNetNamespace(executor.netNamespace, passedNetNamespace);
419
419
  try {
420
- const isModuleFunction = currentReference.rootValue
421
- && currentReference.rootValue instanceof ImportedModule;
422
- if (isModuleFunction) {
423
- this.log('create new module context');
424
- const importedModule = currentReference.rootValue;
425
- const importedModuleContext = importedModule.context;
426
- this.enterFile(importedModule.moduleFilePath);
427
- const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedModuleContext.name, ctx, {
420
+ const isLibraryFunction = currentReference.rootValue
421
+ && currentReference.rootValue instanceof ImportedLibrary;
422
+ if (isLibraryFunction) {
423
+ this.log('create new library context');
424
+ const importedLibrary = currentReference.rootValue;
425
+ const { context: importedLibraryContext } = importedLibrary;
426
+ this.enterFile(importedLibrary.libraryFilePath);
427
+ const newExecutor = this.handleEnterContext(this.getExecutor(), this.executionStack, importedLibraryContext.name, ctx, {
428
428
  netNamespace: executor.netNamespace,
429
- namespace: importedModule.moduleNamespace
429
+ namespace: importedLibrary.libraryNamespace
430
430
  }, [], [], false);
431
- this.log('copy module context scope');
432
- importedModuleContext.scope.copyTo(newExecutor.scope);
431
+ this.log('copy library context scope');
432
+ importedLibraryContext.scope.copyTo(newExecutor.scope);
433
433
  }
434
434
  const [, functionResult] = executor.callFunction(currentReference, parameters, this.executionStack, useNetNamespace);
435
- if (isModuleFunction) {
436
- this.log('pop module context scope');
435
+ if (isLibraryFunction) {
436
+ this.log('pop library context scope');
437
437
  this.handlePopContext(this.getExecutor(), this.executionStack, "", false);
438
438
  this.exitFile();
439
439
  }
@@ -712,8 +712,8 @@ export class BaseVisitor extends CircuitScriptVisitor {
712
712
  return item.id === name;
713
713
  });
714
714
  if (importAlready) {
715
- const tmpImportedModule = importAlready.importedModule;
716
- const alreadyImportedFlag = tmpImportedModule.importHandlingFlag;
715
+ const { importedLibrary: tmpImportedLibrary } = importAlready;
716
+ const alreadyImportedFlag = tmpImportedLibrary.importHandlingFlag;
717
717
  const isMergedNamespace = alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace
718
718
  || alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace;
719
719
  const invalidImportCondition1 = alreadyImportedFlag === ImportFunctionHandling.AllWithNamespace &&
@@ -727,11 +727,11 @@ export class BaseVisitor extends CircuitScriptVisitor {
727
727
  if (alreadyImportedFlag === ImportFunctionHandling.AllMergeIntoNamespace) {
728
728
  }
729
729
  else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.AllMergeIntoNamespace) {
730
- tmpImportedModule.specifiedImports = [];
731
- tmpImportedModule.importHandlingFlag = ImportFunctionHandling.AllMergeIntoNamespace;
730
+ tmpImportedLibrary.specifiedImports = [];
731
+ tmpImportedLibrary.importHandlingFlag = ImportFunctionHandling.AllMergeIntoNamespace;
732
732
  }
733
733
  else if (alreadyImportedFlag === ImportFunctionHandling.SpecificMergeIntoNamespace && importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace) {
734
- tmpImportedModule.specifiedImports.push(...specificImports);
734
+ tmpImportedLibrary.specifiedImports.push(...specificImports);
735
735
  }
736
736
  }
737
737
  return importAlready;
@@ -752,7 +752,7 @@ export class BaseVisitor extends CircuitScriptVisitor {
752
752
  this.log('failed to read file');
753
753
  pathExists = false;
754
754
  }
755
- let importedModule;
755
+ let importedLibrary;
756
756
  if (!pathExists) {
757
757
  try {
758
758
  const tmpFilePath2 = this.environment.getRelativeToDefaultLibs(name + ".cst");
@@ -773,26 +773,26 @@ export class BaseVisitor extends CircuitScriptVisitor {
773
773
  const executor = this.getExecutor();
774
774
  const executionContextName = name;
775
775
  const netNamespace = executor.netNamespace;
776
- const moduleNamespace = `${BaseNamespace}${name}.`;
776
+ const libraryNamespace = `${BaseNamespace}${name}.`;
777
777
  this.enterNewChildContext(executionStack, executor, executionContextName, {
778
778
  netNamespace,
779
- namespace: moduleNamespace,
779
+ namespace: libraryNamespace,
780
780
  }, [], []);
781
781
  const importResult = await this.onImportFile(this, filePathUsed, fileData, this.onErrorHandler);
782
782
  hasError = importResult.hasError;
783
783
  hasParseError = importResult.hasParseError;
784
784
  const importContext = executionStack.pop();
785
785
  this.log(`import handling flag: ${importHandling}`);
786
- importedModule = new ImportedModule(name, moduleNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
786
+ importedLibrary = new ImportedLibrary(name, libraryNamespace, filePathUsed, importResult.tree, importResult.tokens, importContext, importHandling, specificImports);
787
787
  if (specificImports.length > 0) {
788
788
  this.log('specific import: ' + specificImports.join(', '));
789
789
  }
790
790
  const scope = this.getScope();
791
- scope.modules.set(name, importedModule);
792
- importedModule.context.scope.modules.forEach((module, key) => {
793
- scope.modules.set(key, module);
791
+ scope.libraries.set(name, importedLibrary);
792
+ importedLibrary.context.scope.libraries.forEach((lib, key) => {
793
+ scope.libraries.set(key, lib);
794
794
  });
795
- await this.checkModuleHasRefdesFile(filePathUsed);
795
+ await this.checkLibraryHasRefdesFile(filePathUsed);
796
796
  }
797
797
  }
798
798
  catch (err) {
@@ -820,12 +820,12 @@ export class BaseVisitor extends CircuitScriptVisitor {
820
820
  hasError,
821
821
  hasParseError,
822
822
  pathExists,
823
- importedModule: importedModule
823
+ importedLibrary: importedLibrary
824
824
  };
825
825
  this.importedFiles.push(newImportedFile);
826
826
  return newImportedFile;
827
827
  }
828
- async checkModuleHasRefdesFile(filePath) {
828
+ async checkLibraryHasRefdesFile(filePath) {
829
829
  return;
830
830
  }
831
831
  getRefdesFileAnnotation(filePath, startLine, startColumn, stopLine, stopColumn) {
@@ -1,5 +1,5 @@
1
+ import { ComponentTypes } from "./globals.js";
1
2
  import { NumericValue } from "./objects/ParamDefinition.js";
2
- import { TypeProps } from "./objects/types.js";
3
3
  export function flattenConditionNodes(conditionNodes, level = 0) {
4
4
  const conditionBranches = [];
5
5
  conditionNodes.forEach(node => {
@@ -95,7 +95,7 @@ export function partMatchesConditions(instance, partConditions) {
95
95
  }
96
96
  export function applyPartConditions(instances, paramKeys, partConditions) {
97
97
  instances.forEach(item => {
98
- if (item.typeProp !== TypeProps.Graphic) {
98
+ if (item.typeProp !== ComponentTypes.graphic) {
99
99
  const matchedResult = partMatchesConditions(item, partConditions);
100
100
  if (matchedResult !== undefined) {
101
101
  paramKeys.forEach((paramKey, index) => {
@@ -3572,7 +3572,7 @@ export class CircuitScriptParser extends antlr.Parser {
3572
3572
  this.state = 686;
3573
3573
  this.match(CircuitScriptParser.Import);
3574
3574
  this.state = 687;
3575
- localContext._moduleName = this.match(CircuitScriptParser.ID);
3575
+ localContext._libraryName = this.match(CircuitScriptParser.ID);
3576
3576
  this.state = 689;
3577
3577
  this.errorHandler.sync(this);
3578
3578
  switch (this.interpreter.adaptivePredict(this.tokenStream, 76, this.context)) {
@@ -3592,7 +3592,7 @@ export class CircuitScriptParser extends antlr.Parser {
3592
3592
  this.state = 691;
3593
3593
  this.match(CircuitScriptParser.From);
3594
3594
  this.state = 692;
3595
- localContext._moduleName = this.match(CircuitScriptParser.ID);
3595
+ localContext._libraryName = this.match(CircuitScriptParser.ID);
3596
3596
  this.state = 693;
3597
3597
  this.match(CircuitScriptParser.Import);
3598
3598
  this.state = 694;
@@ -3616,7 +3616,7 @@ export class CircuitScriptParser extends antlr.Parser {
3616
3616
  this.state = 698;
3617
3617
  this.match(CircuitScriptParser.From);
3618
3618
  this.state = 699;
3619
- localContext._moduleName = this.match(CircuitScriptParser.ID);
3619
+ localContext._libraryName = this.match(CircuitScriptParser.ID);
3620
3620
  this.state = 700;
3621
3621
  this.match(CircuitScriptParser.Import);
3622
3622
  this.state = 701;
@@ -6760,7 +6760,7 @@ export class Import_exprContext extends antlr.ParserRuleContext {
6760
6760
  }
6761
6761
  }
6762
6762
  export class Import_specificContext extends Import_exprContext {
6763
- _moduleName;
6763
+ _libraryName;
6764
6764
  _ID;
6765
6765
  _funcNames = [];
6766
6766
  constructor(ctx) {
@@ -6794,7 +6794,7 @@ export class Import_specificContext extends Import_exprContext {
6794
6794
  }
6795
6795
  }
6796
6796
  export class Import_all_simpleContext extends Import_exprContext {
6797
- _moduleName;
6797
+ _libraryName;
6798
6798
  constructor(ctx) {
6799
6799
  super(ctx.parent, ctx.invokingState);
6800
6800
  super.copyFrom(ctx);
@@ -6824,7 +6824,7 @@ export class Import_all_simpleContext extends Import_exprContext {
6824
6824
  }
6825
6825
  }
6826
6826
  export class Import_simpleContext extends Import_exprContext {
6827
- _moduleName;
6827
+ _libraryName;
6828
6828
  constructor(ctx) {
6829
6829
  super(ctx.parent, ctx.invokingState);
6830
6830
  super.copyFrom(ctx);
@@ -1,6 +1,6 @@
1
1
  import Big from "big.js";
2
2
  import { numeric, NumericValue } from "./objects/ParamDefinition.js";
3
- import { CFunctionEntry, ImportedModule } from "./objects/types.js";
3
+ import { CFunctionEntry, ImportedLibrary } from "./objects/types.js";
4
4
  import { unwrapValue, resolveToNumericValue, RuntimeExecutionError } from "./utils.js";
5
5
  import { BaseNamespace } from "./globals.js";
6
6
  const builtInMethods = [
@@ -149,8 +149,8 @@ function toString(obj) {
149
149
  else if (obj instanceof CFunctionEntry) {
150
150
  return obj.toString();
151
151
  }
152
- else if (obj instanceof ImportedModule) {
153
- return `[module: ${obj.moduleName}]`;
152
+ else if (obj instanceof ImportedLibrary) {
153
+ return `[library: ${obj.libraryName}]`;
154
154
  }
155
155
  else {
156
156
  if (obj === undefined) {
@@ -646,19 +646,18 @@ export class ExecutionContext {
646
646
  });
647
647
  }
648
648
  else {
649
- const modules = Array.from(context.scope.modules.values());
650
- for (let j = 0; j < modules.length; j++) {
651
- const module = modules[j];
652
- if (module.importHandlingFlag === ImportFunctionHandling.AllMergeIntoNamespace ||
653
- (module.importHandlingFlag === ImportFunctionHandling.SpecificMergeIntoNamespace
654
- && module.specifiedImports.indexOf(idName) !== -1)) {
655
- const moduleContext = module.context;
656
- const functionPath = `${moduleContext.namespace}${idName}`;
657
- if (module.context.hasFunction(functionPath)) {
649
+ const libraries = Array.from(context.scope.libraries.values());
650
+ for (const library of libraries) {
651
+ if (library.importHandlingFlag === ImportFunctionHandling.AllMergeIntoNamespace ||
652
+ (library.importHandlingFlag === ImportFunctionHandling.SpecificMergeIntoNamespace
653
+ && library.specifiedImports.indexOf(idName) !== -1)) {
654
+ const { context: libraryContext } = library;
655
+ const functionPath = `${libraryContext.namespace}${idName}`;
656
+ if (library.context.hasFunction(functionPath)) {
658
657
  return new DeclaredReference({
659
658
  found: true,
660
- rootValue: module,
661
- value: module.context.getFunction(functionPath),
659
+ rootValue: library,
660
+ value: library.context.getFunction(functionPath),
662
661
  type: ReferenceTypes.function,
663
662
  name: idName,
664
663
  trailerIndex: 1,
@@ -667,24 +666,24 @@ export class ExecutionContext {
667
666
  }
668
667
  }
669
668
  }
670
- let isModule = false;
671
- if (context.scope.modules.has(idName)) {
672
- const module = context.scope.modules.get(idName);
673
- if (module.importHandlingFlag === ImportFunctionHandling.AllWithNamespace) {
674
- isModule = true;
669
+ let isLibrary = false;
670
+ if (context.scope.libraries.has(idName)) {
671
+ const library = context.scope.libraries.get(idName);
672
+ if (library.importHandlingFlag === ImportFunctionHandling.AllWithNamespace) {
673
+ isLibrary = true;
675
674
  }
676
675
  }
677
676
  let isVariable = context.scope.variables.has(idName);
678
677
  let isComponentInstance = context.scope.instances.has(idName);
679
- if (isModule || isVariable || isComponentInstance) {
680
- const scopeList = isModule ? context.scope.modules :
678
+ if (isLibrary || isVariable || isComponentInstance) {
679
+ const scopeList = isLibrary ? context.scope.libraries :
681
680
  (isVariable ? context.scope.variables : context.scope.instances);
682
681
  const useValue = scopeList.get(idName);
683
682
  if (!isComponentInstance && (useValue instanceof ClassComponent)) {
684
683
  isComponentInstance = true;
685
684
  isVariable = false;
686
685
  }
687
- const referenceType = isModule ? ReferenceTypes.module :
686
+ const referenceType = isLibrary ? ReferenceTypes.library :
688
687
  (isVariable ? ReferenceTypes.variable : ReferenceTypes.instance);
689
688
  const tmpReference = this.resolveTrailers(referenceType, useValue, trailers);
690
689
  return new DeclaredReference({
@@ -731,12 +730,12 @@ export class ExecutionContext {
731
730
  }
732
731
  break;
733
732
  }
734
- case ReferenceTypes.module: {
733
+ case ReferenceTypes.library: {
735
734
  const funcName = trailers[0];
736
- const module = rootValue;
737
- const functionPath = `${module.moduleNamespace}${funcName}`;
738
- if (module.context.hasFunction(functionPath)) {
739
- const foundFunc = module.context.getFunction(functionPath);
735
+ const library = rootValue;
736
+ const functionPath = `${library.libraryNamespace}${funcName}`;
737
+ if (library.context.hasFunction(functionPath)) {
738
+ const foundFunc = library.context.getFunction(functionPath);
740
739
  return new AnyReference({
741
740
  found: true,
742
741
  type: ReferenceTypes.function,
@@ -87,6 +87,7 @@ export var ComponentTypes;
87
87
  ComponentTypes["graphic"] = "graphic";
88
88
  ComponentTypes["port"] = "port";
89
89
  ComponentTypes["module"] = "module";
90
+ ComponentTypes["resistor"] = "res";
90
91
  })(ComponentTypes || (ComponentTypes = {}));
91
92
  export var ReferenceTypes;
92
93
  (function (ReferenceTypes) {
@@ -95,7 +96,7 @@ export var ReferenceTypes;
95
96
  ReferenceTypes["variable"] = "variable";
96
97
  ReferenceTypes["instance"] = "instance";
97
98
  ReferenceTypes["pinType"] = "pinType";
98
- ReferenceTypes["module"] = "module";
99
+ ReferenceTypes["library"] = "library";
99
100
  ReferenceTypes["unknown"] = "unknown";
100
101
  })(ReferenceTypes || (ReferenceTypes = {}));
101
102
  export var BlockTypes;
package/dist/esm/graph.js CHANGED
@@ -6,7 +6,7 @@ import { RenderFrame, RenderComponent, applyComponentParamsToSymbol, RenderWire
6
6
  import { SequenceAction, FrameAction } from "./objects/ExecutionScope.js";
7
7
  import { Frame, FixedFrameIds, FrameParamKeys } from "./objects/Frame.js";
8
8
  import { numeric } from "./objects/ParamDefinition.js";
9
- import { NetTypes, TypeProps } from "./objects/types.js";
9
+ import { NetTypes } from "./objects/types.js";
10
10
  import Matrix, { solve } from "ml-matrix";
11
11
  import { getPinDefinition, PinId } from "./objects/PinDefinition.js";
12
12
  export class NetGraph {
@@ -232,7 +232,7 @@ export class NetGraph {
232
232
  const netsLength = netsIndexed.length;
233
233
  const conductanceMatrix = Matrix.zeros(netsLength, netsLength);
234
234
  components.forEach(item => {
235
- if (item.typeProp === TypeProps.Resistor) {
235
+ if (item.typeProp === ComponentTypes.resistor) {
236
236
  const net1 = item.pinNets.get(1);
237
237
  const net2 = item.pinNets.get(2);
238
238
  const net1Index = netsIndexed.indexOf(net1);
@@ -149,7 +149,7 @@ export async function validateScript(filePath, scriptData, options) {
149
149
  await visitorResolver.visitAsync(tree);
150
150
  return visitorResolver;
151
151
  }
152
- async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedModules, environment) {
152
+ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
153
153
  const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
154
154
  if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
155
155
  const annotatedFiles = [{
@@ -160,29 +160,29 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
160
160
  filePath: inputPath,
161
161
  outputType: RefdesOutputType.WithSource
162
162
  }];
163
- for (const module of importedModules) {
163
+ for (const library of importedLibraries) {
164
164
  let outputType = RefdesOutputType.None;
165
- if (module.enableRefdesAnnotation) {
165
+ if (library.enableRefdesAnnotation) {
166
166
  outputType = RefdesOutputType.WithSource;
167
167
  }
168
- else if (module.enableRefdesAnnotationFile) {
168
+ else if (library.enableRefdesAnnotationFile) {
169
169
  outputType = RefdesOutputType.CreateExternalFile;
170
170
  }
171
171
  if (outputType !== RefdesOutputType.None) {
172
- const { moduleFilePath, moduleName, tokens: moduleTokens, tree: moduleTree } = module;
173
- const moduleScriptData = await environment.readFile(moduleFilePath, { encoding: 'utf8' });
172
+ const { libraryFilePath, libraryName, tokens: libTokens, tree: libTree } = library;
173
+ const libraryScriptData = await environment.readFile(libraryFilePath, { encoding: 'utf8' });
174
174
  annotatedFiles.push({
175
- tokens: moduleTokens,
176
- tree: moduleTree,
177
- filePath: moduleFilePath,
178
- scriptData: moduleScriptData,
179
- moduleName,
175
+ tokens: libTokens,
176
+ tree: libTree,
177
+ filePath: libraryFilePath,
178
+ scriptData: libraryScriptData,
179
+ libraryName,
180
180
  outputType
181
181
  });
182
182
  }
183
183
  }
184
184
  for (const item of annotatedFiles) {
185
- const { scriptData, tokens, tree, filePath, moduleName, isMainFile = false } = item;
185
+ const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
186
186
  const tmpVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
187
187
  await tmpVisitor.visit(tree);
188
188
  let usePath = filePath;
@@ -208,15 +208,15 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
208
208
  const relativeFilePath = environment.relative(inputDir, filePath);
209
209
  const jsonFile = {
210
210
  format: 'v1',
211
- module: moduleName,
211
+ library: libraryName,
212
212
  file: relativeFilePath,
213
213
  items: output,
214
214
  };
215
215
  environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
216
216
  }
217
217
  let display = 'Refdes annotations';
218
- if (moduleName) {
219
- display += ` for module ${moduleName}`;
218
+ if (libraryName) {
219
+ display += ` for library ${libraryName}`;
220
220
  }
221
221
  console.log(`${display} saved to ${usePath}`);
222
222
  }
@@ -300,9 +300,9 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
300
300
  throw new RenderError(`Error during component annotation: ${err}`, 'annotation');
301
301
  }
302
302
  const componentLinks = visitor.getComponentCtxLinks();
303
- const importedModules = Array.from(visitor.getScope().modules.values());
303
+ const importedLibraries = Array.from(visitor.getScope().libraries.values());
304
304
  for (let i = 0; i < postAnnotationCallbacks.length; i++) {
305
- await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedModules, environment);
305
+ await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedLibraries, environment);
306
306
  }
307
307
  if (dumpNets) {
308
308
  const nets = visitor.dumpNets();
@@ -9,7 +9,7 @@ export class ExecutionScope {
9
9
  functionCounter = new Map();
10
10
  variables = new Map();
11
11
  symbols = new Map();
12
- modules = new Map();
12
+ libraries = new Map();
13
13
  blockStack = new Map();
14
14
  contextStack = [];
15
15
  onPropertyHandler = [];
@@ -112,37 +112,26 @@ export var Direction;
112
112
  Direction["Down"] = "down";
113
113
  Direction["Up"] = "up";
114
114
  })(Direction || (Direction = {}));
115
- export var TypeProps;
116
- (function (TypeProps) {
117
- TypeProps["Net"] = "net";
118
- TypeProps["Port"] = "port";
119
- TypeProps["Graphic"] = "graphic";
120
- TypeProps["Module"] = "module";
121
- TypeProps["Resistor"] = "res";
122
- TypeProps["Capacitor"] = "cap";
123
- TypeProps["Inductor"] = "ind";
124
- TypeProps["Diode"] = "diode";
125
- })(TypeProps || (TypeProps = {}));
126
115
  export var NetTypes;
127
116
  (function (NetTypes) {
128
117
  NetTypes["Any"] = "any";
129
118
  NetTypes["Source"] = "source";
130
119
  })(NetTypes || (NetTypes = {}));
131
- export class ImportedModule {
132
- moduleName;
120
+ export class ImportedLibrary {
121
+ libraryName;
133
122
  context;
134
123
  importHandlingFlag;
135
124
  specifiedImports;
136
- moduleNamespace;
137
- moduleFilePath;
125
+ libraryNamespace;
126
+ libraryFilePath;
138
127
  enableRefdesAnnotation = false;
139
128
  enableRefdesAnnotationFile = false;
140
129
  tree;
141
130
  tokens;
142
- constructor(moduleName, moduleNamespace, moduleFilePath, tree, tokens, context, flag, specifiedImports) {
143
- this.moduleName = moduleName;
144
- this.moduleNamespace = moduleNamespace;
145
- this.moduleFilePath = moduleFilePath;
131
+ constructor(libraryName, libraryNamespace, libraryFilePath, tree, tokens, context, flag, specifiedImports) {
132
+ this.libraryName = libraryName;
133
+ this.libraryNamespace = libraryNamespace;
134
+ this.libraryFilePath = libraryFilePath;
146
135
  this.tree = tree;
147
136
  this.tokens = tokens;
148
137
  this.context = context;
@@ -62,13 +62,13 @@ export class SymbolValidatorVisitor extends BaseVisitor {
62
62
  });
63
63
  specifiedImports.push(...tmpImports);
64
64
  }
65
- const id = ctx._moduleName.text;
66
- const { pathExists, importedModule } = await this.handleImportFile(id, handling, true, ctx, specifiedImports);
65
+ const id = ctx._libraryName.text;
66
+ const { pathExists, importedLibrary } = await this.handleImportFile(id, handling, true, ctx, specifiedImports);
67
67
  if (!pathExists) {
68
- this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._moduleName);
68
+ this.symbolTable.addUndefined(this.getCurrentFile(), this.getExecutor(), id, ctx._libraryName);
69
69
  }
70
70
  else {
71
- this.applyModuleImports(importedModule);
71
+ this.applyLibraryImports(importedLibrary);
72
72
  }
73
73
  }
74
74
  visitImport_simple = async (ctx) => {
@@ -80,15 +80,15 @@ export class SymbolValidatorVisitor extends BaseVisitor {
80
80
  visitImport_specific = async (ctx) => {
81
81
  await this.importCommon(ctx, ImportFunctionHandling.SpecificMergeIntoNamespace);
82
82
  };
83
- applyModuleImports(module) {
84
- const { importHandlingFlag: importHandling, specifiedImports } = module;
83
+ applyLibraryImports(library) {
84
+ const { importHandlingFlag: importHandling, specifiedImports } = library;
85
85
  const addedSymbols = [];
86
86
  const executor = this.getExecutor();
87
87
  const symbolTable = this.symbolTable.getSymbols();
88
88
  symbolTable.forEach((value, key) => {
89
89
  if (value.type === ParseSymbolType.Function) {
90
90
  const definedSymbol = value;
91
- if (definedSymbol.fileName === module.moduleFilePath) {
91
+ if (definedSymbol.fileName === library.libraryFilePath) {
92
92
  const addSymbolToNamespace = importHandling === ImportFunctionHandling.AllMergeIntoNamespace
93
93
  || (importHandling === ImportFunctionHandling.SpecificMergeIntoNamespace
94
94
  && specifiedImports.indexOf(definedSymbol.id) !== -1);
@@ -2,7 +2,7 @@ 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, TypeProps, UndeclaredReference } from './objects/types.js';
5
+ import { AnyReference, 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
8
  import { PlaceHolderCommands, SymbolDrawingCommands } from './draw_symbols.js';
@@ -231,7 +231,7 @@ export class ParserVisitor extends BaseVisitor {
231
231
  const display = properties.get('display') ?? null;
232
232
  const suffix = properties.get('suffix') ?? null;
233
233
  let pins = [];
234
- if (display !== null && arrange === null && typeProp !== TypeProps.Graphic) {
234
+ if (display !== null && arrange === null && typeProp !== ComponentTypes.graphic) {
235
235
  const drawCommands = display.getCommands();
236
236
  drawCommands.forEach(command => {
237
237
  const [commandValue,] = command;
@@ -542,7 +542,7 @@ export class ParserVisitor extends BaseVisitor {
542
542
  return new PinDefinition(index + 1, PinIdType.Int, portName, PinTypes.Any);
543
543
  });
544
544
  const arrange = this.getArrangePropFromModulePorts(modulePorts, nameToPinId);
545
- const unitProperties = this.extractComponentUnitProperties(properties, TypeProps.Module);
545
+ const unitProperties = this.extractComponentUnitProperties(properties, ComponentTypes.module);
546
546
  const firstUnitDef = unitProperties[0][1];
547
547
  firstUnitDef.pins = tmpPorts;
548
548
  firstUnitDef.arrange = arrange;
@@ -553,7 +553,7 @@ export class ParserVisitor extends BaseVisitor {
553
553
  };
554
554
  const moduleInstanceName = this.getExecutor().getUniqueInstanceName();
555
555
  const moduleComponent = this.getExecutor().createComponent(moduleInstanceName, tmpPorts, blankParams, props, true);
556
- moduleComponent.typeProp = TypeProps.Module;
556
+ moduleComponent.typeProp = ComponentTypes.module;
557
557
  const ctxPropertyBlock = ctx.property_block_expr();
558
558
  if (ctxPropertyBlock) {
559
559
  const [firstBlock] = ctxPropertyBlock;
@@ -1375,7 +1375,7 @@ export class ParserVisitor extends BaseVisitor {
1375
1375
  children,
1376
1376
  });
1377
1377
  };
1378
- async checkModuleHasRefdesFile(filePath) {
1378
+ async checkLibraryHasRefdesFile(filePath) {
1379
1379
  const dir = this.environment.dirname(filePath);
1380
1380
  const ext = this.environment.extname(filePath);
1381
1381
  const basename = this.environment.basename(filePath, ext);
@@ -1652,8 +1652,8 @@ export class ParserVisitor extends BaseVisitor {
1652
1652
  const fullNetNames = Array.from(uniqueNets).map(item => item.toString());
1653
1653
  nets.forEach(([component, pin, net]) => {
1654
1654
  if (net.priority === 0 && seenNets.indexOf(net) === -1
1655
- && component.typeProp !== TypeProps.Module
1656
- && component.typeProp !== TypeProps.Net) {
1655
+ && component.typeProp !== ComponentTypes.module
1656
+ && component.typeProp !== ComponentTypes.net) {
1657
1657
  net.name = net.baseName =
1658
1658
  `NET-(${component.assignedRefDes}-${pin.toString()})`;
1659
1659
  if (fullNetNames.indexOf(net.toString()) !== -1) {
package/dist/libs/std.cst CHANGED
@@ -428,4 +428,5 @@ def sheet_A6(revision="V1"):
428
428
  return tmp_sheet
429
429
 
430
430
  document.sheet_type = sheet_A4()
431
- document.bom.columns = ["refdes", "mpn", "manufacturer", "footprint"]
431
+ document.bom.columns = ["refdes", "mpn", "manufacturer", "footprint"]
432
+ document.bom.group_by = ["mpn", "manufacturer"]