circuitscript 0.0.22 → 0.0.24

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 (164) hide show
  1. package/dist/cjs/antlr/CircuitScriptLexer.js +288 -0
  2. package/dist/cjs/antlr/CircuitScriptParser.js +4905 -0
  3. package/dist/cjs/antlr/CircuitScriptVisitor.js +6 -0
  4. package/{src/draw_symbols.ts → dist/cjs/draw_symbols.js} +303 -614
  5. package/dist/cjs/execute.js +780 -0
  6. package/{src/export.ts → dist/cjs/export.js} +34 -56
  7. package/dist/cjs/fonts.js +4 -0
  8. package/dist/cjs/geometry.js +430 -0
  9. package/dist/cjs/globals.js +60 -0
  10. package/dist/cjs/helpers.js +99 -0
  11. package/dist/cjs/index.js +29 -0
  12. package/{src/layout.ts → dist/cjs/layout.js} +413 -1002
  13. package/dist/cjs/lexer.js +114 -0
  14. package/dist/cjs/logger.js +17 -0
  15. package/dist/cjs/main.js +87 -0
  16. package/dist/cjs/objects/ClassComponent.js +142 -0
  17. package/dist/cjs/objects/ExecutionScope.js +134 -0
  18. package/dist/cjs/objects/Frame.js +22 -0
  19. package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
  20. package/dist/cjs/objects/ParamDefinition.js +42 -0
  21. package/dist/cjs/objects/PinDefinition.js +31 -0
  22. package/dist/cjs/objects/PinTypes.js +11 -0
  23. package/dist/cjs/objects/Wire.js +9 -0
  24. package/dist/cjs/objects/types.js +9 -0
  25. package/dist/cjs/parser.js +299 -0
  26. package/dist/cjs/regenerate-tests.js +23 -0
  27. package/dist/cjs/render.js +155 -0
  28. package/{src/server.ts → dist/cjs/server.js} +15 -21
  29. package/dist/cjs/sizing.js +105 -0
  30. package/{src/utils.ts → dist/cjs/utils.js} +25 -35
  31. package/{src/visitor.ts → dist/cjs/visitor.js} +392 -948
  32. package/{build/src/antlr/CircuitScriptLexer.js → dist/esm/antlr/CircuitScriptLexer.mjs} +90 -91
  33. package/{build/src/antlr/CircuitScriptParser.js → dist/esm/antlr/CircuitScriptParser.mjs} +138 -136
  34. package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +11 -11
  35. package/{build/src/execute.js → dist/esm/execute.mjs} +9 -8
  36. package/{build/src/export.js → dist/esm/export.mjs} +2 -2
  37. package/{build/src/geometry.js → dist/esm/geometry.mjs} +3 -7
  38. package/{build/src/helpers.js → dist/esm/helpers.mjs} +27 -7
  39. package/dist/esm/index.mjs +13 -0
  40. package/{build/src/layout.js → dist/esm/layout.mjs} +11 -11
  41. package/{build/src/lexer.js → dist/esm/lexer.mjs} +2 -2
  42. package/{build/src/main.js → dist/esm/main.mjs} +5 -5
  43. package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +3 -3
  44. package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
  45. package/dist/esm/parser.mjs +269 -0
  46. package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
  47. package/{build/src/render.js → dist/esm/render.mjs} +7 -24
  48. package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
  49. package/{build/src/visitor.js → dist/esm/visitor.mjs} +10 -29
  50. package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +23 -23
  51. package/{build/src → dist/types}/antlr/CircuitScriptParser.d.ts +24 -23
  52. package/{build/src → dist/types}/draw_symbols.d.ts +2 -2
  53. package/{build/src → dist/types}/execute.d.ts +2 -2
  54. package/{build/src → dist/types}/geometry.d.ts +1 -1
  55. package/dist/types/helpers.d.ts +9 -0
  56. package/dist/types/index.d.ts +13 -0
  57. package/{build/src → dist/types}/layout.d.ts +10 -10
  58. package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
  59. package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
  60. package/dist/types/parser.d.ts +38 -0
  61. package/{build/src → dist/types}/render.d.ts +1 -1
  62. package/{build/src → dist/types}/sizing.d.ts +3 -1
  63. package/{build/src → dist/types}/visitor.d.ts +5 -3
  64. package/package.json +30 -12
  65. package/.editorconfig +0 -15
  66. package/.eslintignore +0 -1
  67. package/.eslintrc.json +0 -27
  68. package/.gitlab-ci.yml +0 -81
  69. package/.prettierignore +0 -8
  70. package/.prettierrc +0 -16
  71. package/__tests__/expectedResults.ts +0 -657
  72. package/__tests__/helpers.ts +0 -82
  73. package/__tests__/parseScripts.ts +0 -593
  74. package/__tests__/renderData/script1.cst +0 -58
  75. package/__tests__/renderData/script1.cst.svg +0 -1
  76. package/__tests__/renderData/script2.cst +0 -16
  77. package/__tests__/renderData/script2.cst.svg +0 -1
  78. package/__tests__/renderData/script3.cst +0 -30
  79. package/__tests__/renderData/script3.cst.svg +0 -1
  80. package/__tests__/renderData/script4.cst +0 -54
  81. package/__tests__/renderData/script4.cst.svg +0 -1
  82. package/__tests__/renderData/script5.cst +0 -23
  83. package/__tests__/renderData/script5.cst.svg +0 -1
  84. package/__tests__/renderData/script6.cst +0 -28
  85. package/__tests__/renderData/script6.cst.svg +0 -1
  86. package/__tests__/renderData/script7.cst +0 -26
  87. package/__tests__/renderData/script7.cst.svg +0 -1
  88. package/__tests__/renderData/script8.cst +0 -37
  89. package/__tests__/renderData/script8.cst.svg +0 -1
  90. package/__tests__/testCLI.ts +0 -68
  91. package/__tests__/testMathOps.ts +0 -36
  92. package/__tests__/testMergeWires.ts +0 -141
  93. package/__tests__/testParse.ts +0 -263
  94. package/__tests__/testRender.ts +0 -38
  95. package/build/src/helpers.d.ts +0 -1
  96. package/build/src/parser.js +0 -69
  97. package/documentation.md +0 -238
  98. package/examples/example_arduino_uno.cst +0 -1146
  99. package/examples/example_garden_pump.cst +0 -567
  100. package/examples/lib.cst +0 -185
  101. package/fonts/Inter-Bold.ttf +0 -0
  102. package/fonts/Inter-Regular.ttf +0 -0
  103. package/fonts/OpenSans-Regular.ttf +0 -0
  104. package/fonts/Roboto-Regular.ttf +0 -0
  105. package/jest.config.js +0 -23
  106. package/libs/lib.cst +0 -185
  107. package/refresh.html +0 -42
  108. package/server.cjs +0 -50
  109. package/src/antlr/CircuitScript.g4 +0 -209
  110. package/src/antlr/CircuitScriptLexer.ts +0 -317
  111. package/src/antlr/CircuitScriptParser.ts +0 -4979
  112. package/src/antlr/CircuitScriptVisitor.ts +0 -420
  113. package/src/execute.ts +0 -1227
  114. package/src/fonts.ts +0 -1
  115. package/src/geometry.ts +0 -638
  116. package/src/globals.ts +0 -67
  117. package/src/helpers.ts +0 -114
  118. package/src/lexer.ts +0 -151
  119. package/src/logger.ts +0 -17
  120. package/src/main.ts +0 -105
  121. package/src/objects/ClassComponent.ts +0 -223
  122. package/src/objects/ExecutionScope.ts +0 -201
  123. package/src/objects/Frame.ts +0 -20
  124. package/src/objects/ParamDefinition.ts +0 -49
  125. package/src/objects/PinDefinition.ts +0 -49
  126. package/src/objects/PinTypes.ts +0 -7
  127. package/src/objects/Wire.ts +0 -19
  128. package/src/objects/types.ts +0 -66
  129. package/src/parser.ts +0 -106
  130. package/src/regenerate-tests.ts +0 -25
  131. package/src/render.ts +0 -260
  132. package/src/sizing.ts +0 -96
  133. package/tsconfig.json +0 -27
  134. package/tsconfig.release.json +0 -8
  135. /package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +0 -0
  136. /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
  137. /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
  138. /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
  139. /package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +0 -0
  140. /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
  141. /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
  142. /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
  143. /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
  144. /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
  145. /package/{build/src/objects/types.js → dist/esm/objects/types.mjs} +0 -0
  146. /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
  147. /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
  148. /package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +0 -0
  149. /package/{build/src → dist/types}/export.d.ts +0 -0
  150. /package/{build/src → dist/types}/fonts.d.ts +0 -0
  151. /package/{build/src → dist/types}/globals.d.ts +0 -0
  152. /package/{build/src → dist/types}/lexer.d.ts +0 -0
  153. /package/{build/src → dist/types}/logger.d.ts +0 -0
  154. /package/{build/src → dist/types}/main.d.ts +0 -0
  155. /package/{build/src → dist/types}/objects/ExecutionScope.d.ts +0 -0
  156. /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
  157. /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
  158. /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
  159. /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
  160. /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
  161. /package/{build/src → dist/types}/objects/types.d.ts +0 -0
  162. /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
  163. /package/{build/src → dist/types}/server.d.ts +0 -0
  164. /package/{build/src → dist/types}/utils.d.ts +0 -0
