circuitscript 0.0.22 → 0.0.25

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 (180) hide show
  1. package/dist/cjs/BaseVisitor.js +487 -0
  2. package/dist/cjs/SemanticTokenVisitor.js +218 -0
  3. package/dist/cjs/SymbolValidatorVisitor.js +233 -0
  4. package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
  5. package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
  6. package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
  7. package/dist/cjs/draw_symbols.js +819 -0
  8. package/dist/cjs/execute.js +778 -0
  9. package/{src/export.ts → dist/cjs/export.js} +34 -56
  10. package/dist/cjs/fonts.js +4 -0
  11. package/dist/cjs/geometry.js +450 -0
  12. package/dist/cjs/globals.js +60 -0
  13. package/dist/cjs/helpers.js +269 -0
  14. package/dist/cjs/index.js +31 -0
  15. package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
  16. package/dist/cjs/lexer.js +111 -0
  17. package/dist/cjs/logger.js +17 -0
  18. package/dist/cjs/main.js +82 -0
  19. package/dist/cjs/objects/ClassComponent.js +145 -0
  20. package/dist/cjs/objects/ExecutionScope.js +135 -0
  21. package/dist/cjs/objects/Frame.js +22 -0
  22. package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
  23. package/dist/cjs/objects/ParamDefinition.js +42 -0
  24. package/dist/cjs/objects/PinDefinition.js +31 -0
  25. package/dist/cjs/objects/PinTypes.js +11 -0
  26. package/dist/cjs/objects/Wire.js +9 -0
  27. package/dist/cjs/objects/types.js +15 -0
  28. package/dist/cjs/parser.js +70 -0
  29. package/dist/cjs/regenerate-tests.js +23 -0
  30. package/dist/cjs/render.js +155 -0
  31. package/{src/server.ts → dist/cjs/server.js} +15 -21
  32. package/dist/cjs/sizing.js +105 -0
  33. package/{src/utils.ts → dist/cjs/utils.js} +25 -35
  34. package/dist/cjs/validate.js +81 -0
  35. package/dist/cjs/visitor.js +844 -0
  36. package/dist/esm/BaseVisitor.mjs +488 -0
  37. package/dist/esm/SemanticTokenVisitor.mjs +215 -0
  38. package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
  39. package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
  40. package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
  41. package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
  42. package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
  43. package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
  44. package/{build/src/export.js → dist/esm/export.mjs} +2 -2
  45. package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
  46. package/dist/esm/helpers.mjs +252 -0
  47. package/dist/esm/index.mjs +15 -0
  48. package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
  49. package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
  50. package/{build/src/main.js → dist/esm/main.mjs} +9 -14
  51. package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
  52. package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
  53. package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
  54. package/dist/esm/objects/types.mjs +12 -0
  55. package/dist/esm/parser.mjs +64 -0
  56. package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
  57. package/{build/src/render.js → dist/esm/render.mjs} +7 -24
  58. package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
  59. package/{src/main.ts → dist/esm/validate.mjs} +31 -62
  60. package/dist/esm/visitor.mjs +838 -0
  61. package/dist/types/BaseVisitor.d.ts +69 -0
  62. package/dist/types/SemanticTokenVisitor.d.ts +36 -0
  63. package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
  64. package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
  65. package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
  66. package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
  67. package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
  68. package/{build/src → dist/types}/execute.d.ts +6 -9
  69. package/{build/src → dist/types}/geometry.d.ts +5 -1
  70. package/dist/types/helpers.d.ts +40 -0
  71. package/dist/types/index.d.ts +15 -0
  72. package/{build/src → dist/types}/layout.d.ts +10 -10
  73. package/{build/src → dist/types}/lexer.d.ts +2 -2
  74. package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
  75. package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
  76. package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
  77. package/{build/src → dist/types}/objects/types.d.ts +5 -0
  78. package/dist/types/parser.d.ts +25 -0
  79. package/{build/src → dist/types}/render.d.ts +1 -1
  80. package/{build/src → dist/types}/sizing.d.ts +3 -1
  81. package/dist/types/validate.d.ts +2 -0
  82. package/dist/types/visitor.d.ts +80 -0
  83. package/libs/lib.cst +0 -2
  84. package/package.json +38 -15
  85. package/.editorconfig +0 -15
  86. package/.eslintignore +0 -1
  87. package/.eslintrc.json +0 -27
  88. package/.gitlab-ci.yml +0 -81
  89. package/.prettierignore +0 -8
  90. package/.prettierrc +0 -16
  91. package/__tests__/expectedResults.ts +0 -657
  92. package/__tests__/helpers.ts +0 -82
  93. package/__tests__/parseScripts.ts +0 -593
  94. package/__tests__/renderData/script1.cst +0 -58
  95. package/__tests__/renderData/script1.cst.svg +0 -1
  96. package/__tests__/renderData/script2.cst +0 -16
  97. package/__tests__/renderData/script2.cst.svg +0 -1
  98. package/__tests__/renderData/script3.cst +0 -30
  99. package/__tests__/renderData/script3.cst.svg +0 -1
  100. package/__tests__/renderData/script4.cst +0 -54
  101. package/__tests__/renderData/script4.cst.svg +0 -1
  102. package/__tests__/renderData/script5.cst +0 -23
  103. package/__tests__/renderData/script5.cst.svg +0 -1
  104. package/__tests__/renderData/script6.cst +0 -28
  105. package/__tests__/renderData/script6.cst.svg +0 -1
  106. package/__tests__/renderData/script7.cst +0 -26
  107. package/__tests__/renderData/script7.cst.svg +0 -1
  108. package/__tests__/renderData/script8.cst +0 -37
  109. package/__tests__/renderData/script8.cst.svg +0 -1
  110. package/__tests__/testCLI.ts +0 -68
  111. package/__tests__/testMathOps.ts +0 -36
  112. package/__tests__/testMergeWires.ts +0 -141
  113. package/__tests__/testParse.ts +0 -263
  114. package/__tests__/testRender.ts +0 -38
  115. package/build/src/antlr/CircuitScriptLexer.js +0 -287
  116. package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
  117. package/build/src/antlr/CircuitScriptParser.js +0 -4841
  118. package/build/src/helpers.d.ts +0 -1
  119. package/build/src/helpers.js +0 -73
  120. package/build/src/objects/types.js +0 -6
  121. package/build/src/parser.js +0 -69
  122. package/build/src/visitor.d.ts +0 -133
  123. package/build/src/visitor.js +0 -1154
  124. package/documentation.md +0 -238
  125. package/examples/example_arduino_uno.cst +0 -1146
  126. package/examples/example_garden_pump.cst +0 -567
  127. package/examples/lib.cst +0 -185
  128. package/jest.config.js +0 -23
  129. package/refresh.html +0 -42
  130. package/server.cjs +0 -50
  131. package/src/antlr/CircuitScript.g4 +0 -209
  132. package/src/antlr/CircuitScriptLexer.ts +0 -317
  133. package/src/antlr/CircuitScriptParser.ts +0 -4979
  134. package/src/antlr/CircuitScriptVisitor.ts +0 -420
  135. package/src/draw_symbols.ts +0 -1085
  136. package/src/execute.ts +0 -1227
  137. package/src/fonts.ts +0 -1
  138. package/src/geometry.ts +0 -638
  139. package/src/globals.ts +0 -67
  140. package/src/helpers.ts +0 -114
  141. package/src/lexer.ts +0 -151
  142. package/src/logger.ts +0 -17
  143. package/src/objects/ClassComponent.ts +0 -223
  144. package/src/objects/ExecutionScope.ts +0 -201
  145. package/src/objects/Frame.ts +0 -20
  146. package/src/objects/ParamDefinition.ts +0 -49
  147. package/src/objects/PinDefinition.ts +0 -49
  148. package/src/objects/PinTypes.ts +0 -7
  149. package/src/objects/Wire.ts +0 -19
  150. package/src/objects/types.ts +0 -66
  151. package/src/parser.ts +0 -106
  152. package/src/regenerate-tests.ts +0 -25
  153. package/src/render.ts +0 -260
  154. package/src/sizing.ts +0 -96
  155. package/src/visitor.ts +0 -1691
  156. package/tsconfig.json +0 -27
  157. package/tsconfig.release.json +0 -8
  158. /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
  159. /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
  160. /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
  161. /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
  162. /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
  163. /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
  164. /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
  165. /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
  166. /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
  167. /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
  168. /package/{build/src → dist/types}/export.d.ts +0 -0
  169. /package/{build/src → dist/types}/fonts.d.ts +0 -0
  170. /package/{build/src → dist/types}/globals.d.ts +0 -0
  171. /package/{build/src → dist/types}/logger.d.ts +0 -0
  172. /package/{build/src → dist/types}/main.d.ts +0 -0
  173. /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
  174. /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
  175. /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
  176. /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
  177. /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
  178. /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
  179. /package/{build/src → dist/types}/server.d.ts +0 -0
  180. /package/{build/src → dist/types}/utils.d.ts +0 -0
