circuitscript 0.0.12 → 0.0.13

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.
package/.gitlab-ci.yml CHANGED
@@ -40,6 +40,7 @@ test_jest:
40
40
  dependencies:
41
41
  - install
42
42
  script:
43
+ - npm run build:release || true
43
44
  - npm run test
44
45
 
45
46
  test_build:
@@ -0,0 +1,23 @@
1
+ import lib
2
+
3
+ v5v = supply("5v")
4
+ gnd = dgnd()
5
+
6
+ at gnd
7
+ wire up 20 right 20
8
+ to D1 = led("GREEN") pin 2 right
9
+ at D1 pin 1
10
+ wire right 20 up 20
11
+ to v5v
12
+
13
+ at v5v
14
+ wire down 20 right 20
15
+ add led("RED")
16
+ wire right 20 down 20
17
+ to gnd
18
+
19
+
20
+ #wire down 20
21
+ #add led("GREEN")
22
+ #wire down 20
23
+ #to gnd
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.dev/svgjs" width="190" height="310.5" viewBox="-25 -25.5 190 310.5"><g transform="matrix(1,0,0,1,0,0)"><path d="M -20 -20.5 L -20 280 M 0 -20.5 L 0 280 M 20 -20.5 L 20 280 M 40 -20.5 L 40 280 M 60 -20.5 L 60 280 M 80 -20.5 L 80 280 M 100 -20.5 L 100 280 M 120 -20.5 L 120 280 M 140 -20.5 L 140 280 M 160 -20.5 L 160 280" fill="none" stroke-dasharray="1,19" stroke-width="1" stroke="#aaaaaa"></path></g><g transform="matrix(1,0,0,1,20,90)"><g><path d="M -10 0 L 10 0 L 0 10 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 -10 L 0 0" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="middle" dominant-baseline="text-top" transform="matrix(1,0,0,1,0,20)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">GND</tspan></text></g></g><g transform="matrix(1,0,0,1,70,60)"><g><path d="M -10.000000000000002 9.999999999999998 L -9.999999999999998 -10.000000000000002" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 9.999999999999998 10.000000000000002 L 10.000000000000002 -9.999999999999998 L -10 -1.2246467991473533e-15 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 9.797174393178826e-16 -8 L -4.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -2.999999999999999 -8 L -7.999999999999998 -18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 30 3.67394039744206e-15 L 10 1.2246467991473533e-15 M -30 -3.67394039744206e-15 L -10 -1.2246467991473533e-15" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="end" dominant-baseline="hanging" transform="matrix(1,0,0,1,-15,5)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">D1</tspan></text></g></g><g transform="matrix(1,0,0,1,120,30.000000000000007)"><g><path d="M -15 0 L 15 0" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 0 10 L 0 0" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="middle" dominant-baseline="text-top" transform="matrix(1,0,0,1,0,-5)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">5v</tspan></text></g></g><g transform="matrix(1,0,0,1,20,170)"><g><path d="M -15 0 L 15 0" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 0 10 L 0 0" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="middle" dominant-baseline="text-top" transform="matrix(1,0,0,1,0,-5)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">5v</tspan></text></g></g><g transform="matrix(1,0,0,1,70,200)"><g><path d="M 10 -10 L 10 10" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -10 -10 L -10 10 L 10 0 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 8 L 5 18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M 3 8 L 8 18" stroke-width="1" stroke="#333333" fill="none"></path><path d="M -30 0 L -10 0 M 30 0 L 10 0" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="start" dominant-baseline="hanging" transform="matrix(1,0,0,1,15,5)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">D2</tspan></text></g></g><g transform="matrix(1,0,0,1,120,230)"><g><path d="M -10 0 L 10 0 L 0 10 Z" stroke-width="1" stroke="#333333" fill="#ffffff"></path><path d="M 0 -10 L 0 0" stroke-width="2" stroke="#333333"></path><text fill="#333333" font-family="Inter" font-size="10" text-anchor="middle" dominant-baseline="text-top" transform="matrix(1,0,0,1,0,20)" svgjs:data="{&quot;leading&quot;:&quot;1.3&quot;}"><tspan dy="0" x="0" svgjs:data="{&quot;newLined&quot;:true}">GND</tspan></text></g></g><g><line x1="20" y1="80" x2="20" y2="60" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="60" x2="40" y2="60" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="100" y1="200" x2="120" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="120" y1="200" x2="120" y2="220" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="100" y1="60.00000000000001" x2="120" y2="60.00000000000001" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="120" y1="60.00000000000001" x2="120" y2="40.00000000000001" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="180" x2="20" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line><line x1="20" y1="200" x2="40" y2="200" stroke-linecap="square" stroke-width="1" stroke="#008400" fill="none"></line></g><g></g></svg>
@@ -0,0 +1,68 @@
1
+ import { execSync } from 'child_process';
2
+ import figlet from 'figlet';
3
+ import { existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
4
+
5
+ describe('test cli program', () => {
6
+
7
+ const tmpFolder = '__tests__/tmp';
8
+
9
+ const baseCommand = 'node build/src/main.js';
10
+
11
+ test('start program and display help', () => {
12
+ const result = execSync(baseCommand).toString();
13
+ const circuitscriptText = figlet.textSync('circuitscript', {
14
+ font: 'Small Slant'
15
+ });
16
+
17
+ expect(result.includes(circuitscriptText)).toBe(true);
18
+
19
+ const options =
20
+ `Options:
21
+ -V, --version output the version number
22
+ -i, --input text <input text> Input text directly
23
+ -f, --input-file <path> Input file
24
+ -o, --output <path> Output path
25
+ -c, --current-directory <path> Set current directory
26
+ -k, --kicad-netlist <filename> Create KiCad netlist
27
+ -w, --watch Watch for file changes
28
+ -n, --dump-nets Dump out net information
29
+ -d, --dump-data Dump data during parsing
30
+ -s, --stats Show stats during generation
31
+ -h, --help display help for command`
32
+
33
+ expect(result.includes(options)).toBe(true);
34
+ });
35
+
36
+ test('pass in file and output directly', () => {
37
+ const result = execSync(baseCommand + ' -f __tests__/renderData/script1.cst').toString();
38
+ const expected = readFileSync('__tests__/renderData/script1.cst.svg').toString();
39
+ expect(result.trim()).toBe(expected);
40
+ });
41
+
42
+ test.each([false, true])('pass in file and output file (with stats: %s)', (withStatsFlag: boolean) => {
43
+ const outputPath = '__tests__/tmp/result1.svg';
44
+ if (existsSync(outputPath)) {
45
+ unlinkSync(outputPath);
46
+ }
47
+
48
+ if (!existsSync(tmpFolder)) {
49
+ mkdirSync(tmpFolder);
50
+ }
51
+
52
+ const statsFlag = withStatsFlag ? ' -s ' : '';
53
+
54
+ const result = execSync(`${baseCommand} -f __tests__/renderData/script1.cst -o ${outputPath} ${statsFlag}`).toString();
55
+
56
+ const outputFile = readFileSync(outputPath).toString();
57
+ const expected = readFileSync('__tests__/renderData/script1.cst.svg').toString();
58
+
59
+ expect(outputFile.trim()).toBe(expected.trim());
60
+
61
+ expect(
62
+ result.includes('Lexing took:') &&
63
+ result.includes('Parsing took:') &&
64
+ result.includes('Layout took:') &&
65
+ result.includes('Render took:')
66
+ ).toBe(withStatsFlag);
67
+ });
68
+ });
@@ -12,7 +12,8 @@ describe('Render tests', () => {
12
12
  ['variant and branch rendering', 'script1.cst'],
13
13
  ['simple function', 'script2.cst'],
14
14
  ['simple frame', 'script3.cst'],
15
- ['drawing functions for graphics', 'script4.cst']
15
+ ['drawing functions for graphics', 'script4.cst'],
16
+ ['drawing 180 deg flipped components', 'script5.cst']
16
17
 
17
18
  ])('render - %s (%s)', async (title, scriptPath) => {
18
19
 
@@ -102,7 +102,8 @@ export class SymbolGraphic {
102
102
  let anchorStyle = 'start';
103
103
  let dominantBaseline = 'auto';
104
104
  let useAnchor = anchor;
105
- if (this.angle === 180) {
105
+ const isRotation180 = Math.abs(this.angle) === 180;
106
+ if (isRotation180) {
106
107
  useAnchor = this.flipTextAnchor(anchor);
107
108
  }
108
109
  switch (useAnchor) {
@@ -140,7 +141,7 @@ export class SymbolGraphic {
140
141
  anchor: anchorStyle,
141
142
  'dominant-baseline': dominantBaseline,
142
143
  });
143
- if (this.angle === 180) {
144
+ if (isRotation180) {
144
145
  text.translate(-position[0], position[1]);
145
146
  }
146
147
  else {
package/build/src/main.js CHANGED
@@ -15,6 +15,8 @@ import { SimpleStopwatch } from './utils.js';
15
15
  export default async function main() {
16
16
  const toolSrcPath = fileURLToPath(import.meta.url);
17
17
  const toolDirectory = path.dirname(toolSrcPath) + '/../../';
18
+ const fontsPath = toolDirectory + '/fonts';
19
+ const defaultLibsPath = toolDirectory + '/libs';
18
20
  const packageJson = JSON.parse(readFileSync(toolDirectory + 'package.json').toString());
19
21
  ;
20
22
  const { version } = packageJson;
@@ -44,8 +46,6 @@ export default async function main() {
44
46
  const dumpData = options.dumpData;
45
47
  const kicadNetlist = options.kicadNetlist;
46
48
  let currentDirectory = options.currentDirectory ?? null;
47
- const fontsPath = toolDirectory + '/fonts';
48
- const defaultLibsPath = toolDirectory + '/libs';
49
49
  if (watchFileChanges) {
50
50
  console.log('watching for file changes...');
51
51
  }
@@ -75,7 +75,7 @@ export default async function main() {
75
75
  console.log(output);
76
76
  }
77
77
  if (watchFileChanges) {
78
- watch(inputFilePath, (event, targetFile) => {
78
+ watch(inputFilePath, event => {
79
79
  if (event === 'change') {
80
80
  const scriptData = readFileSync(inputFilePath, { encoding: 'utf-8' });
81
81
  renderScript(scriptData, outputPath, renderOptions);
@@ -93,14 +93,12 @@ export function renderScript(scriptData, outputPath, options) {
93
93
  const { tree, parser, hasParseError, hasError, parserTimeTaken, lexerTimeTaken } = parseFileWithVisitor(visitor, scriptData);
94
94
  showStats && console.log('Lexing took:', lexerTimeTaken);
95
95
  showStats && console.log('Parsing took:', parserTimeTaken);
96
- if (dumpNets) {
97
- console.log(visitor.dumpNets());
98
- }
96
+ dumpNets && console.log(visitor.dumpNets());
99
97
  dumpData && writeFileSync('dump/tree.lisp', tree.toStringTree(null, parser));
100
98
  dumpData && writeFileSync('dump/raw-parser.txt', visitor.logger.dump());
101
99
  if (hasError || hasParseError) {
102
100
  console.log('Error while parsing');
103
- return;
101
+ return null;
104
102
  }
105
103
  visitor.annotateComponents();
106
104
  if (kicadNetlistPath) {
@@ -63,12 +63,6 @@ export class CircuitscriptParserErrorListener extends ErrorListener {
63
63
  console.log("Syntax error at line", line, ':', column, ' - ', msg);
64
64
  this.syntaxErrorCounter++;
65
65
  }
66
- reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) {
67
- }
68
- reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) {
69
- }
70
- reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) {
71
- }
72
66
  hasParseErrors() {
73
67
  return (this.syntaxErrorCounter > 0);
74
68
  }
@@ -42,6 +42,10 @@ def solder_bridge():
42
42
  return create component:
43
43
  pins: 2
44
44
 
45
+ gnd = dgnd()
46
+ v3v3 = supply("3V3")
47
+ v5v = supply("5V")
48
+
45
49
  atmega = create component:
46
50
  pins:
47
51
  1: "XTAL1"
@@ -189,7 +193,7 @@ at atmega:
189
193
  wire left 40
190
194
  branch:
191
195
  wire up 20
192
- to net("5V")
196
+ to v5v
193
197
  wire down 20
194
198
  branch:
195
199
  wire auto
@@ -223,7 +227,7 @@ at atmega:
223
227
  to icsp_conn2 pin 5
224
228
 
225
229
  branch:
226
- at net("5V")
230
+ at v5v
227
231
  wire down 20 left 20
228
232
  to icsp_conn2 pin 2
229
233
  point tmp4
@@ -393,19 +397,19 @@ at atmega:
393
397
  wire right 40
394
398
  add label("RXLED")
395
399
  wire right 100 down 100 right 60
396
- add led("yellow") pin 1 ..angle=180
400
+ add led("yellow") pin 2 right
397
401
  wire right 20
398
402
  add res(1k)
399
403
  wire right 20 up 80
400
404
  point tmp6
401
405
  wire up 20
402
- to net("5V")
406
+ to v5v
403
407
 
404
408
  11:
405
409
  wire right 40
406
410
  add label("TXLED")
407
411
  wire right 120 down 40 right 40
408
- add led("yellow") pin 1 ..angle=180
412
+ add led("yellow") pin 2 right
409
413
  wire right 20
410
414
  add res(1k)
411
415
  wire auto
@@ -419,11 +423,11 @@ power_conn2 = create component:
419
423
 
420
424
  at power_conn2:
421
425
  2:
422
- wire left 40
423
- add label("3V3")
426
+ wire left 60 up 80
427
+ add v3v3
424
428
  3:
425
- wire left 80 up 100
426
- to net("5V")
429
+ wire left 100 up 100
430
+ to v5v
427
431
 
428
432
  4:
429
433
  wire left 20 down 20
@@ -446,7 +450,7 @@ at atmega8:
446
450
  wire up 20
447
451
  add res(10k) pin 2 ..angle=90
448
452
  wire up 20
449
- to net("5V")
453
+ to v5v
450
454
  branch:
451
455
  wire left 40 up 420 right 120
452
456
  to power_conn2 pin 1
@@ -482,7 +486,7 @@ at atmega8:
482
486
  wire left 40
483
487
  branch:
484
488
  wire up 20
485
- to net("5V")
489
+ to v5v
486
490
  wire down 20
487
491
  add cap(100n)
488
492
  wire down 20
@@ -626,7 +630,7 @@ at icsp_conn:
626
630
  to gnd
627
631
  2:
628
632
  wire right 20 up 20
629
- to net("5V")
633
+ to v5v
630
634
 
631
635
  5:
632
636
  wire left 140
@@ -649,23 +653,6 @@ at icsp_conn:
649
653
  to gnd
650
654
 
651
655
 
652
- # Block for 5V leds
653
- at net("5V")
654
- wire down 20
655
- branch:
656
- wire right 20
657
- add res(1k)
658
- wire right 20
659
- point tmp9
660
- wire right 20
661
- add led("green") pin 2
662
- wire right 20 down 20
663
- to gnd
664
- wire down 40 right 20
665
- add res(1k)
666
- wire auto_
667
- to tmp9
668
-
669
656
  # 3V3 output converter
670
657
  dcdc_3v3 = create component:
671
658
  pins:
@@ -724,123 +711,157 @@ fet = create component:
724
711
  param:
725
712
  manufacturer_pn: "FDN304V"
726
713
 
727
- at label("VIN")
728
- wire right 40 down 20
729
- add res(10k) ..angle=90
730
- wire down 20
731
- branch:
732
- wire down 20
733
- add res(10k) ..angle=90
734
- to gnd
735
- wire right 80
736
- add label("CMP")
737
- wire right 20
738
- to opamp_1 pin 3
739
-
740
- at label("3V3")
741
- wire right 40
742
- to opamp_1 pin 2
743
-
744
- at label("USBVCC")
745
- wire right 40 to fet pin 1
746
-
747
- at opamp_1 pin 1
748
- wire right 80 down 100 left 20
749
- to fet pin 2
750
-
751
- at fet pin 3
752
- wire right 60
753
- branch:
754
- wire up 20
755
- to net("5V")
756
- wire right 60
757
- branch:
758
- wire right 20
759
- to dcdc_3v3 pin 1
760
- wire auto_
761
- to dcdc_3v3 pin 3
762
-
763
- at dcdc_3v3:
764
- 2:
765
- wire left 20 down 20
766
- to gnd
767
-
768
- 5:
769
- wire right 20
770
- add label("3V3")
771
- wire right 20 down 20
772
- add cap(1u)
773
- to gnd
774
-
775
-
776
-
777
- # Block for 5V power
778
- power_conn = create component:
779
- pins: 3
780
- arrange:
781
- left: 1,3
782
- right: 2
783
-
784
- at power_conn:
785
- 1:
786
- wire left 20 down 20
787
- branch:
788
- wire auto
789
- to power_conn pin 3
714
+ frame:
715
+ ..title = "Supply generation"
716
+ ..direction = "row"
717
+
718
+ frame:
719
+ ..title = "3V3 power"
720
+
721
+ at label("VIN")
722
+ wire right 40 down 20
723
+ add res(10k) ..angle=90
790
724
  wire down 20
791
- to gnd
792
- 2:
793
- wire right 20
794
- add label("PWRIN")
795
- wire right 40
796
- add diode()
797
- wire right 40
798
725
  branch:
799
726
  wire down 20
800
- add cap(47u)
727
+ add res(10k) ..angle=90
801
728
  to gnd
729
+ wire right 80
730
+ add label("CMP")
802
731
  wire right 20
803
- point tmp10
732
+ to opamp_1 pin 3
804
733
 
805
- at dcdc_5V:
806
- 1:
807
- wire left 20 down 20
808
- to gnd
809
- 3:
810
- wire left 80
811
- to tmp10
734
+ at v3v3 left
735
+ wire right 20
736
+ to opamp_1 pin 2
812
737
 
813
- wire up 20
814
- branch:
815
- wire right 20
816
- add label("VIN")
817
- wire right 40
818
- wire up 100 right 80
819
- to dcdc_5V_2 pin 3
820
- 2:
821
- wire right 40
822
- point tmp11
738
+ at label("USBVCC")
739
+ wire right 40 to fet pin 1
740
+
741
+ at opamp_1 pin 1
742
+ wire right 80 down 100 left 20
743
+ to fet pin 2
744
+
745
+ at fet pin 3
746
+ wire right 60
823
747
  branch:
824
- wire down 20
825
- add cap(47u)
826
- to gnd
748
+ wire up 20
749
+ to v5v
827
750
  wire right 60
828
751
  branch:
829
- wire down 20
830
- add cap(100n)
831
- to gnd
832
- wire right 20 up 20
833
- to net("5V")
834
-
752
+ wire right 20
753
+ to dcdc_3v3 pin 1
754
+ wire auto_
755
+ to dcdc_3v3 pin 3
756
+
757
+ at dcdc_3v3:
758
+ 2:
759
+ wire left 20 down 20
760
+ to gnd
761
+
762
+ 5:
763
+ wire right 40
764
+ branch:
765
+ wire up 20
766
+ to v3v3
767
+ wire down 20
768
+ add cap(1u)
769
+ to gnd
770
+
835
771
 
836
- at dcdc_5V_2:
837
- 1:
838
- wire left 20 down 20
839
- to gnd
840
- 4:
841
- wire right 20 down 20
842
- branch:
843
- wire auto
844
- to dcdc_5V_2 pin 2
845
- wire auto
846
- to tmp11
772
+ frame:
773
+ ..title = "5V power"
774
+
775
+ # Block for 5V power
776
+ power_conn = create component:
777
+ pins: 3
778
+ arrange:
779
+ left: 1,3
780
+ right: 2
781
+
782
+ at power_conn:
783
+ 1:
784
+ wire left 20 down 20
785
+ branch:
786
+ wire auto
787
+ to power_conn pin 3
788
+ wire down 20
789
+ to gnd
790
+ 2:
791
+ wire right 20
792
+ add label("PWRIN")
793
+ wire right 40
794
+ add diode()
795
+ wire right 40
796
+ branch:
797
+ wire down 20
798
+ add cap(47u)
799
+ to gnd
800
+ wire right 20
801
+ point tmp10
802
+
803
+ at dcdc_5V:
804
+ 1:
805
+ wire left 20 down 20
806
+ to gnd
807
+ 3:
808
+ wire left 80
809
+ to tmp10
810
+
811
+ wire up 20
812
+ branch:
813
+ wire right 20
814
+ add label("VIN")
815
+ wire right 40
816
+ wire up 100 right 80
817
+ to dcdc_5V_2 pin 3
818
+ 2:
819
+ wire right 40
820
+ point tmp11
821
+ branch:
822
+ wire down 20
823
+ add cap(47u)
824
+ to gnd
825
+ wire right 60
826
+ branch:
827
+ wire down 20
828
+ add cap(100n)
829
+ to gnd
830
+ wire right 20 up 20
831
+ to v5v
832
+
833
+
834
+ at dcdc_5V_2:
835
+ 1:
836
+ wire left 20 down 20
837
+ to gnd
838
+ 4:
839
+ wire right 20 down 20
840
+ branch:
841
+ wire auto
842
+ to dcdc_5V_2 pin 2
843
+ wire auto
844
+ to tmp11
845
+
846
+ frame:
847
+ ..title = "5V indication"
848
+ ..border = 0
849
+
850
+ # Block for 5V leds
851
+ at v5v
852
+ wire down 20
853
+ branch:
854
+ wire right 20
855
+ add res(1k)
856
+ wire right 20
857
+ point tmp9
858
+ wire right 20
859
+
860
+ add led("green")
861
+ wire right 20 down 20
862
+ to gnd
863
+
864
+ wire down 40 right 20
865
+ add res(1k)
866
+ wire auto_
867
+ to tmp9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "circuitscript",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "Interpreter for the circuitscript language",
5
5
  "homepage": "https://circuitscript.net",
6
6
  "engines": {
@@ -160,7 +160,9 @@ export abstract class SymbolGraphic {
160
160
  let dominantBaseline = 'auto';
161
161
 
162
162
  let useAnchor = anchor;
163
- if (this.angle === 180){
163
+ const isRotation180 = Math.abs(this.angle) === 180;
164
+
165
+ if (isRotation180){
164
166
  // Special case to flip the text instead of rotating
165
167
  useAnchor = this.flipTextAnchor(anchor);
166
168
  }
@@ -194,7 +196,7 @@ export abstract class SymbolGraphic {
194
196
  }
195
197
 
196
198
  const position = tmpLabel.getLabelPosition();
197
-
199
+
198
200
  let useFont = defaultFont;
199
201
  if (fontWeight === 'bold'){
200
202
  useFont = 'Inter-Bold';
@@ -210,7 +212,7 @@ export abstract class SymbolGraphic {
210
212
  // weight: fontWeight,
211
213
  });
212
214
 
213
- if (this.angle === 180){
215
+ if (isRotation180){
214
216
  text.translate(-position[0], position[1]);
215
217
  } else {
216
218
  text.translate(position[0], position[1])
package/src/main.ts CHANGED
@@ -17,7 +17,10 @@ import { SimpleStopwatch } from './utils.js';
17
17
 
18
18
  export default async function main(): Promise<void> {
19
19
  const toolSrcPath = fileURLToPath(import.meta.url);
20
+
20
21
  const toolDirectory = path.dirname(toolSrcPath) + '/../../';
22
+ const fontsPath = toolDirectory + '/fonts';
23
+ const defaultLibsPath = toolDirectory + '/libs';
21
24
 
22
25
  const packageJson = JSON.parse(readFileSync(toolDirectory + 'package.json').toString());;
23
26
  const {version} = packageJson;
@@ -56,10 +59,6 @@ export default async function main(): Promise<void> {
56
59
 
57
60
  let currentDirectory = options.currentDirectory ?? null;
58
61
 
59
-
60
- const fontsPath = toolDirectory + '/fonts';
61
- const defaultLibsPath = toolDirectory + '/libs';
62
-
63
62
  if (watchFileChanges) {
64
63
  console.log('watching for file changes...');
65
64
  }
@@ -97,7 +96,7 @@ export default async function main(): Promise<void> {
97
96
  }
98
97
 
99
98
  if (watchFileChanges) {
100
- watch(inputFilePath, (event, targetFile) => {
99
+ watch(inputFilePath, event => {
101
100
  if (event === 'change') {
102
101
  const scriptData = readFileSync(inputFilePath,
103
102
  {encoding: 'utf-8'});
@@ -134,23 +133,19 @@ export function renderScript(scriptData: string, outputPath: string, options): s
134
133
 
135
134
  showStats && console.log('Lexing took:', lexerTimeTaken);
136
135
  showStats && console.log('Parsing took:', parserTimeTaken);
137
-
138
- if (dumpNets){
139
- console.log(visitor.dumpNets());
140
- }
141
- // console.log(visitor.dumpUniqueNets());
136
+ dumpNets && console.log(visitor.dumpNets());
142
137
 
143
138
  dumpData && writeFileSync('dump/tree.lisp', tree.toStringTree(null, parser));
144
139
  dumpData && writeFileSync('dump/raw-parser.txt', visitor.logger.dump());
145
140
 
146
141
  if (hasError || hasParseError) {
147
142
  console.log('Error while parsing');
148
- return;
143
+ return null;
149
144
  }
150
145
 
151
146
  visitor.annotateComponents();
152
147
 
153
- if(kicadNetlistPath){
148
+ if (kicadNetlistPath) {
154
149
  const kicadNetList = generateKiCADNetList(visitor.getNetList());
155
150
  writeFileSync(kicadNetlistPath, kicadNetList);
156
151
  console.log('Generated KiCad netlist file');
package/src/parser.ts CHANGED
@@ -91,14 +91,14 @@ export class CircuitscriptParserErrorListener extends ErrorListener {
91
91
  this.syntaxErrorCounter++;
92
92
  }
93
93
 
94
- reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) {
95
- }
94
+ // reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs) {
95
+ // }
96
96
 
97
- reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) {
98
- }
97
+ // reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs) {
98
+ // }
99
99
 
100
- reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) {
101
- }
100
+ // reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs) {
101
+ // }
102
102
 
103
103
  hasParseErrors(): boolean {
104
104
  return (this.syntaxErrorCounter > 0);
File without changes