circuitscript 0.1.33 → 0.3.0

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 (41) hide show
  1. package/dist/cjs/BaseVisitor.js +32 -32
  2. package/dist/cjs/BomGeneration.js +2 -3
  3. package/dist/cjs/ComponentMatchConditions.js +2 -2
  4. package/dist/cjs/SemanticTokenVisitor.js +1 -1
  5. package/dist/cjs/antlr/CircuitScriptParser.js +3 -3
  6. package/dist/cjs/builtinMethods.js +2 -2
  7. package/dist/cjs/environment.js +14 -6
  8. package/dist/cjs/execute.js +28 -24
  9. package/dist/cjs/globals.js +2 -1
  10. package/dist/cjs/graph.js +1 -1
  11. package/dist/cjs/helpers.js +28 -29
  12. package/dist/cjs/objects/ExecutionScope.js +1 -1
  13. package/dist/cjs/objects/types.js +7 -18
  14. package/dist/cjs/validate/SymbolValidatorVisitor.js +7 -7
  15. package/dist/cjs/visitor.js +6 -6
  16. package/dist/esm/BaseVisitor.js +33 -33
  17. package/dist/esm/BomGeneration.js +2 -3
  18. package/dist/esm/ComponentMatchConditions.js +2 -2
  19. package/dist/esm/SemanticTokenVisitor.js +1 -1
  20. package/dist/esm/antlr/CircuitScriptParser.js +6 -6
  21. package/dist/esm/builtinMethods.js +3 -3
  22. package/dist/esm/environment.js +10 -2
  23. package/dist/esm/execute.js +28 -24
  24. package/dist/esm/globals.js +2 -1
  25. package/dist/esm/graph.js +2 -2
  26. package/dist/esm/helpers.js +28 -29
  27. package/dist/esm/objects/ExecutionScope.js +1 -1
  28. package/dist/esm/objects/types.js +8 -19
  29. package/dist/esm/validate/SymbolValidatorVisitor.js +7 -7
  30. package/dist/esm/visitor.js +7 -7
  31. package/dist/types/BaseVisitor.d.ts +6 -6
  32. package/dist/types/BomGeneration.d.ts +2 -1
  33. package/dist/types/antlr/CircuitScriptParser.d.ts +3 -3
  34. package/dist/types/environment.d.ts +7 -4
  35. package/dist/types/globals.d.ts +3 -2
  36. package/dist/types/helpers.d.ts +2 -2
  37. package/dist/types/objects/ExecutionScope.d.ts +2 -2
  38. package/dist/types/objects/types.d.ts +5 -15
  39. package/dist/types/validate/SymbolValidatorVisitor.d.ts +1 -1
  40. package/dist/types/visitor.d.ts +1 -1
  41. package/package.json +1 -1
@@ -1,4 +1,3 @@
1
- import { writeFileSync, createWriteStream, existsSync, mkdirSync } from "fs";
2
1
  import path from "path";
3
2
  import PDFDocument from "pdfkit";
4
3
  import { generateKiCadNetList, printTree } from "./export.js";
@@ -150,7 +149,7 @@ export async function validateScript(filePath, scriptData, options) {
150
149
  await visitorResolver.visitAsync(tree);
151
150
  return visitorResolver;
152
151
  }