@@ -1,82 +0,0 @@
1
- import { dirname } from 'path';
2
-
3
- import CircuitScriptParser from '../src/antlr/CircuitScriptParser.js';
4
-
5
- import { CharStream, CommonTokenStream } from 'antlr4';
6
- import { MainVisitor } from '../src/visitor.js';
7
- import { ComponentPinNet } from '../src/objects/types.js';
8
- import { CircuitscriptParserErrorListener } from '../src/parser.js';
9
- import { ClassComponent } from '../src/objects/ClassComponent.js';
10
- import { MainLexer } from '../src/lexer.js';
11
-
12
-
13
- export async function runScript(script: string): Promise<{
14
- visitor: MainVisitor,
15
- hasError: boolean,
16
- componentPinNets: ComponentPinNet[]
17
- }> {
18
-
19
- const chars = new CharStream(script);
20
- const lexer = new MainLexer(chars);
21
- const tokens = new CommonTokenStream(lexer);
22
-
23
- const parser = new CircuitScriptParser(tokens);
24
- // Clear any existing error listeners and use the custom one only
25
- parser.removeErrorListeners();
26
-
27
- const errorListener = new CircuitscriptParserErrorListener();
28
- parser.addErrorListener(errorListener);
29
-
30
- const tree = parser.script();
31
-
32
- const scriptPath = "./examples/helpers.ts";
33
- const defaultLibsPath = "./libs";
34
-
35
- const visitor = new MainVisitor(true);
36
- visitor.printToConsole = false; // do not clutter the console log
37
-
38
- const currentDirectory = dirname(scriptPath);
39
- visitor.onImportFile = visitor.createImportFileHandler(currentDirectory, defaultLibsPath);
40
-
41
- let hasError = false;
42
- try {
43
- visitor.visit(tree);
44
- } catch (err) {
45
- // Error should be internally handled in visitor
46
- err.print(script);
47
- hasError = true;
48
- }
49
-
50
- hasError = hasError || errorListener.hasParseErrors();
51
-
52
- return {
53
- visitor, hasError,
54
- componentPinNets: visitor.dumpNets(),
55
- }
56
- }
57
-
58
- export function findItem(instances: Map<string, ClassComponent>, typeProp: string,
59
- refdes: string, value: string): ClassComponent | null {
60
- // Find matching item by refdes and by value parameter
61
-
62
- for (const [, instance] of instances) {
63
- if (instance.typeProp === typeProp && instance.assignedRefDes === refdes) {
64
- if (instance.parameters.get('value').toString() === value) {
65
- return instance;
66
- }
67
- }
68
- }
69
-
70
- return null;
71
- }
72
-
73
- export function findItemByRefDes(instances: Map<string, ClassComponent>, typeProp: string,
74
- refdes: string): ClassComponent | null {
75
- for (const [, instance] of instances) {
76
- if (instance.typeProp === typeProp && instance.assignedRefDes === refdes) {
77
- return instance;
78
- }
79
- }
80
-
81
- return null;
82
- }
@@ -1,593 +0,0 @@
1
- import { ComponentPinNet } from "../src/objects/types";
2
-
3
-
4
- export class ScriptTest {
5
-
6
- script: string;
7
- expected: ComponentPinNet[];
8
-
9
- constructor(script:string, expected: ComponentPinNet[]){
10
- this.script = script;
11
- this.expected = expected;
12
- }
13
- }
14
-
15
- export const script1 = new ScriptTest(`
16
- U1 = create component:
17
- pins: 10
18
-
19
- U2 = create component:
20
- pins: 10
21
-
22
- at U1:
23
- 2:
24
- wire right 200
25
- to U2 pin 1
26
-
27
- at U1 pin 10
28
- wire right 180 up 40
29
-
30
- branch:
31
- wire auto
32
- to U2 pin 5
33
-
34
- wire auto
35
- to U2 pin 3
36
- `, [
37
- ['/NET_1', 'U1', 2],
38
- ['/NET_1', 'U2', 1],
39
- ['/NET_2', 'U1', 10],
40
- ['/NET_2', 'U2', 5],
41
- ['/NET_2', 'U2', 3]
42
- ]);
43
-
44
- export const script2 = new ScriptTest(`
45
- import lib
46
- gnd = dgnd()
47
-
48
- # Test functions
49
- def power_input():
50
- return create component:
51
- pins: 3
52
- arrange:
53
- left: 1,3
54
- right: 2
55
-
56
-
57
- J1 = power_input()
58
-
59
- at J1 pin 1
60
- wire left 20 down 20
61
-
62
- branch:
63
- wire right 20
64
- to J1 pin 3
65
-
66
- wire down 20
67
- to gnd
68
- `, [
69
- [ '/GND', 'gnd', 1 ],
70
- [ '/GND', 'J1', 1 ],
71
- [ '/GND', 'J1', 3 ],
72
- [ '/GND', 'gnd:0', 1 ]
73
- ]);
74
-
75
- export const script3 = new ScriptTest(`
76
- import lib
77
-
78
- at label("hello")
79
- wire right 40
80
-
81
- branch:
82
- wire down 40
83
-
84
- branch:
85
- wire down 20
86
- add diode() ..angle = 90
87
-
88
- wire left 20
89
- add diode() pin 2
90
- wire left 20 down 20
91
- add diode() ..angle = 90
92
-
93
- wire right 40
94
- add diode()
95
- `, [
96
- [ '/NET_1', 'diode_1.COMP_1', 1 ],
97
- [ '/NET_1', 'diode_2.COMP_1', 1 ],
98
- [ '/hello', 'label_0.COMP_1_1', 1 ],
99
- [ '/hello', 'label_0.COMP_1_1:0', 1 ],
100
- [ '/hello', 'diode_0.COMP_1', 1 ],
101
- [ '/hello', 'diode_1.COMP_1', 2 ],
102
- [ '/hello', 'diode_3.COMP_1', 1 ]
103
- ]);
104
-
105
- export const script6 = new ScriptTest(`
106
- import lib
107
-
108
- vcc = net("3v3")
109
- midpt = net("out")
110
- gnd = dgnd()
111
-
112
- at vcc
113
- wire down 20
114
- add res(20k) down
115
- wire down 20
116
- branch:
117
- wire down 20
118
- add res(20k) down
119
- wire down 20
120
- to gnd
121
- wire right 60
122
- to midpt ..angle = 90
123
-
124
- at vcc
125
- wire down 20
126
- add res(10k) down
127
- wire down 20 right 40 up 20
128
- to midpt
129
- `, [
130
- [ '/3v3', 'vcc', 1 ],
131
- [ '/3v3', 'vcc:0', 1 ],
132
- [ '/3v3', 'res_0.COMP_1_20k', 1 ],
133
- [ '/3v3', 'vcc:1', 1 ],
134
- [ '/3v3', 'res_2.COMP_1_10k', 1 ],
135
- [ '/GND', 'gnd', 1 ],
136
- [ '/GND', 'gnd:0', 1 ],
137
- [ '/GND', 'res_1.COMP_1_20k', 2 ],
138
- [ '/out', 'midpt', 1 ],
139
- [ '/out', 'res_0.COMP_1_20k', 2 ],
140
- [ '/out', 'res_1.COMP_1_20k', 1 ],
141
- [ '/out', 'midpt:0', 1 ],
142
- [ '/out', 'midpt:1', 1 ],
143
- [ '/out', 'res_2.COMP_1_10k', 2 ]
144
- ]);
145
-
146
- export const script7 = new ScriptTest(`
147
- import lib
148
-
149
- v5v = net("5V")
150
- gnd = dgnd()
151
-
152
- def tmp1():
153
- at v5v
154
- wire down 20
155
- add res(10k)
156
- wire down 20
157
- to gnd
158
-
159
- tmp1()
160
-
161
- tmp1()
162
- `, [
163
- [ '/5V', 'v5v', 1 ],
164
- [ '/5V', 'tmp1_0.v5v:0', 1 ],
165
- [ '/5V', 'tmp1_0.res_0.COMP_1_10k', 1 ],
166
- [ '/5V', 'tmp1_1.v5v:0', 1 ],
167
- [ '/5V', 'tmp1_1.res_1.COMP_1_10k', 1 ],
168
- [ '/GND', 'gnd', 1 ],
169
- [ '/GND', 'tmp1_0.gnd:0', 1 ],
170
- [ '/GND', 'tmp1_0.res_0.COMP_1_10k', 2 ],
171
- [ '/GND', 'tmp1_1.gnd:0', 1 ],
172
- [ '/GND', 'tmp1_1.res_1.COMP_1_10k', 2 ]
173
- ]);
174
-
175
- export const script8 = new ScriptTest(`
176
- import lib
177
-
178
- v5v = supply("5v")
179
- gnd = dgnd()
180
-
181
- def divider(power_net, r1, r2, output_net):
182
- at power_net
183
- wire down 20
184
- add res(r1) down
185
- wire down 20
186
-
187
- branch:
188
- wire right 20
189
- add output_net
190
- wire right 20
191
-
192
- wire down 20
193
- add res(r2) down
194
- wire down 20
195
- to gnd
196
-
197
- divider(v5v, 10k, 20k, label("hello"))
198
- `, [
199
- [ '/5v', 'v5v', 1 ],
200
- [ '/5v', 'divider_0.v5v:0', 1 ],
201
- [ '/5v', 'divider_0.res_0.COMP_1_10k', 1 ],
202
- [ '/GND', 'gnd', 1 ],
203
- [ '/GND', 'divider_0.gnd:0', 1 ],
204
- [ '/GND', 'divider_0.res_1.COMP_1_20k', 2 ],
205
- [ '/hello', 'label_0.COMP_1_1', 1 ],
206
- [ '/hello', 'divider_0.res_0.COMP_1_10k', 2 ],
207
- [ '/hello', 'divider_0.res_1.COMP_1_20k', 1 ]
208
- ]);
209
-
210
- export const script9 = new ScriptTest(`
211
- import lib
212
-
213
- v5v = supply("5v")
214
- gnd = dgnd()
215
-
216
- net("global_name")
217
-
218
- def divider(power_net, r1, r2, net_name):
219
- frame:
220
- ..border = 0
221
-
222
- at power_net
223
- wire down 20
224
- add res(r1) down
225
- wire down 20
226
-
227
- branch:
228
- wire right 20
229
- add label("inner_name")
230
- wire right 60
231
- add res(100k) right
232
- wire right 20
233
- add / label("global_name")
234
- wire right 40
235
-
236
- add res(0)
237
-
238
- add / label("global_name_2")
239
-
240
- wire down 20
241
- add res(r2) down
242
- wire down 20
243
- to gnd
244
-
245
- frame:
246
- ..border = 0
247
- ..direction = "row"
248
-
249
- /div1 divider(v5v, 10k, 20k, "hello2")
250
- /div2 divider(v5v, 10k, 20k, "hello1")
251
- `, [
252
- [ '/5v', 'v5v', 1 ],
253
- [ '/5v', 'divider_0.v5v:0', 1 ],
254
- [ '/5v', 'divider_0.res_0.COMP_1_10k', 1 ],
255
- [ '/5v', 'divider_1.v5v:0', 1 ],
256
- [ '/5v', 'divider_1.res_4.COMP_1_10k', 1 ],
257
- [ '/GND', 'gnd', 1 ],
258
- [ '/GND', 'divider_0.gnd:0', 1 ],
259
- [ '/GND', 'divider_0.res_3.COMP_1_20k', 2 ],
260
- [ '/GND', 'divider_1.gnd:0', 1 ],
261
- [ '/GND', 'divider_1.res_7.COMP_1_20k', 2 ],
262
- [ '/div1/inner_name', 'divider_0.label_0.COMP_1_1', 1 ],
263
- [ '/div1/inner_name', 'divider_0.res_0.COMP_1_10k', 2 ],
264
- [ '/div1/inner_name', 'divider_0.res_1.COMP_1_100k', 1 ],
265
- [ '/div1/inner_name', 'divider_0.res_3.COMP_1_20k', 1 ],
266
- [ '/div2/inner_name', 'divider_1.label_3.COMP_1_1', 1 ],
267
- [ '/div2/inner_name', 'divider_1.res_4.COMP_1_10k', 2 ],
268
- [ '/div2/inner_name', 'divider_1.res_5.COMP_1_100k', 1 ],
269
- [ '/div2/inner_name', 'divider_1.res_7.COMP_1_20k', 1 ],
270
- [ '/global_name', 'net_0.COMP_1_1', 1 ],
271
- [ '/global_name', 'divider_0.label_1.COMP_1_1', 1 ],
272
- [ '/global_name', 'divider_0.res_1.COMP_1_100k', 2 ],
273
- [ '/global_name', 'divider_0.res_2.COMP_1_0', 1 ],
274
- [ '/global_name', 'divider_1.label_4.COMP_1_1', 1 ],
275
- [ '/global_name', 'divider_1.res_5.COMP_1_100k', 2 ],
276
- [ '/global_name', 'divider_1.res_6.COMP_1_0', 1 ],
277
- [ '/global_name_2', 'divider_0.label_2.COMP_1_1', 1 ],
278
- [ '/global_name_2', 'divider_0.res_2.COMP_1_0', 2 ],
279
- [ '/global_name_2', 'divider_1.label_5.COMP_1_1', 1 ],
280
- [ '/global_name_2', 'divider_1.res_6.COMP_1_0', 2 ]
281
- ]);
282
-
283
- export const script10 = new ScriptTest(`
284
- import lib
285
- gnd = dgnd()
286
-
287
- at v5v = supply("5V")
288
- wire down 20
289
- add R1 = res(10k) down
290
- wire down 20
291
- add R2 = res(10k) down
292
- wire down 20
293
- to C1 = cap(10n) down
294
-
295
- at C1 pin 2
296
- wire down 20
297
- to gnd
298
- `, [
299
- ['/5V', 'v5v', 1],
300
- ['/5V', 'v5v:0', 1],
301
- ['/5V', 'R1', 1],
302
- ['/GND', 'gnd', 1],
303
- ['/GND', 'gnd:0', 1],
304
- ['/GND', 'C1', 2],
305
- ['/NET_1', 'R1', 2],
306
- ['/NET_1', 'R2', 1],
307
- ['/NET_2', 'R2', 2],
308
- ['/NET_2', 'C1', 1]
309
- ]);
310
-
311
- export const script11 = new ScriptTest(`
312
- import lib
313
-
314
- v5v = supply("5V")
315
-
316
- def tmp1():
317
- wire right 20
318
- add res(0)
319
- wire right 20
320
- add label("label_1")
321
-
322
- wire right 40
323
- add res(0)
324
- add / label("global_label")
325
-
326
- wire right 80
327
- add res(0)
328
-
329
- +/inner tmp2()
330
-
331
- def tmp2():
332
- wire right 20
333
- add res(0)
334
- add label("label_2")
335
- wire right 40
336
-
337
- at v5v
338
- wire down 20
339
- branch:
340
- /scope1 tmp1()
341
-
342
- wire down 40
343
- branch:
344
- /scope2 tmp1()
345
- `, [
346
- ['/5V', 'v5v', 1],
347
- ['/5V', 'v5v:0', 1],
348
- ['/5V', 'tmp1_0.__root', 1],
349
- ['/5V', 'tmp1_0.res_0.COMP_1_0', 1],
350
- ['/5V', 'tmp1_1.__root', 1],
351
- ['/5V', 'tmp1_1.res_4.COMP_1_0', 1],
352
- ['/global_label', 'tmp1_0.label_1.COMP_1_1', 1],
353
- ['/global_label', 'tmp1_0.res_1.COMP_1_0', 2],
354
- ['/global_label', 'tmp1_0.res_2.COMP_1_0', 1],
355
- ['/global_label', 'tmp1_1.label_4.COMP_1_1', 1],
356
- ['/global_label', 'tmp1_1.res_5.COMP_1_0', 2],
357
- ['/global_label', 'tmp1_1.res_6.COMP_1_0', 1],
358
- ['/scope1/inner/NET_1', 'tmp2_0.__root', 1],
359
- ['/scope1/inner/NET_1', 'tmp1_0.tmp2_0.res_3.COMP_1_0', 1],
360
- ['/scope1/inner/NET_1', 'tmp1_0.res_2.COMP_1_0', 2],
361
- ['/scope1/inner/label_2', 'tmp1_0.tmp2_0.label_2.COMP_1_1', 1],
362
- ['/scope1/inner/label_2', 'tmp1_0.tmp2_0.res_3.COMP_1_0', 2],
363
- ['/scope1/label_1', 'tmp1_0.label_0.COMP_1_1', 1],
364
- ['/scope1/label_1', 'tmp1_0.res_0.COMP_1_0', 2],
365
- ['/scope1/label_1', 'tmp1_0.res_1.COMP_1_0', 1],
366
- ['/scope2/inner/NET_1', 'tmp2_1.__root', 1],
367
- ['/scope2/inner/NET_1', 'tmp1_1.tmp2_1.res_7.COMP_1_0', 1],
368
- ['/scope2/inner/NET_1', 'tmp1_1.res_6.COMP_1_0', 2],
369
- ['/scope2/inner/label_2', 'tmp1_1.tmp2_1.label_5.COMP_1_1', 1],
370
- ['/scope2/inner/label_2', 'tmp1_1.tmp2_1.res_7.COMP_1_0', 2],
371
- ['/scope2/label_1', 'tmp1_1.label_3.COMP_1_1', 1],
372
- ['/scope2/label_1', 'tmp1_1.res_4.COMP_1_0', 2],
373
- ['/scope2/label_1', 'tmp1_1.res_5.COMP_1_0', 1]
374
- ]);
375
-
376
- export const script12 = new ScriptTest(`
377
- my_net = create component:
378
- pins: 1
379
- params:
380
- __is_net: 1
381
- net_name: "hello"
382
-
383
- at my_net
384
- `, [
385
- ['/hello', 'my_net', 1],
386
- ['/hello', 'my_net:0', 1
387
- ]]);
388
-
389
-
390
- /*
391
- After a function call, the correct graph position should be resumed from.
392
- This test also checks the join keyword
393
- */
394
- export const script13 = new ScriptTest(`import lib
395
-
396
- v5v = supply("5V")
397
- gnd = dgnd()
398
-
399
- def led_with_res():
400
- add led("yellow") pin 2 right
401
- wire right 20
402
- add res(1k)
403
- wire right 20
404
-
405
- join:
406
- at gnd left
407
- wire right 20
408
- add label("TXLED")
409
- wire right 60
410
- led_with_res()
411
-
412
- join:
413
- at gnd left
414
- wire right 20
415
- add label("RXLED")
416
- wire right 60
417
- led_with_res()
418
- wire up 100
419
-
420
- wire up 20
421
- to v5v`,
422
- [
423
- [ '/5V', 'v5v', 1 ],
424
- [ '/5V', 'led_with_res_0.res_0.COMP_1_1k', 2 ],
425
- [ '/5V', '_join.__.0', 1 ],
426
- [ '/5V', 'led_with_res_1.res_1.COMP_1_1k', 2 ],
427
- [ '/5V', 'v5v:0', 1 ],
428
- [ '/GND', 'gnd', 1 ],
429
- [ '/GND', 'gnd:0', 1 ],
430
- [ '/GND', 'label_0.COMP_1_1', 1 ],
431
- [ '/GND', 'led_with_res_0.__root', 1 ],
432
- [ '/GND', 'led_with_res_0.led_0.COMP_1_0603', 2 ],
433
- [ '/GND', 'gnd:1', 1 ],
434
- [ '/GND', 'label_1.COMP_1_1', 1 ],
435
- [ '/GND', 'led_with_res_1.__root', 1 ],
436
- [ '/GND', 'led_with_res_1.led_1.COMP_1_0603', 2 ],
437
- [ '/NET_2', 'led_with_res_0.led_0.COMP_1_0603', 1 ],
438
- [ '/NET_2', 'led_with_res_0.res_0.COMP_1_1k', 1 ],
439
- [ '/NET_2', 'led_with_res_1.led_1.COMP_1_0603', 1 ],
440
- [ '/NET_2', 'led_with_res_1.res_1.COMP_1_1k', 1 ]
441
- ]);
442
-
443
-
444
-
445
- /**
446
- Tests the `point` branching keyword
447
- */
448
- export const script14 = new ScriptTest(`
449
- import lib
450
-
451
- v5v = supply("5V")
452
- gnd = dgnd()
453
-
454
- at v5v
455
- wire down 20
456
- add res(360) down
457
- wire down 20
458
-
459
- point:
460
- at v5v
461
- wire down 20
462
- add res(360) down
463
- wire down 20
464
-
465
- branch:
466
- wire left 100
467
- to point
468
-
469
- wire down 20
470
- add res(360) down
471
- wire down 20
472
- to gnd
473
-
474
- at point
475
- wire right 200 down 20
476
- add res(360) down
477
- wire down 20
478
- to gnd
479
-
480
- wire down 20
481
- add led("red") down
482
- wire down 40
483
- to gnd`, [
484
- [ '/5V', 'v5v', 1 ],
485
- [ '/5V', 'v5v:0', 1 ],
486
- [ '/5V', 'res_0.COMP_1_360', 1 ],
487
- [ '/5V', 'v5v:1', 1 ],
488
- [ '/5V', 'res_1.COMP_1_360', 1 ],
489
- [ '/GND', 'gnd', 1 ],
490
- [ '/GND', 'gnd:0', 1 ],
491
- [ '/GND', 'res_2.COMP_1_360', 2 ],
492
- [ '/GND', 'gnd:1', 1 ],
493
- [ '/GND', 'res_3.COMP_1_360', 2 ],
494
- [ '/GND', 'gnd:2', 1 ],
495
- [ '/GND', 'led_0.COMP_1_0603', 2 ],
496
- [ '/NET_1', 'res_0.COMP_1_360', 2 ],
497
- [ '/NET_1', '_point.__.0', 1 ],
498
- [ '/NET_1', 'res_1.COMP_1_360', 2 ],
499
- [ '/NET_1', 'res_2.COMP_1_360', 1 ],
500
- [ '/NET_1', 'res_3.COMP_1_360', 1 ],
501
- [ '/NET_1', 'led_0.COMP_1_0603', 1 ]
502
- ]);
503
-
504
- /*
505
- Test with `paralell` keyword
506
- */
507
- export const script15 = new ScriptTest(`
508
- import lib
509
-
510
- v5v = supply("5V")
511
- gnd = dgnd()
512
-
513
- at v5v
514
- wire down 20
515
-
516
- parallel:
517
- wire down 20
518
- add res(1k) down
519
- wire down 20
520
-
521
- parallel:
522
- wire right 60 down 20
523
- add res(1k) down
524
- wire auto
525
-
526
- parallel:
527
- wire right 120 down 20
528
- add res(1k) down
529
- wire auto
530
-
531
- wire down 20
532
- to gnd
533
- `, [
534
- ['/5V', 'v5v', 1],
535
- ['/5V', 'v5v:0', 1],
536
- ['/5V', '_parallel.__.0', 1],
537
- ['/5V', 'res_0.COMP_1_1k', 1],
538
- ['/5V', 'res_1.COMP_1_1k', 1],
539
- ['/5V', 'res_2.COMP_1_1k', 1],
540
- ['/GND', 'gnd', 1],
541
- ['/GND', 'res_0.COMP_1_1k', 2],
542
- ['/GND', '_parallel.__.1', 1],
543
- ['/GND', 'res_1.COMP_1_1k', 2],
544
- ['/GND', 'res_2.COMP_1_1k', 2],
545
- ['/GND', 'gnd:0', 1]
546
- ]);
547
-
548
- /*
549
- Test that consecutive blocks with different block type
550
- are parsed correctly.
551
- */
552
- export const script16 = new ScriptTest(`
553
- import lib
554
-
555
- v5v = supply("5V")
556
- gnd = dgnd()
557
-
558
- join:
559
- at v5v
560
- wire down 20
561
- add res(1k) down
562
- wire down 20
563
-
564
- join:
565
- at v5v
566
- wire down 20
567
- add res(1k) down
568
- wire left 100
569
-
570
- point:
571
- at v5v
572
- wire right 20
573
- add res(1k) right
574
- wire right 20
575
- to point
576
-
577
- wire down 20
578
- to gnd`, [
579
- [ '/5V', 'v5v', 1 ],
580
- [ '/5V', 'v5v:0', 1 ],
581
- [ '/5V', 'res_0.COMP_1_1k', 1 ],
582
- [ '/5V', 'v5v:1', 1 ],
583
- [ '/5V', 'res_1.COMP_1_1k', 1 ],
584
- [ '/5V', 'v5v:2', 1 ],
585
- [ '/5V', 'res_2.COMP_1_1k', 1 ],
586
- [ '/GND', 'gnd', 1 ],
587
- [ '/GND', 'res_0.COMP_1_1k', 2 ],
588
- [ '/GND', '_join.__.0', 1 ],
589
- [ '/GND', 'res_1.COMP_1_1k', 2 ],
590
- [ '/GND', '_point.__.1', 1 ],
591
- [ '/GND', 'res_2.COMP_1_1k', 2 ],
592
- [ '/GND', 'gnd:0', 1 ]
593
- ]);