@@ -1,16 +1,16 @@
1
1
  import { ParseTreeVisitor } from 'antlr4';
2
2
  import { readFileSync } from 'fs';
3
3
  import { join } from 'path';
4
- import { ExecutionContext } from './execute.js';
5
- import { ClassComponent } from './objects/ClassComponent.js';
6
- import { NumericValue, ParamDefinition, PercentageValue, PinBlankValue, } from './objects/ParamDefinition.js';
7
- import { PinDefinition, PinIdType } from './objects/PinDefinition.js';
8
- import { PinTypes } from './objects/PinTypes.js';
9
- import { UndeclaredReference } from './objects/types.js';
10
- import { Logger } from './logger.js';
11
- import { BlockTypes, ComponentTypes, NoNetText } from './globals.js';
12
- import { SymbolDrawingCommands } from './draw_symbols.js';
13
- import { parseFileWithVisitor } from './parser.js';
4
+ import { ExecutionContext } from './execute.mjs';
5
+ import { ClassComponent } from './objects/ClassComponent.mjs';
6
+ import { NumericValue, ParamDefinition, PercentageValue, PinBlankValue, } from './objects/ParamDefinition.mjs';
7
+ import { PinDefinition, PinIdType } from './objects/PinDefinition.mjs';
8
+ import { PinTypes } from './objects/PinTypes.mjs';
9
+ import { UndeclaredReference } from './objects/types.mjs';
10
+ import { Logger } from './logger.mjs';
11
+ import { BlockTypes, ComponentTypes, NoNetText } from './globals.mjs';
12
+ import { SymbolDrawingCommands } from './draw_symbols.mjs';
13
+ import { parseFileWithVisitor } from './parser.mjs';
14
14
  export class MainVisitor extends ParseTreeVisitor {
15
15
  indentLevel = 0;
16
16
  startingContext;
@@ -1033,25 +1033,6 @@ export class MainVisitor extends ParseTreeVisitor {
1033
1033
  }
1034
1034
  return returnValue;
1035
1035
  }
1036
- checkNetNamespaceIncludes(targetNetName, targetNamespaceParts, net) {
1037
- if (net.name === targetNetName) {
1038
- const netNamespaceParts = this.getNamespaceParts(net.namespace);
1039
- this.print('check namespace', targetNetName, targetNamespaceParts, netNamespaceParts);
1040
- let matches = 0;
1041
- for (let i = 0; i < netNamespaceParts.length; i++) {
1042
- if (netNamespaceParts[i] === targetNamespaceParts[i]) {
1043
- matches++;
1044
- }
1045
- }
1046
- if (matches === netNamespaceParts.length) {
1047
- return true;
1048
- }
1049
- }
1050
- return false;
1051
- }
1052
- getNamespaceParts(namespace) {
1053
- return namespace.split(".").slice(0, -2);
1054
- }
1055
1036
  setupPrintFunction(context) {
1056
1037
  context.createFunction('print', (params) => {
1057
1038
  const items = params.map(([, , value]) => {
@@ -1,4 +1,4 @@
1
- import { ATN, CharStream, Lexer, RuleContext } from "antlr4";
1
+ import { ATN, CharStream, DFA, Lexer, RuleContext } from "antlr4";
2
2
  export default class CircuitScriptLexer extends Lexer {
3
3
  static readonly T__0 = 1;
4
4
  static readonly T__1 = 2;
@@ -7,25 +7,25 @@ export default class CircuitScriptLexer extends Lexer {
7
7
  static readonly T__4 = 5;
8
8
  static readonly T__5 = 6;
9
9
  static readonly T__6 = 7;
10
- static readonly T__7 = 8;
11
- static readonly Break = 9;
12
- static readonly Branch = 10;
13
- static readonly Create = 11;
14
- static readonly Component = 12;
15
- static readonly Graphic = 13;
16
- static readonly Wire = 14;
17
- static readonly Pin = 15;
18
- static readonly Add = 16;
19
- static readonly At = 17;
20
- static readonly To = 18;
21
- static readonly Point = 19;
22
- static readonly Join = 20;
23
- static readonly Parallel = 21;
24
- static readonly Return = 22;
25
- static readonly Define = 23;
26
- static readonly Import = 24;
27
- static readonly If = 25;
28
- static readonly Not = 26;
10
+ static readonly Break = 8;
11
+ static readonly Branch = 9;
12
+ static readonly Create = 10;
13
+ static readonly Component = 11;
14
+ static readonly Graphic = 12;
15
+ static readonly Wire = 13;
16
+ static readonly Pin = 14;
17
+ static readonly Add = 15;
18
+ static readonly At = 16;
19
+ static readonly To = 17;
20
+ static readonly Point = 18;
21
+ static readonly Join = 19;
22
+ static readonly Parallel = 20;
23
+ static readonly Return = 21;
24
+ static readonly Define = 22;
25
+ static readonly Import = 23;
26
+ static readonly If = 24;
27
+ static readonly Not = 25;
28
+ static readonly Frame = 26;
29
29
  static readonly Equals = 27;
30
30
  static readonly NotEquals = 28;
31
31
  static readonly Addition = 29;
@@ -45,8 +45,8 @@ export default class CircuitScriptLexer extends Lexer {
45
45
  static readonly ALPHA_NUMERIC = 43;
46
46
  static readonly WS = 44;
47
47
  static readonly NEWLINE = 45;
48
- static readonly SKIP_ = 46;
49
- static readonly EOF: any;
48
+ static readonly COMMENT = 46;
49
+ static readonly EOF: number;
50
50
  static readonly channelNames: string[];
51
51
  static readonly literalNames: (string | null)[];
52
52
  static readonly symbolicNames: (string | null)[];
@@ -67,5 +67,5 @@ export default class CircuitScriptLexer extends Lexer {
67
67
  static readonly _serializedATN: number[];
68
68
  private static __ATN;
69
69
  static get _ATN(): ATN;
70
- static DecisionsToDFA: any;
70
+ static DecisionsToDFA: DFA[];
71
71
  }
@@ -1,4 +1,4 @@
1
- import { ATN, FailedPredicateException, Parser, RuleContext, ParserRuleContext, TerminalNode, TokenStream } from 'antlr4';
1
+ import { ATN, DFA, FailedPredicateException, Parser, RuleContext, ParserRuleContext, TerminalNode, TokenStream } from 'antlr4';
2
2
  import CircuitScriptVisitor from "./CircuitScriptVisitor.js";
3
3
  export default class CircuitScriptParser extends Parser {
4
4
  static readonly T__0 = 1;
@@ -8,25 +8,25 @@ export default class CircuitScriptParser extends Parser {
8
8
  static readonly T__4 = 5;
9
9
  static readonly T__5 = 6;
10
10
  static readonly T__6 = 7;
11
- static readonly T__7 = 8;
12
- static readonly Break = 9;
13
- static readonly Branch = 10;
14
- static readonly Create = 11;
15
- static readonly Component = 12;
16
- static readonly Graphic = 13;
17
- static readonly Wire = 14;
18
- static readonly Pin = 15;
19
- static readonly Add = 16;
20
- static readonly At = 17;
21
- static readonly To = 18;
22
- static readonly Point = 19;
23
- static readonly Join = 20;
24
- static readonly Parallel = 21;
25
- static readonly Return = 22;
26
- static readonly Define = 23;
27
- static readonly Import = 24;
28
- static readonly If = 25;
29
- static readonly Not = 26;
11
+ static readonly Break = 8;
12
+ static readonly Branch = 9;
13
+ static readonly Create = 10;
14
+ static readonly Component = 11;
15
+ static readonly Graphic = 12;
16
+ static readonly Wire = 13;
17
+ static readonly Pin = 14;
18
+ static readonly Add = 15;
19
+ static readonly At = 16;
20
+ static readonly To = 17;
21
+ static readonly Point = 18;
22
+ static readonly Join = 19;
23
+ static readonly Parallel = 20;
24
+ static readonly Return = 21;
25
+ static readonly Define = 22;
26
+ static readonly Import = 23;
27
+ static readonly If = 24;
28
+ static readonly Not = 25;
29
+ static readonly Frame = 26;
30
30
  static readonly Equals = 27;
31
31
  static readonly NotEquals = 28;
32
32
  static readonly Addition = 29;
@@ -46,10 +46,10 @@ export default class CircuitScriptParser extends Parser {
46
46
  static readonly ALPHA_NUMERIC = 43;
47
47
  static readonly WS = 44;
48
48
  static readonly NEWLINE = 45;
49
- static readonly SKIP_ = 46;
49
+ static readonly COMMENT = 46;
50
50
  static readonly INDENT = 47;
51
51
  static readonly DEDENT = 48;
52
- static readonly EOF: any;
52
+ static readonly EOF: number;
53
53
  static readonly RULE_script = 0;
54
54
  static readonly RULE_expression = 1;
55
55
  static readonly RULE_path_blocks = 2;
@@ -164,7 +164,7 @@ export default class CircuitScriptParser extends Parser {
164
164
  static readonly _serializedATN: number[];
165
165
  private static __ATN;
166
166
  static get _ATN(): ATN;
167
- static DecisionsToDFA: any;
167
+ static DecisionsToDFA: DFA[];
168
168
  }
169
169
  export declare class ScriptContext extends ParserRuleContext {
170
170
  constructor(parser?: CircuitScriptParser, parent?: ParserRuleContext, invokingState?: number);
@@ -663,6 +663,7 @@ export declare class Import_exprContext extends ParserRuleContext {
663
663
  }
664
664
  export declare class Frame_exprContext extends ParserRuleContext {
665
665
  constructor(parser?: CircuitScriptParser, parent?: ParserRuleContext, invokingState?: number);
666
+ Frame(): TerminalNode;
666
667
  NEWLINE_list(): TerminalNode[];
667
668
  NEWLINE(i: number): TerminalNode;
668
669
  INDENT(): TerminalNode;
@@ -18,7 +18,7 @@ export declare abstract class SymbolGraphic {
18
18
  width: number;
19
19
  height: number;
20
20
  };
21
- draw(group: G, extra?: {}): void;
21
+ draw(group: G, extra?: unknown): void;
22
22
  drawPlaceRemove(group: G, extra?: {
23
23
  place?: boolean;
24
24
  }): void;
@@ -36,7 +36,7 @@ export declare abstract class SymbolGraphic {
36
36
  setLabelValue(labelId: string, labelValue: string): void;
37
37
  getLabelValue(labelId: string): string;
38
38
  }
39
- export declare function SymbolFactory(name: string): SymbolGraphic | null;
39
+ export declare function SymbolFactory(name: string): SymbolGraphic;
40
40
  export declare class SymbolPointHidden extends SymbolGraphic {
41
41
  generateDrawing(): void;
42
42
  }
@@ -18,11 +18,11 @@ export declare class ExecutionContext {
18
18
  net?: Net;
19
19
  });
20
20
  stopFurtherExpressions: boolean;
21
- returnValue: any;
21
+ returnValue: null;
22
22
  silent: boolean;
23
23
  logger: Logger;
24
24
  __functionCache: {};
25
- constructor(name: string, namespace: string, netNamespace: string, executionLevel: number, indentLevel: number, silent: boolean, logger: Logger);
25
+ constructor(name: string, namespace: string, netNamespace: string, executionLevel: number | undefined, indentLevel: number | undefined, silent: boolean | undefined, logger: Logger);
26
26
  print(...params: any[]): void;
27
27
  private setupRoot;
28
28
  instanceExists(instanceName: string): boolean;
@@ -26,7 +26,7 @@ export declare class Label extends Flatten.Polygon {
26
26
  font: string;
27
27
  style: LabelStyle;
28
28
  textMeasurementBounds: Box;
29
- get box(): any;
29
+ get box(): Flatten.Box;
30
30
  constructor(id: string, text: string, anchorPoint: [number, number], polygon: Flatten.Polygon, style: LabelStyle, bounds: Box);
31
31
  static fromPoint(id: string, x: number, y: number, text: string, style: LabelStyle): Label;
32
32
  rotate(angle: number, origin: Flatten.Point): Label;
@@ -0,0 +1,9 @@
1
+ export declare enum JSModuleType {
2
+ CommonJs = "cjs",
3
+ ESM = "mjs"
4
+ }
5
+ export declare function renderScript(scriptData: string, outputPath: string, options: any): string;
6
+ export declare function detectJSModuleType(): JSModuleType;
7
+ export declare function getCurrentPath(): {
8
+ filePath: string;
9
+ };
@@ -0,0 +1,13 @@
1
+ export * from './draw_symbols.js';
2
+ export * from './execute.js';
3
+ export * from './export.js';
4
+ export * from './geometry.js';
5
+ export * from './globals.js';
6
+ export * from './helpers.js';
7
+ export * from './layout.js';
8
+ export * from './lexer.js';
9
+ export * from './logger.js';
10
+ export * from './parser.js';
11
+ export * from './render.js';
12
+ export * from './utils.js';
13
+ export * from './visitor.js';
@@ -1,4 +1,4 @@
1
- import graphlib from '@dagrejs/graphlib';
1
+ import { Graph, Edge } from '@dagrejs/graphlib';
2
2
  import { SymbolGraphic, SymbolText } from "./draw_symbols.js";
3
3
  import { ClassComponent } from "./objects/ClassComponent.js";
4
4
  import { SequenceItem } from "./objects/ExecutionScope.js";
@@ -27,7 +27,7 @@ export declare class LayoutEngine {
27
27
  junctions: RenderJunction[];
28
28
  mergedWires: MergedWire[];
29
29
  };
30
- placeFrames(graph: graphlib.Graph, subgraphInfo: SubGraphInfo[], frameObjects: RenderFrame[]): {
30
+ placeFrames(graph: Graph, subgraphInfo: SubGraphInfo[], frameObjects: RenderFrame[]): {
31
31
  elementFrames: RenderFrame[];
32
32
  textObjects: RenderText[];
33
33
  };
@@ -35,23 +35,23 @@ export declare class LayoutEngine {
35
35
  applyFrameOffset(frame: RenderFrame, level?: number): void;
36
36
  placeAndSizeFrame(frame: RenderFrame, level?: number): void;
37
37
  dumpFrame(frame: RenderFrame, level?: number): void;
38
- prepareFrames(graph: graphlib.Graph, subgraphInfo: SubGraphInfo[], frame: RenderFrame, level?: number): {
38
+ prepareFrames(graph: Graph, subgraphInfo: SubGraphInfo[], frame: RenderFrame, level?: number): {
39
39
  elementFrames: RenderFrame[];
40
40
  textObjects: RenderText[];
41
41
  };
42
42
  generateLayoutGraph(sequence: SequenceItem[], nets: [ClassComponent, pin: number, net: Net][]): {
43
- graph: graphlib.Graph;
43
+ graph: Graph;
44
44
  containerFrames: RenderFrame[];
45
45
  };
46
- setGraphEdge(graph: graphlib.Graph, node1: string, node2: string, edgeValue: EdgeValue): void;
47
- sizeSubGraphs(graph: graphlib.Graph): SubGraphInfo[];
48
- walkAndPlaceGraph(graph: graphlib.Graph, firstNodeId: string, subgraphNodes: string[]): void;
49
- placeSubgraphV2(graph: graphlib.Graph, firstNodeId: string, subgraphEdges: graphlib.Edge[]): void;
46
+ setGraphEdge(graph: Graph, node1: string, node2: string, edgeValue: EdgeValue): void;
47
+ sizeSubGraphs(graph: Graph): SubGraphInfo[];
48
+ walkAndPlaceGraph(graph: Graph, firstNodeId: string, subgraphNodes: string[]): void;
49
+ placeSubgraphV2(graph: Graph, firstNodeId: string, subgraphEdges: Edge[]): void;
50
50
  mergeOriginNodes(node1: RenderItem, pin1: number, node2: RenderItem, pin2: number, originNode1: string, originNode2: string, originNodes: RenderItem[], originNodeGroups: Map<string, RenderItem[]>): void;
51
- placeSubgraph(graph: graphlib.Graph, firstNodeId: string, subgraphEdges: graphlib.Edge[]): void;
51
+ placeSubgraph(graph: Graph, firstNodeId: string, subgraphEdges: Edge[]): void;
52
52
  translateNodeBy(offsetX: number, offsetY: number, item: RenderItem): void;
53
53
  placeNodeAtPosition(fromX: number, fromY: number, item: RenderItem, pin: number, depth?: number): void;
54
- placeFloatingItems(graph: graphlib.Graph, item: RenderItem, depth?: number): void;
54
+ placeFloatingItems(graph: Graph, item: RenderItem, depth?: number): void;
55
55
  printWarnings(): void;
56
56
  }
57
57
  type EdgeValue = [
@@ -1,6 +1,6 @@
1
1
  import { SymbolDrawingCommands } from '../draw_symbols.js';
2
2
  import { Net } from './Net.js';
3
- import { PinDefinition } from './PinDefinition.js';
3
+ import { PinDefinition, PinId } from './PinDefinition.js';
4
4
  import { WireSegment } from './Wire.js';
5
5
  export declare class ClassComponent {
6
6
  instanceName: string;
@@ -26,7 +26,7 @@ export declare class ClassComponent {
26
26
  setupPins(): void;
27
27
  getDefaultPin(): number;
28
28
  hasPin(pinId: number | string): boolean;
29
- getPin(pinId: number | string): number;
29
+ getPin(pinId: number | string): PinId;
30
30
  getNextPinAfter(pinIndex: number): number;
31
31
  setParam(key: string, value: number | string): void;
32
32
  private refreshParamCache;
@@ -8,7 +8,7 @@ export declare class PinDefinition {
8
8
  altNames: string[];
9
9
  side: string;
10
10
  position: number;
11
- constructor(id: PinId, idType: PinIdType, name: string, pinType?: PinTypes, altNames?: any[]);
11
+ constructor(id: PinId, idType: PinIdType, name: string, pinType?: PinTypes, altNames?: never[]);
12
12
  }
13
13
  export declare enum PinIdType {
14
14
  Int = "int",
@@ -0,0 +1,38 @@
1
+ import { ErrorListener, ParseTreeVisitor, ParserRuleContext, TerminalNode } from 'antlr4';
2
+ import CircuitScriptLexer from './antlr/CircuitScriptLexer.js';
3
+ import CircuitScriptParser, { ScriptContext } from './antlr/CircuitScriptParser.js';
4
+ import { MainVisitor } from './visitor.js';
5
+ export declare function parseFileWithVisitor(visitor: MainVisitor, data: string): {
6
+ tree: ScriptContext;
7
+ parser: CircuitScriptParser;
8
+ hasError: boolean;
9
+ hasParseError: boolean;
10
+ parserTimeTaken: number;
11
+ lexerTimeTaken: number;
12
+ tokens: IParsedToken[];
13
+ };
14
+ export declare class SemanticTokensVisitor extends ParseTreeVisitor<any> {
15
+ parsedTokens: IParsedToken[];
16
+ lexer: CircuitScriptLexer;
17
+ script: string;
18
+ semanticTokens: Map<string, IParsedToken>;
19
+ constructor(lexer: CircuitScriptLexer, script: string);
20
+ visit(ctx: ParserRuleContext): any;
21
+ handleError(ctx: ParserRuleContext, err: Error): void;
22
+ checkContext(ctx: ParserRuleContext): void;
23
+ addSemanticToken(parsedToken: IParsedToken): void;
24
+ parseToken(node: TerminalNode, modifiers: string[], tokenType?: string | null): IParsedToken;
25
+ }
26
+ export interface IParsedToken {
27
+ line: number;
28
+ column: number;
29
+ length: number;
30
+ tokenType: string;
31
+ tokenModifiers: string[];
32
+ textValue: string;
33
+ }
34
+ export declare class CircuitscriptParserErrorListener extends ErrorListener {
35
+ syntaxErrorCounter: number;
36
+ syntaxError(recognizer: any, offendingSymbol: any, line: number, column: number, msg: string, e: any | undefined): void;
37
+ hasParseErrors(): boolean;
38
+ }
@@ -4,7 +4,7 @@ export declare function generateSVG2(graph: {
4
4
  wires: RenderWire[];
5
5
  junctions: RenderJunction[];
6
6
  mergedWires: MergedWire[];
7
- debugRects: BoundBox[];
7
+ debugRects?: BoundBox[];
8
8
  frameObjects: RenderFrame[];
9
9
  textObjects: RenderText[];
10
10
  }): string;
@@ -1,6 +1,8 @@
1
1
  import { Box, SVGTypeMapping } from '@svgdotjs/svg.js';
2
2
  import { HorizontalAlign, VerticalAlign } from './geometry.js';
3
- export declare function prepareSizing(fontsPath: any): Promise<void>;
3
+ import { SVGWindow } from 'svgdom';
4
+ export declare function prepareSVGEnvironment(fontsPath: string | null): Promise<void>;
5
+ export declare function getCreateSVGWindow(): () => SVGWindow;
4
6
  export declare function applyFontsToSVG(canvas: SVGTypeMapping): void;
5
7
  export declare function measureTextSize(text: string, fontFamily: string, fontSize: number): Promise<{
6
8
  width: number;
@@ -101,7 +101,11 @@ export declare class MainVisitor extends ParseTreeVisitor<any> {
101
101
  dumpUniqueNets(): Net[];
102
102
  dumpVariables(): Map<string, any>;
103
103
  dumpInstances(): Map<string, ClassComponent>;
104
- dump2(): any[];
104
+ dump2(): {
105
+ name: string;
106
+ refdes: string;
107
+ pins: {};
108
+ }[];
105
109
  getNetList(): NetListItem[];
106
110
  getGraph(): {
107
111
  sequence: any[];
@@ -113,8 +117,6 @@ export declare class MainVisitor extends ParseTreeVisitor<any> {
113
117
  private setComponentOrientation;
114
118
  private getPropertyExprList;
115
119
  private runExpressions;
116
- private checkNetNamespaceIncludes;
117
- private getNamespaceParts;
118
120
  private setupPrintFunction;
119
121
  private getNetNamespace;
120
122
  }
package/package.json CHANGED
@@ -1,16 +1,26 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
7
7
  "node": ">=16.0"
8
8
  },
9
- "type": "module",
10
- "main": "./build/src/main.js",
9
+ "main": "./dist/cjs/index.js",
10
+ "module": "./dist/esm/index.mjs",
11
+ "types": "./dist/types/index.d.ts",
11
12
  "bin": {
12
- "circuitscript": "./build/src/main.js"
13
+ "circuitscript": "./dist/esm/main.mjs"
13
14
  },
15
+ "exports": {
16
+ ".": {
17
+ "require": "./dist/cjs/index.js",
18
+ "import": "./dist/esm/index.mjs"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
14
24
  "devDependencies": {
15
25
  "@types/figlet": "^1.5.8",
16
26
  "@types/jest": "~29.5",
@@ -27,15 +37,22 @@
27
37
  "source-map-support": "^0.5.21",
28
38
  "ts-api-utils": "~0.0.44",
29
39
  "ts-jest": "~29.1",
40
+ "ts2mjs": "^3.0.0",
30
41
  "typescript": "^5.4.5"
31
42
  },
32
43
  "scripts": {
33
44
  "start": "node build/src/main.js",
34
- "clean": "rimraf coverage build tmp",
35
- "build": "tsc -p tsconfig.json",
36
- "build:watch": "tsc -w -p tsconfig.json",
37
- "build:release": "npm run clean && tsc -p tsconfig.release.json",
38
- "prebuild": "npm run lint",
45
+ "clean": "rimraf coverage build tmp dist",
46
+ "build": "npm run build:cjs || npm run build:esm",
47
+ "build:cjs": "tsc -p tsconfig.cjs.json",
48
+ "build:release:cjs": "tsc -p tsconfig.release.cjs.json",
49
+ "build:esm": "tsc -p tsconfig.esm.json || npm run rename:esm",
50
+ "build:release:esm": "tsc -p tsconfig.release.esm.json || npm run rename:esm",
51
+ "rename:esm": "npx ts2mjs ./dist/esm && rm -rf ./dist/esm/*.js && rm -rf ./dist/esm/**/*.js",
52
+ "build:watch": "tsc -w -p tsconfig.esm.json",
53
+ "build:watch:cjs": "tsc -w -p tsconfig.cjs.json",
54
+ "build:release": "npm run clean && npm run build:release:cjs || npm run build:release:esm",
55
+ "prebuild": "npm run lint || true",
39
56
  "lint": "eslint . --ext .ts --ext .mts",
40
57
  "test": "jest",
41
58
  "test-coverage": "jest --coverage",
@@ -49,15 +66,16 @@
49
66
  "boilerplate_author": "Jakub Synowiec <jsynowiec@users.noreply.github.com>",
50
67
  "license": "MIT",
51
68
  "dependencies": {
52
- "@dagrejs/graphlib": "^2.1.13",
53
- "@flatten-js/core": "^1.4.3",
54
- "@svgdotjs/svg.js": "^3.2.0",
69
+ "@dagrejs/graphlib": "2.1.13",
70
+ "@flatten-js/core": "1.5.5",
71
+ "@svgdotjs/svg.js": "3.2.0",
55
72
  "antlr4": "^4.13.0",
56
73
  "commander": "^11.1.0",
57
74
  "express": "^4.18.2",
58
75
  "figlet": "^1.7.0",
59
76
  "lodash": "^4.17.21",
60
77
  "svgdom": "^0.1.14",
78
+ "this-file": "^2.0.3",
61
79
  "tslib": "~2.5",
62
80
  "ws": "^8.14.2"
63
81
  },
package/.editorconfig DELETED
@@ -1,15 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- charset = utf-8
5
- end_of_line = lf
6
- trim_trailing_whitespace = true
7
- insert_final_newline = true
8
-
9
- [*.md]
10
- insert_final_newline = false
11
- trim_trailing_whitespace = false
12
-
13
- [*.{js,json,ts,mts,yml,yaml}]
14
- indent_size = 2
15
- indent_style = space
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- /**/*.js
package/.eslintrc.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "env": {
3
- "browser": false,
4
- "es6": true,
5
- "node": true
6
- },
7
- "parser": "@typescript-eslint/parser",
8
- "parserOptions": {
9
- "project": "tsconfig.json",
10
- "sourceType": "module",
11
- "ecmaVersion": 2020
12
- },
13
- "plugins": ["@typescript-eslint", "jest"],
14
- "extends": [
15
- "eslint:recommended",
16
- "plugin:@typescript-eslint/recommended",
17
- "plugin:jest/recommended",
18
- "prettier"
19
- ],
20
- "rules": {
21
- // The following rule is enabled only to supplement the inline suppression
22
- // examples, and because it is not a recommended rule, you should either
23
- // disable it, or understand what it enforces.
24
- // https://typescript-eslint.io/rules/explicit-function-return-type/
25
- "@typescript-eslint/explicit-function-return-type": "warn"
26
- }
27
- }
package/.gitlab-ci.yml DELETED
@@ -1,81 +0,0 @@
1
- image: node:18
2
-
3
- # variables:
4
- # ARTIFACT_DOWNLOAD_ATTEMPTS: 2 # Number of retries for restoring saved artifacts.
5
- # FORCE_COLOR: '1' # Whether to force colour output in compatible tooling.
6
- # GET_SOURCES_ATTEMPTS: 2 # Number of retries for git commands.
7
- # GIT_STRATEGY: fetch # How to pull submodules.
8
- # GIT_SUBMODULE_STRATEGY: recursive # How to treat nested git submodules.
9
- # RESTORE_CACHE_ATTEMPTS: 2 # Number of retries for restoring cached files.
10
-
11
- stages:
12
- - prepare
13
- - test_jest
14
- - test_build
15
- - publish
16
-
17
- .common_rules:
18
- rules:
19
- - if: $CI_COMMIT_TAG
20
- # - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
21
-
22
- # Installs all dependencies.
23
- install:
24
- stage: prepare
25
- interruptible: true
26
- retry: 1
27
- dependencies: []
28
- artifacts:
29
- name: 'deps_$CI_COMMIT_REF_SLUG'
30
- paths:
31
- - node_modules/
32
- when: on_success
33
- expire_in: 12h
34
- script:
35
- - echo $CI_COMMIT_BRANCH
36
- - echo $CI_COMMIT_TAG
37
- - echo $CI_PIPELINE_SOURCE
38
- - echo $CI_COMMIT_REF_NAME
39
- - npm install --no-progress --no-audit --no-fund --verbose
40
- rules:
41
- - !reference [.common_rules, rules]
42
-
43
- test_jest:
44
- stage: test_jest
45
- interruptible: true
46
- retry: 1
47
- dependencies:
48
- - install
49
- script:
50
- - npm run build:release || true
51
- - npm run test
52
- rules:
53
- - !reference [.common_rules, rules]
54
-
55
- test_build:
56
- stage: test_build
57
- interruptible: true
58
- retry: 1
59
- dependencies:
60
- - install
61
- script:
62
- - npm run build:release || true
63
- - ls
64
- - ls build
65
- - node build/src/main.js
66
- rules:
67
- - !reference [.common_rules, rules]
68
-
69
- # Publishes the package to npm.
70
- publish:
71
- stage: publish
72
- interruptible: false
73
- dependencies:
74
- - install
75
- script:
76
- - npm config set -- '//registry.npmjs.org/:_authToken' "${NPM_AUTH_TOKEN}"
77
- - npm run build:release || true
78
- - npm publish --verbose
79
- resource_group: 'deployment-$CI_COMMIT_REF_SLUG'
80
- rules:
81
- - !reference [.common_rules, rules]
package/.prettierignore DELETED
@@ -1,8 +0,0 @@
1
- *.md
2
- *.json
3
- .prettierrc
4
-
5
- build/*
6
- src/antlr/CircuitScriptLexer.ts
7
- src/antlr/CircuitScriptParser.ts
8
- src/antlr/CircuitScriptVisitor.ts