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,73 +1,62 @@
1
- import { ComponentTypes, NoNetText } from "./globals.js";
2
- import { NumericValue } from "./objects/ParamDefinition.js";
3
- import { NetListItem } from "./visitor.js";
4
-
5
- export function generateKiCADNetList(netlist: NetListItem[]): string {
6
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateKiCADNetList = void 0;
4
+ const globals_js_1 = require("./globals.js");
5
+ const ParamDefinition_js_1 = require("./objects/ParamDefinition.js");
6
+ function generateKiCADNetList(netlist) {
7
7
  const componentsList = [];
8
-
9
- // Dictionary storing net name to the list of nodes/pins
10
8
  const nets = {};
11
-
12
9
  netlist.forEach(entry => {
13
10
  const { instance, pins } = entry;
14
- if (instance.assignedRefDes !== null){
15
-
11
+ if (instance.assignedRefDes !== null) {
16
12
  const instanceDetails = [
17
13
  Id('comp'),
18
14
  [Id('ref'), instance.assignedRefDes],
19
15
  ];
20
-
21
- if (instance.parameters.has('value')){
16
+ if (instance.parameters.has('value')) {
22
17
  let value = instance.parameters.get('value');
23
- if (value instanceof NumericValue){
18
+ if (value instanceof ParamDefinition_js_1.NumericValue) {
24
19
  value = value.value;
25
20
  }
26
21
  instanceDetails.push([Id('value'), value]);
27
22
  }
28
-
29
- if (instance.parameters.has('footprint')){
30
- instanceDetails.push([Id('footprint'),
23
+ if (instance.parameters.has('footprint')) {
24
+ instanceDetails.push([Id('footprint'),
31
25
  instance.parameters.get('footprint')]);
32
- } else {
26
+ }
27
+ else {
33
28
  console.log(instance.assignedRefDes, instance.instanceName, 'does not have footprint');
34
29
  }
35
-
36
30
  componentsList.push(instanceDetails);
37
-
38
- for(const key in pins){
31
+ for (const key in pins) {
39
32
  const netInfo = pins[key];
40
33
  const netName = netInfo.netName;
41
-
42
- if (netName === NoNetText){
34
+ if (netName === globals_js_1.NoNetText) {
43
35
  continue;
44
36
  }
45
-
46
- if (nets[netName] === undefined){
37
+ if (nets[netName] === undefined) {
47
38
  nets[netName] = [];
48
39
  }
49
-
50
40
  nets[netName].push([
51
- Id('node'),
41
+ Id('node'),
52
42
  [Id('ref'), instance.assignedRefDes],
53
43
  [Id('pin'), key],
54
44
  [Id('pintype'), "passive"]
55
- ])
45
+ ]);
56
46
  }
57
- } else {
58
- if (instance.typeProp !== ComponentTypes.label &&
59
- instance.typeProp !== ComponentTypes.net &&
60
- instance.typeProp !== ComponentTypes.point &&
61
- instance.typeProp !== null){
47
+ }
48
+ else {
49
+ if (instance.typeProp !== globals_js_1.ComponentTypes.label &&
50
+ instance.typeProp !== globals_js_1.ComponentTypes.net &&
51
+ instance.typeProp !== globals_js_1.ComponentTypes.point &&
52
+ instance.typeProp !== null) {
62
53
  console.log('Skipping', instance.instanceName);
63
54
  }
64
55
  }
65
56
  });
66
-
67
57
  const netItems = [];
68
58
  let counter = 1;
69
-
70
- for(const netName in nets){
59
+ for (const netName in nets) {
71
60
  const netPins = nets[netName];
72
61
  netItems.push([
73
62
  Id('net'),
@@ -77,7 +66,6 @@ export function generateKiCADNetList(netlist: NetListItem[]): string {
77
66
  ]);
78
67
  counter++;
79
68
  }
80
-
81
69
  const tree = [
82
70
  Id("export"),
83
71
  [Id("version"), "E"],
@@ -89,43 +77,33 @@ export function generateKiCADNetList(netlist: NetListItem[]): string {
89
77
  [Id('components'), ...componentsList],
90
78
  [Id('nets'), ...netItems]
91
79
  ];
92
-
93
80
  return printTree(tree);
94
81
  }
95
-
96
- function printTree(tree: (IdObject | string)[] | string, level = 0): string {
82
+ exports.generateKiCADNetList = generateKiCADNetList;
83
+ function printTree(tree, level = 0) {
97
84
  const output = [];
98
-
99
- // If a single item, then just return the value
100
85
  if (!Array.isArray(tree)) {
101
86
  return "\"" + tree + "\"";
102
87
  }
103
-
104
- const firstItem = tree[0] as IdObject;
88
+ const firstItem = tree[0];
105
89
  output.push(firstItem.keyName);
106
-
107
- const padding = "".padStart(2 * (level+1));
108
-
90
+ const padding = "".padStart(2 * (level + 1));
109
91
  for (let i = 1; i < tree.length; i++) {
110
92
  const result = printTree(tree[i], level + 1);
111
93
  if (result[0] === "(") {
112
94
  output.push("\n" + padding + result);
113
- } else {
95
+ }
96
+ else {
114
97
  output.push(result);
115
98
  }
116
99
  }
117
-
118
100
  return "(" + output.join(" ") + ")";
119
101
  }
120
-
121
-
122
- function Id(name): IdObject {
102
+ function Id(name) {
123
103
  return new IdObject(name);
124
104
  }
125
-
126
105
  class IdObject {
127
- keyName: string;
128
- constructor(keyName: string) {
106
+ constructor(keyName) {
129
107
  this.keyName = keyName;
130
108
  }
131
- }
109
+ }