153
- async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedModules, environment) {
152
+ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens, componentLinks, importedLibraries, environment) {
154
153
  const { inputPath = null, updateSource = false, saveAnnotatedCopy = undefined, } = options;
155
154
  if (inputPath && (updateSource || saveAnnotatedCopy !== undefined)) {
156
155
  const annotatedFiles = [{
@@ -161,29 +160,29 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
161
160
  filePath: inputPath,
162
161
  outputType: RefdesOutputType.WithSource
163
162
  }];
164
- for (const module of importedModules) {
163
+ for (const library of importedLibraries) {
165
164
  let outputType = RefdesOutputType.None;
166
- if (module.enableRefdesAnnotation) {
165
+ if (library.enableRefdesAnnotation) {
167
166
  outputType = RefdesOutputType.WithSource;
168
167
  }
169
- else if (module.enableRefdesAnnotationFile) {
168
+ else if (library.enableRefdesAnnotationFile) {
170
169
  outputType = RefdesOutputType.CreateExternalFile;
171
170
  }
172
171
  if (outputType !== RefdesOutputType.None) {
173
- const { moduleFilePath, moduleName, tokens: moduleTokens, tree: moduleTree } = module;
174
- 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' });
175
174
  annotatedFiles.push({
176
- tokens: moduleTokens,
177
- tree: moduleTree,
178
- filePath: moduleFilePath,
179
- scriptData: moduleScriptData,
180
- moduleName,
175
+ tokens: libTokens,
176
+ tree: libTree,
177
+ filePath: libraryFilePath,
178
+ scriptData: libraryScriptData,
179
+ libraryName,
181
180
  outputType
182
181
  });
183
182
  }
184
183
  }
185
184
  for (const item of annotatedFiles) {
186
- const { scriptData, tokens, tree, filePath, moduleName, isMainFile = false } = item;
185
+ const { scriptData, tokens, tree, filePath, libraryName, isMainFile = false } = item;
187
186
  const tmpVisitor = new RefdesAnnotationVisitor(true, scriptData, tokens, componentLinks);
188
187
  await tmpVisitor.visit(tree);
189
188
  let usePath = filePath;
@@ -209,15 +208,15 @@ async function DefaultPostAnnotationCallback(options, scriptData, tree, tokens,
209
208
  const relativeFilePath = environment.relative(inputDir, filePath);
210
209
  const jsonFile = {
211
210
  format: 'v1',
212
- module: moduleName,
211
+ library: libraryName,
213
212
  file: relativeFilePath,
214
213
  items: output,
215
214
  };
216
215
  environment.writeFileSync(usePath, JSON.stringify(jsonFile, null, 4));
217
216
  }
218
217
  let display = 'Refdes annotations';
219
- if (moduleName) {
220
- display += ` for module ${moduleName}`;
218
+ if (libraryName) {
219
+ display += ` for library ${libraryName}`;
221
220
  }
222
221
  console.log(`${display} saved to ${usePath}`);
223
222
  }
@@ -283,8 +282,8 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
283
282
  const dumpDirectory = environment.getRelativeToModule('/dump/');
284
283
  if (dumpData) {
285
284
  console.log('Dump data to:', dumpDirectory);
286
- if (!existsSync(dumpDirectory)) {
287
- mkdirSync(dumpDirectory);
285
+ if (!environment.existsSync(dumpDirectory)) {
286
+ environment.mkdirSync(dumpDirectory);
288
287
  }
289
288
  }
290
289
  if (inputPath !== '') {
@@ -301,16 +300,16 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
301
300
  throw new RenderError(`Error during component annotation: ${err}`, 'annotation');
302
301
  }
303
302
  const componentLinks = visitor.getComponentCtxLinks();
304
- const importedModules = Array.from(visitor.getScope().modules.values());
303
+ const importedLibraries = Array.from(visitor.getScope().libraries.values());
305
304
  for (let i = 0; i < postAnnotationCallbacks.length; i++) {
306
- await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedModules, environment);
305
+ await postAnnotationCallbacks[i](options, scriptData, tree, tokens, componentLinks, importedLibraries, environment);
307
306
  }
308
307
  if (dumpNets) {
309
308
  const nets = visitor.dumpNets();
310
309
  nets.forEach(item => console.log(item.join(" | ")));
311
310
  }
312
- dumpData && writeFileSync(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
313
- dumpData && writeFileSync(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
311
+ dumpData && environment.writeFileSync(dumpDirectory + 'tree.lisp', tree.toStringTree(null, parser));
312
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-parser.txt', visitor.logger.dump());
314
313
  if (throwError) {
315
314
  throw throwError;
316
315
  }
@@ -323,11 +322,11 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
323
322
  const bomConfig = documentVariable.bom;
324
323
  const bomData = generateBom(bomConfig, visitor.getScope().getInstances());
325
324
  const bomCsvOutput = generateBomCSV(bomData);
326
- await saveBomOutputCsv(bomCsvOutput, bomOutputPath);
325
+ await saveBomOutputCsv(environment, bomCsvOutput, bomOutputPath);
327
326
  console.log('Generated BOM file', bomOutputPath);
328
327
  }
329
328
  const tmpSequence = generateDebugSequenceAction(sequence).map(item => sequenceActionString(item));
330
- dumpData && writeFileSync(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
329
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-sequence.txt', tmpSequence.join('\n'));
331
330
  try {
332
331
  let fileExtension = null;
333
332
  let outputDefaultZoom = defaultZoomScale;
@@ -372,7 +371,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
372
371
  }
373
372
  layoutEngine.printWarnings();
374
373
  showStats && console.log('Layout took:', layoutTimer.lap());
375
- dumpData && writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
374
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-layout.txt', layoutEngine.logger.dump());
376
375
  const generateSvgTimer = new SimpleStopwatch();
377
376
  const renderLogger = new Logger();
378
377
  let svgCanvas;
@@ -383,7 +382,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
383
382
  throw new RenderError(`Error during SVG generation: ${err}`, 'svg_generation');
384
383
  }
385
384
  showStats && console.log('Render took:', generateSvgTimer.lap());
386
- dumpData && writeFileSync(dumpDirectory + 'raw-render.txt', renderLogger.dump());
385
+ dumpData && environment.writeFileSync(dumpDirectory + 'raw-render.txt', renderLogger.dump());
387
386
  try {
388
387
  if (fileExtension === "pdf") {
389
388
  outputDefaultZoom = 1;
@@ -396,7 +395,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
396
395
  if (outputPath) {
397
396
  if (fileExtension === 'svg') {
398
397
  try {
399
- writeFileSync(outputPath, svgOutput);
398
+ environment.writeFileSync(outputPath, svgOutput);
400
399
  }
401
400
  catch (err) {
402
401
  throw new RenderError(`Error writing SVG file: ${err}`, 'file_output');
@@ -414,7 +413,7 @@ export async function renderScriptCustom(scriptData, outputPath, options, parseH
414
413
  layout: 'landscape',
415
414
  size: sheetSize
416
415
  });
417
- const outputStream = createWriteStream(outputPath);
416
+ const outputStream = environment.createWriteStream(outputPath);
418
417
  generatePdfOutput(doc, svgCanvas, sheetSize, sheetSizeDefined, outputDefaultZoom);
419
418
  doc.pipe(outputStream);
420
419
  doc.end();
@@ -450,7 +449,7 @@ export class KiCadNetListOutputHandler extends ParseOutputHandler {
450
449
  missingFootprints.forEach(entry => {
451
450
  console.log(`${entry.refdes} (${entry.instanceName}) does not have footprint`);
452
451
  });
453
- writeFileSync(outputPath, printTree(kiCadNetList));
452
+ visitor.environment.writeFileSync(outputPath, printTree(kiCadNetList));
454
453
  console.log('Generated file', outputPath);
455
454
  return false;
456
455
  }
@@ -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) {
@@ -4,7 +4,7 @@ import { ExecutionContext } from "./execute.js";
4
4
  import { Logger } from "./logger.js";
5
5
  import { ClassComponent } from "./objects/ClassComponent.js";
6
6
  import { Net } from "./objects/Net.js";
7
- import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference, ImportedModule, NewContextOptions, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
7
+ import { CallableParameter, ComplexType, Direction, FunctionDefinedParameter, AnyReference, ImportedLibrary, NewContextOptions, ImportFunctionHandling as ImportFunctionHandling } from "./objects/types.js";
8
8
  import { CommonTokenStream, ParserRuleContext } from 'antlr4ng';
9
9
  import { ExecutionWarning } from "./utils.js";
10
10
  import { BaseError } from './utils.js';
@@ -26,7 +26,7 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
26
26
  pinTypesList: string[];
27
27
  onErrorHandler: OnErrorHandler | null;
28
28
  environment: NodeScriptEnvironment;
29
- protected importedFiles: ImportFile[];
29
+ protected importedFiles: ImportLibraryFile[];
30
30
  protected warnings: ExecutionWarning[];
31
31
  onImportFile: (visitor: BaseVisitor, filePath: string, fileData: string, onErrorHandler: OnErrorHandler) => Promise<ImportFileResult>;
32
32
  refdesFileAnnotations: Map<string, string>;
@@ -73,8 +73,8 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
73
73
  protected linkComponentToCtx(ctx: ParserRuleContext, instance: ClassComponent, creationFlag?: boolean): void;
74
74
  getComponentCtxLinks(): Map<ParserRuleContext, ClassComponent>;
75
75
  visitResult(ctx: ParserRuleContext): any;
76
- protected handleImportFile(name: string, importHandling: ImportFunctionHandling, throwErrors?: boolean, ctx?: ParserRuleContext | null, specificImports?: string[]): Promise<ImportFile>;
77
- checkModuleHasRefdesFile(filePath: string): Promise<void>;
76
+ protected handleImportFile(name: string, importHandling: ImportFunctionHandling, throwErrors?: boolean, ctx?: ParserRuleContext | null, specificImports?: string[]): Promise<ImportLibraryFile>;
77
+ checkLibraryHasRefdesFile(filePath: string): Promise<void>;
78
78
  getRefdesFileAnnotation(filePath: string, startLine: number, startColumn: number, stopLine: number, stopColumn: number): string;
79
79
  visitRoundedBracketsExpr: (ctx: RoundedBracketsExprContext) => void;
80
80
  protected setupDefinedParameters(funcDefinedParameters: FunctionDefinedParameter[], passedInParameters: CallableParameter[], executor: ExecutionContext): void;
@@ -94,12 +94,12 @@ export declare class BaseVisitor extends CircuitScriptVisitor<ComplexType | AnyR
94
94
  getCurrentFile(): string;
95
95
  }
96
96
  export type OnErrorHandler = (message: string, context: ParserRuleContext, e?: any) => void;
97
- type ImportFile = {
97
+ type ImportLibraryFile = {
98
98
  id: string;
99
99
  hasError: boolean;
100
100
  hasParseError: boolean;
101
101
  pathExists: boolean;
102
- importedModule: ImportedModule;
102
+ importedLibrary: ImportedLibrary;
103
103
  };
104
104
  export type ImportFileResult = {
105
105
  hasError: boolean;
@@ -1,4 +1,5 @@
1
1
  import { ClassComponent } from "./objects/ClassComponent.js";
2
+ import { NodeScriptEnvironment } from './environment.js';
2
3
  export type BomConfig = {
3
4
  columns: string[];
4
5
  };
@@ -9,5 +10,5 @@ type GroupEntry = {
9
10
  };
10
11
  export declare function groupComponents(bomConfig: BomConfig, bomComponents: Record<string, unknown>[]): Map<string, GroupEntry>;
11
12
  export declare function generateBomCSV(bomData: Record<string, GroupEntry>[]): string[][];
12
- export declare function saveBomOutputCsv(bomCsvOutput: string[][], filePath: string): Promise<void>;
13
+ export declare function saveBomOutputCsv(environment: NodeScriptEnvironment, bomCsvOutput: string[][], filePath: string): Promise<void>;
13
14
  export {};
@@ -895,7 +895,7 @@ export declare class Import_exprContext extends antlr.ParserRuleContext {
895
895
  copyFrom(ctx: Import_exprContext): void;
896
896
  }
897
897
  export declare class Import_specificContext extends Import_exprContext {
898
- _moduleName?: Token | null;
898
+ _libraryName?: Token | null;
899
899
  _ID?: Token | null;
900
900
  _funcNames: antlr.Token[];
901
901
  constructor(ctx: Import_exprContext);
@@ -907,7 +907,7 @@ export declare class Import_specificContext extends Import_exprContext {
907
907
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
908
908
  }
909
909
  export declare class Import_all_simpleContext extends Import_exprContext {
910
- _moduleName?: Token | null;
910
+ _libraryName?: Token | null;
911
911
  constructor(ctx: Import_exprContext);
912
912
  From(): antlr.TerminalNode;
913
913
  Import(): antlr.TerminalNode;
@@ -917,7 +917,7 @@ export declare class Import_all_simpleContext extends Import_exprContext {
917
917
  accept<Result>(visitor: CircuitScriptVisitor<Result>): Result | null;
918
918
  }
919
919
  export declare class Import_simpleContext extends Import_exprContext {
920
- _moduleName?: Token | null;
920
+ _libraryName?: Token | null;
921
921
  constructor(ctx: Import_exprContext);
922
922
  Import(): antlr.TerminalNode;
923
923
  ID(): antlr.TerminalNode;
@@ -1,8 +1,10 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import { Dom } from "@svgdotjs/svg.js";
3
- import { PathOrFileDescriptor, PathLike } from "fs";
3
+ import fs from 'fs';
4
4
  import { SVGWindow } from "./helpers.js";
5
5
  export declare class NodeScriptEnvironment {
6
+ existsSync(pathLike: string): boolean;
7
+ mkdirSync(pathLike: string): void;
6
8
  static _instance: NodeScriptEnvironment | null;
7
9
  static setInstance(instance: NodeScriptEnvironment): void;
8
10
  static getInstance(): NodeScriptEnvironment;
@@ -28,18 +30,19 @@ export declare class NodeScriptEnvironment {
28
30
  textMeasurementCanvas: Dom | undefined;
29
31
  getCanvasWindow(): Dom;
30
32
  prepareSVGEnvironment(): Promise<void>;
31
- readFile(path: PathOrFileDescriptor, options?: any): Promise<string>;
32
- writeFileSync(path: PathOrFileDescriptor, data: string): void;
33
+ readFile(path: fs.PathOrFileDescriptor, options?: any): Promise<string>;
34
+ writeFileSync(path: fs.PathOrFileDescriptor, data: string): void;
33
35
  getAbsolutePath(filePath: string): string;
34
36
  getDirPath(filePath: string): string;
35
37
  setCurrentFile(filePath: string): string;
36
38
  getCurrentFile(): string;
37
39
  getRelativeToCurrentFolder(filePath: string): string;
38
- exists(path: PathLike): Promise<boolean>;
40
+ exists(path: fs.PathLike): Promise<boolean>;
39
41
  hashStringSHA256(value: string): string;
40
42
  dirname(filePath: string): string;
41
43
  extname(filePath: string): string;
42
44
  basename(filePath: string, ext: string): string;
43
45
  join(...paths: string[]): string;
44
46
  relative(from: string, to: string): string;
47
+ createWriteStream(filePath: string): fs.WriteStream;
45
48
  }
@@ -76,7 +76,8 @@ export declare enum ComponentTypes {
76
76
  net = "net",
77
77
  graphic = "graphic",
78
78
  port = "port",
79
- module = "module"
79
+ module = "module",
80
+ resistor = "res"
80
81
  }
81
82
  export declare enum ReferenceTypes {
82
83
  function = "function",
@@ -84,7 +85,7 @@ export declare enum ReferenceTypes {
84
85
  variable = "variable",
85
86
  instance = "instance",
86
87
  pinType = "pinType",
87
- module = "module",
88
+ library = "library",
88
89
  unknown = "unknown"
89
90
  }
90
91
  export declare enum BlockTypes {
@@ -11,7 +11,7 @@ export type SVGWindow = any;
11
11
  import { NumericValue } from "./objects/ParamDefinition.js";
12
12
  import { NodeScriptEnvironment } from "./environment.js";
13
13
  import { ClassComponent } from "./objects/ClassComponent.js";
14
- import { ImportedModule } from "./objects/types.js";
14
+ import { ImportedLibrary } from "./objects/types.js";
15
15
  export declare enum JSModuleType {
16
16
  CommonJs = "cjs",
17
17
  ESM = "mjs"
@@ -47,7 +47,7 @@ type RenderScriptReturn = {
47
47
  errors: BaseError[];
48
48
  };
49
49
  export declare function renderScript(scriptData: string, outputPath: string | null, options: ScriptOptions): Promise<RenderScriptReturn>;
50
- export declare function renderScriptCustom(scriptData: string, outputPath: string | null, options: ScriptOptions, parseHandlers: ParseOutputHandler[], postAnnotationCallbacks: ((options: ScriptOptions, scriptData: string, tree: ScriptContext, tokens: CommonTokenStream, componentLinks: Map<ParserRuleContext, ClassComponent>, importedModule: ImportedModule[], environment: NodeScriptEnvironment) => void)[]): Promise<RenderScriptReturn>;
50
+ export declare function renderScriptCustom(scriptData: string, outputPath: string | null, options: ScriptOptions, parseHandlers: ParseOutputHandler[], postAnnotationCallbacks: ((options: ScriptOptions, scriptData: string, tree: ScriptContext, tokens: CommonTokenStream, componentLinks: Map<ParserRuleContext, ClassComponent>, importedLibraries: ImportedLibrary[], environment: NodeScriptEnvironment) => void)[]): Promise<RenderScriptReturn>;
51
51
  export declare abstract class ParseOutputHandler {
52
52
  beforeRender: boolean;
53
53
  afterRender: boolean;
@@ -1,6 +1,6 @@
1
1
  import { ClassComponent } from './ClassComponent.js';
2
2
  import { Net } from './Net.js';
3
- import { CFunction, CFunctionEntry, ComponentPinNet, ComponentPinNetPair, ComponentPinWireId, ImportedModule, ParseSymbolType, ValueType } from './types.js';
3
+ import { CFunction, CFunctionEntry, ComponentPinNet, ComponentPinNetPair, ComponentPinWireId, ImportedLibrary, ParseSymbolType, ValueType } from './types.js';
4
4
  import { BlockTypes, LayoutDirection } from '../globals.js';
5
5
  import { Wire, WireSegment } from './Wire.js';
6
6
  import { Frame } from './Frame.js';
@@ -19,7 +19,7 @@ export declare class ExecutionScope {
19
19
  symbols: Map<string, {
20
20
  type: ParseSymbolType;
21
21
  }>;
22
- modules: Map<string, ImportedModule>;
22
+ libraries: Map<string, ImportedLibrary>;
23
23
  blockStack: Map<number, BlockStackEntry>;
24
24
  contextStack: ParserRuleContext[];
25
25
  onPropertyHandler: OnPropertyHandler[];
@@ -108,32 +108,22 @@ export declare enum Direction {
108
108
  Down = "down",
109
109
  Up = "up"
110
110
  }
111
- export declare enum TypeProps {
112
- Net = "net",
113
- Port = "port",
114
- Graphic = "graphic",
115
- Module = "module",
116
- Resistor = "res",
117
- Capacitor = "cap",
118
- Inductor = "ind",
119
- Diode = "diode"
120
- }
121
111
  export declare enum NetTypes {
122
112
  Any = "any",
123
113
  Source = "source"
124
114
  }
125
- export declare class ImportedModule {
126
- moduleName: string;
115
+ export declare class ImportedLibrary {
116
+ libraryName: string;
127
117
  context: ExecutionContext;
128
118
  importHandlingFlag: ImportFunctionHandling;
129
119
  specifiedImports: string[];
130
- moduleNamespace: string;
131
- moduleFilePath: string;
120
+ libraryNamespace: string;
121
+ libraryFilePath: string;
132
122
  enableRefdesAnnotation: boolean;
133
123
  enableRefdesAnnotationFile: boolean;
134
124
  tree: ScriptContext;
135
125
  tokens: CommonTokenStream;
136
- constructor(moduleName: string, moduleNamespace: string, moduleFilePath: string, tree: ScriptContext, tokens: CommonTokenStream, context: ExecutionContext, flag: ImportFunctionHandling, specifiedImports: string[]);
126
+ constructor(libraryName: string, libraryNamespace: string, libraryFilePath: string, tree: ScriptContext, tokens: CommonTokenStream, context: ExecutionContext, flag: ImportFunctionHandling, specifiedImports: string[]);
137
127
  }
138
128
  export declare enum ImportFunctionHandling {
139
129
  AllWithNamespace = "all-with-namespace",
@@ -16,7 +16,7 @@ export declare class SymbolValidatorVisitor extends BaseVisitor {
16
16
  visitImport_simple: (ctx: Import_simpleContext) => Promise<void>;
17
17
  visitImport_all_simple: (ctx: Import_all_simpleContext) => Promise<void>;
18
18
  visitImport_specific: (ctx: Import_specificContext) => Promise<void>;
19
- private applyModuleImports;
19
+ private applyLibraryImports;
20
20
  visitAssignment_expr: (ctx: Assignment_exprContext) => ComplexType;
21
21
  visitAtom_expr: (ctx: Atom_exprContext) => void;
22
22
  visitFunction_call_expr: (ctx: Function_call_exprContext) => void;
@@ -75,7 +75,7 @@ export declare class ParserVisitor extends BaseVisitor {
75
75
  visitPart_value_expr: (ctx: Part_value_exprContext) => void;
76
76
  visitPart_condition_expr: (ctx: Part_condition_exprContext) => void;
77
77
  visitPart_condition_key_only_expr: (ctx: Part_condition_key_only_exprContext) => void;
78
- checkModuleHasRefdesFile(filePath: string): Promise<void>;
78
+ checkLibraryHasRefdesFile(filePath: string): Promise<void>;
79
79
  private resolveDataExpr;
80
80
  private resolveDataValue;
81
81
  pinTypes: PinTypes[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.1.33",
3
+ "version": "0.3.0",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {