circuitscript 0.0.24 → 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 (63) 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 +209 -195
  5. package/dist/cjs/antlr/CircuitScriptParser.js +2310 -2087
  6. package/dist/cjs/antlr/CircuitScriptVisitor.js +4 -3
  7. package/dist/cjs/draw_symbols.js +67 -22
  8. package/dist/cjs/execute.js +51 -53
  9. package/dist/cjs/geometry.js +28 -8
  10. package/dist/cjs/helpers.js +175 -5
  11. package/dist/cjs/index.js +2 -0
  12. package/dist/cjs/layout.js +8 -0
  13. package/dist/cjs/lexer.js +19 -22
  14. package/dist/cjs/main.js +6 -11
  15. package/dist/cjs/objects/ClassComponent.js +3 -0
  16. package/dist/cjs/objects/ExecutionScope.js +1 -0
  17. package/dist/cjs/objects/types.js +7 -1
  18. package/dist/cjs/parser.js +29 -258
  19. package/dist/cjs/validate.js +81 -0
  20. package/dist/cjs/visitor.js +529 -820
  21. package/dist/esm/BaseVisitor.mjs +488 -0
  22. package/dist/esm/SemanticTokenVisitor.mjs +215 -0
  23. package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
  24. package/dist/esm/antlr/CircuitScriptLexer.mjs +184 -194
  25. package/dist/esm/antlr/CircuitScriptParser.mjs +2279 -2084
  26. package/dist/esm/antlr/CircuitScriptVisitor.mjs +8 -3
  27. package/dist/esm/draw_symbols.mjs +67 -22
  28. package/dist/esm/execute.mjs +50 -52
  29. package/dist/esm/geometry.mjs +28 -8
  30. package/dist/esm/helpers.mjs +165 -6
  31. package/dist/esm/index.mjs +2 -0
  32. package/dist/esm/layout.mjs +8 -0
  33. package/dist/esm/lexer.mjs +10 -10
  34. package/dist/esm/main.mjs +7 -12
  35. package/dist/esm/objects/ClassComponent.mjs +3 -0
  36. package/dist/esm/objects/ExecutionScope.mjs +1 -0
  37. package/dist/esm/objects/types.mjs +6 -0
  38. package/dist/esm/parser.mjs +25 -230
  39. package/dist/esm/validate.mjs +74 -0
  40. package/dist/esm/visitor.mjs +343 -640
  41. package/dist/types/BaseVisitor.d.ts +69 -0
  42. package/dist/types/SemanticTokenVisitor.d.ts +36 -0
  43. package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
  44. package/dist/types/antlr/CircuitScriptLexer.d.ts +8 -7
  45. package/dist/types/antlr/CircuitScriptParser.d.ts +513 -469
  46. package/dist/types/antlr/CircuitScriptVisitor.d.ts +69 -59
  47. package/dist/types/draw_symbols.d.ts +9 -0
  48. package/dist/types/execute.d.ts +5 -8
  49. package/dist/types/geometry.d.ts +4 -0
  50. package/dist/types/helpers.d.ts +32 -1
  51. package/dist/types/index.d.ts +2 -0
  52. package/dist/types/lexer.d.ts +2 -2
  53. package/dist/types/objects/ExecutionScope.d.ts +4 -1
  54. package/dist/types/objects/types.d.ts +5 -0
  55. package/dist/types/parser.d.ts +15 -28
  56. package/dist/types/validate.d.ts +2 -0
  57. package/dist/types/visitor.d.ts +40 -95
  58. package/fonts/Inter-Bold.ttf +0 -0
  59. package/fonts/Inter-Regular.ttf +0 -0
  60. package/fonts/OpenSans-Regular.ttf +0 -0
  61. package/fonts/Roboto-Regular.ttf +0 -0
  62. package/libs/lib.cst +183 -0
  63. package/package.json +11 -6
@@ -0,0 +1,74 @@
1
+ #! /usr/bin/env node
2
+ import { program } from 'commander';
3
+ import figlet from 'figlet';
4
+ import path from 'path';
5
+ import { readFileSync } from 'fs';
6
+ import { prepareSVGEnvironment } from './sizing.mjs';
7
+ import { getCurrentPath, getScriptText, getSemanticTokens, validateScript } from './helpers.mjs';
8
+ export async function validate() {
9
+ const { filePath } = getCurrentPath();
10
+ const toolSrcPath = filePath;
11
+ const toolDirectory = path.dirname(toolSrcPath) + '/../../';
12
+ const fontsPath = toolDirectory + '/fonts';
13
+ const defaultLibsPath = toolDirectory + '/libs';
14
+ const packageJson = JSON.parse(readFileSync(toolDirectory + 'package.json').toString());
15
+ ;
16
+ const { version } = packageJson;
17
+ program
18
+ .description('generate graphical output from circuitscript files')
19
+ .version(version)
20
+ .option('-i, --input text <input text>', 'Input text directly')
21
+ .option('-f, --input-file <path>', 'Input file')
22
+ .option('-o, --output <path>', 'Output path')
23
+ .option('-c, --current-directory <path>', 'Set current directory')
24
+ .option('-k, --kicad-netlist <filename>', 'Create KiCad netlist')
25
+ .option('-w, --watch', 'Watch for file changes')
26
+ .option('-n, --dump-nets', 'Dump out net information')
27
+ .option('-d, --dump-data', 'Dump data during parsing')
28
+ .option('-s, --stats', 'Show stats during generation');
29
+ program.addHelpText('before', figlet.textSync('circuitscript', {
30
+ font: 'Small Slant'
31
+ }));
32
+ if (process.argv.length < 3) {
33
+ program.help();
34
+ }
35
+ program.parse();
36
+ const options = program.opts();
37
+ const watchFileChanges = options.watch;
38
+ const outputPath = options.output ?? null;
39
+ const dumpNets = options.dumpNets;
40
+ const dumpData = options.dumpData;
41
+ const kicadNetlist = options.kicadNetlist;
42
+ let currentDirectory = options.currentDirectory ?? null;
43
+ if (watchFileChanges) {
44
+ console.log('watching for file changes...');
45
+ }
46
+ await prepareSVGEnvironment(fontsPath);
47
+ let inputFilePath = null;
48
+ let scriptData;
49
+ if (options.input) {
50
+ scriptData = options.input;
51
+ }
52
+ else {
53
+ inputFilePath = options.inputFile;
54
+ const tmpScriptData = getScriptText(inputFilePath);
55
+ if (tmpScriptData === null) {
56
+ throw "File does not exists";
57
+ }
58
+ scriptData = tmpScriptData;
59
+ if (currentDirectory === null) {
60
+ currentDirectory = path.dirname(inputFilePath);
61
+ }
62
+ }
63
+ const scriptOptions = {
64
+ currentDirectory,
65
+ defaultLibsPath,
66
+ dumpNets,
67
+ dumpData,
68
+ kicadNetlistPath: kicadNetlist,
69
+ showStats: options.stats,
70
+ };
71
+ const visitor = validateScript(scriptData, scriptOptions);
72
+ const semanticTokensVisitor = getSemanticTokens(scriptData, scriptOptions);
73
+ }
74
+ validate();